Skip to content

Commit

Permalink
refactor(YouTube): remove unused code, improve settings (#8901)
Browse files Browse the repository at this point in the history
* fix: remove nonexistent string

* chore: change default logo option

* fix: remove `adjustTimeError`

* chore: rename Logo option to Image

* perf: run `getTimestampsfromMedia` once

* chore: remove `adjustTimeError`

---------

Signed-off-by: veryCrunchy <me@verycrunchy.dev>
  • Loading branch information
veryCrunchy authored Nov 22, 2024
1 parent 027e345 commit 09e294f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
6 changes: 3 additions & 3 deletions websites/Y/YouTube/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"www.youtube.com",
"studio.youtube.com"
],
"version": "5.13.4",
"version": "5.13.5",
"logo": "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube/assets/thumbnail.jpg",
"color": "#E40813",
Expand Down Expand Up @@ -162,9 +162,9 @@
"if": {
"privacy": false
},
"title": "Logo",
"title": "Image",
"icon": "fad fa-images",
"value": 0,
"value": 1,
"values": [
"YT Logo",
"Thumbnail",
Expand Down
10 changes: 3 additions & 7 deletions websites/Y/YouTube/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import youtubeMiniplayerResolver from "./video_sources/miniplayer";
import youtubeApiResolver from "./video_sources/api";
import {
Resolver,
adjustTimeError,
presence,
strings,
getSetting,
Expand Down Expand Up @@ -145,6 +144,7 @@ presence.on("UpdateData", async () => {
unlistedPathElement?.getAttribute("d") ===
unlistedBadgeElement?.getAttribute("d"),
videoId = resolver.getVideoID(),
[startTimestamp, endTimestamp] = presence.getTimestampsfromMedia(video),
presenceData: PresenceData = {
type: ActivityType.Watching,
details: vidDetail
Expand Down Expand Up @@ -177,12 +177,8 @@ presence.on("UpdateData", async () => {
: isPlaylistLoop
? "Playlist on loop"
: strings.play,
endTimestamp: !video?.paused
? adjustTimeError(presence.getTimestampsfromMedia(video)[1], 0.75)
: -1,
startTimestamp: !video?.paused
? adjustTimeError(presence.getTimestampsfromMedia(video)[0], 0.75)
: -1,
startTimestamp,
endTimestamp,
};

if (vidState.includes("{0}")) delete presenceData.state;
Expand Down
7 changes: 0 additions & 7 deletions websites/Y/YouTube/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ export const presence = new Presence({
clientId: "463097721130188830",
});

let cachedTime = 0;
export function adjustTimeError(time: number, acceptableError: number): number {
if (Math.abs(time - cachedTime) > acceptableError) cachedTime = time;
return cachedTime;
}

export function truncateAfter(str: string, pattern: string): string {
return str.slice(0, str.indexOf(pattern));
}
Expand Down Expand Up @@ -69,7 +63,6 @@ const stringMap = {
watchStreamButton: "general.buttonWatchStream",
watchVideoButton: "general.buttonWatchVideo",
viewChannelButton: "general.buttonViewChannel",
videos: "youtube.videos",
perVideoPrivacyToolTip1: "youtube.perVideoPrivacy.tooltip.1",
perVideoPrivacyToolTip2: "youtube.perVideoPrivacy.tooltip.2",
};
Expand Down

0 comments on commit 09e294f

Please sign in to comment.