-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97a94a8
commit 6dc5b62
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const iframe = new iFrame(); | ||
iframe.on("UpdateData", async () => { | ||
const videoElement: HTMLVideoElement = | ||
document.querySelector(".video-stream"); | ||
if (!videoElement) return; | ||
|
||
iframe.send({ | ||
title: document.querySelector<HTMLAnchorElement>("div.ytp-title-text > a") | ||
.textContent, | ||
duration: videoElement.duration, | ||
currentTime: videoElement.currentTime, | ||
paused: videoElement.paused, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.11", | ||
"apiVersion": 1, | ||
"author": { | ||
"name": "uwu_peter", | ||
"id": "762219738570555412" | ||
}, | ||
"service": "YTPLR", | ||
"altnames": ["YouTube Playlist Randomizer"], | ||
"description": { | ||
"en": "Shuffles a YouTube Playlist in random order" | ||
}, | ||
"url": "youtube-playlist-randomizer.bitbucket.io", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/hsDOqgw.png", | ||
"thumbnail": "https://i.imgur.com/VhkOWl2.png", | ||
"color": "#ff6d70", | ||
"tags": [ | ||
"video", | ||
"media" | ||
], | ||
"settings": [ | ||
{ | ||
"id": "buttons", | ||
"title": "Show Buttons", | ||
"icon": "fas fa-compress-arrows-alt", | ||
"value": true | ||
} | ||
], | ||
"category": "videos", | ||
"iFrameRegExp": "youtube[-]playlist[-]randomizer[.]bitbucket[.]io", | ||
"iframe": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const presence = new Presence({ | ||
clientId: "1284161421957136486", | ||
}), | ||
strings = presence.getStrings({ | ||
play: "general.watchingVid", | ||
pause: "general.paused", | ||
}), | ||
browsingTimestamp = Math.floor(Date.now() / 1000); | ||
|
||
let videoTitle: string, | ||
videoCurrentTime: number, | ||
videoDuration: number, | ||
videoPaused: boolean, | ||
videoPlaylistTotal: number, | ||
videoPlaylistID: string, | ||
videoPlaylistTitle: string; | ||
|
||
interface DataInterface { | ||
title: string; | ||
currentTime: number; | ||
duration: number; | ||
paused: boolean; | ||
} | ||
|
||
const enum Assets { | ||
Logo = "https://i.imgur.com/hsDOqgw.png", | ||
} | ||
|
||
presence.on("iFrameData", (data: DataInterface) => { | ||
videoTitle = data.title; | ||
videoCurrentTime = data.currentTime; | ||
videoDuration = data.duration; | ||
videoPaused = data.paused; | ||
videoPlaylistTotal = parseInt(document.querySelector("#all").textContent); | ||
videoPlaylistID = document.querySelector<HTMLInputElement>("#pid").value; | ||
videoPlaylistTitle = document.querySelector("#title").textContent; | ||
}); | ||
|
||
presence.on("UpdateData", async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: Assets.Logo, | ||
}, | ||
[startTimestamp, endTimestamp] = presence.getTimestamps( | ||
Math.floor(videoCurrentTime), | ||
Math.floor(videoDuration) | ||
), | ||
showButtons = await presence.getSetting<boolean>("buttons"); | ||
|
||
if (videoTitle) { | ||
presenceData.type = ActivityType.Watching; | ||
presenceData.details = `Shuffling ${videoPlaylistTotal} Videos`; | ||
presenceData.state = videoTitle; | ||
presenceData.smallImageKey = videoPaused ? Assets.Pause : Assets.Play; | ||
presenceData.smallImageText = videoPaused | ||
? (await strings).pause | ||
: (await strings).play; | ||
|
||
if (!videoPaused) { | ||
presenceData.startTimestamp = startTimestamp; | ||
presenceData.endTimestamp = endTimestamp; | ||
} else { | ||
delete presenceData.startTimestamp; | ||
delete presenceData.endTimestamp; | ||
} | ||
|
||
if (videoPlaylistID && showButtons) { | ||
presenceData.buttons = [ | ||
{ | ||
label: `Shuffle ${videoPlaylistTitle}`, | ||
url: `https://youtube-playlist-randomizer.bitbucket.io/?pid=${videoPlaylistID}&autostart`, | ||
}, | ||
]; | ||
} else delete presenceData.buttons; | ||
} else presenceData.startTimestamp = browsingTimestamp; | ||
|
||
presenceData.state = `"${presenceData.state}"`; | ||
|
||
if (presenceData.details) presence.setActivity(presenceData); | ||
else presence.setActivity(); | ||
}); |