Last active
March 29, 2024 08:09
-
-
Save FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c to your computer and use it in GitHub Desktop.
A simple BetterDiscord plugin that adds a loop button next to the pause button in videos.
This file contains hidden or 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
/** | |
* @name VideoLoop | |
* @authorLink https://github.com/FrostBird347 | |
* @source https://gist.github.com/FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c#gistcomment-3640733 | |
* @updateUrl https://gist.githubusercontent.com/FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c/raw/VideoLoop.plugin.js | |
*/ | |
module.exports = class VideoLoop { | |
getName () {return "VideoLoop";} | |
getDescription () {return "Adds a replay button next to the pause button in discord videos audio files.";} | |
getVersion() {return "1.1.8";} | |
getAuthor () {return "FrostBird347";} | |
load() {} | |
stop() {} | |
start() { | |
//Simple update notifier | |
//I have been unable to figure out how to obtain the plugin's version | |
let CurrentVersion = "1.1.8" | |
window.fetch("https://gist.githubusercontent.com/FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c/raw/VideoLoop.plugin.js").then(function(response) { | |
response.text().then(function(text) { | |
let Lines = text.split("\t").join("").split("\n") | |
let RemoteVersion = "" | |
for (let l = 0; l < Lines.length; l++) { | |
if (RemoteVersion == "" && Lines[l].split(" ").join("").split("\"")[0] == "getVersion(){return") { | |
RemoteVersion = Lines[l].split(" ").join("").split("\"")[1] | |
} | |
} | |
if (RemoteVersion != CurrentVersion) { | |
window.BdApi.UI.showToast("VideoLoop is outdated!\nCurrent: " + CurrentVersion + "\nLatest: " + RemoteVersion, {type: "info", icon:true, timeout: 7500}) | |
} | |
}) | |
}) | |
} | |
observer(changes) { | |
let ElementClasses = { | |
"videoControls": "videoControls__7bc92", | |
"controlIcon": "controlIcon_d1bbd7", | |
"audioControls": "audioControls_da7066" | |
} | |
Array.prototype.forEach.call(document.querySelectorAll("[class*=" + ElementClasses.videoControls + "]"), function(el) { | |
try { | |
if (!el.classList.contains("AddedLoop")) { | |
el.classList.add("AddedLoop") | |
el.insertBefore(document.createElement("div"), el.children[1]) | |
el.children[1].innerHTML = '<svg class="' + ElementClasses.controlIcon + '" aria-hidden="false" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="m 17.673205,7.3499186 2.828428,-2.8284271 h -7.071068 v 7.0710675 l 2.828427,-2.8284268 c 2.340523,2.3405238 2.340523,6.1447578 -2e-6,8.4852828 -2.340524,2.340524 -6.144758,2.340524 -8.4852815,1e-6 -2.3405235,-2.340524 -2.3405234,-6.144758 5e-7,-8.4852824 L 6.3594955,7.34992 c -3.1254128,3.125413 -3.1254126,8.188297 -7e-7,11.313709 3.125412,3.125412 8.1882962,3.125412 11.3137092,0 3.125413,-3.125414 3.125413,-8.188298 1e-6,-11.3137104 z M 6.3267946,18.696329 3.4983675,21.524757 h 7.0710675 v -7.071068 l -2.8284268,2.828427 c -2.3405235,-2.340524 -2.3405235,-6.144758 0,-8.4852815 2.3405238,-2.3405235 6.1447578,-2.3405235 8.4852818,0 2.340523,2.3405235 2.340523,6.1447575 0,8.4852815 l 1.414213,1.414213 c 3.125412,-3.125412 3.125412,-8.188296 0,-11.3137081 -3.125412,-3.125412 -8.1882964,-3.125412 -11.3137084,0 -3.125412,3.1254121 -3.125412,8.1882961 0,11.3137081 z"></path></svg>' | |
el.children[1].id = "VideoLoopButton" | |
el.children[1].onclick = function(preel) { | |
let el = preel.srcElement | |
if (el.tagName.toLowerCase() == "path") { | |
el = el.parentElement | |
} | |
if (!el.parentElement.classList.contains("ChangingLoop")) { | |
el.parentElement.classList.add("ChangingLoop") | |
let videl = el | |
videl = el.parentElement.parentElement.parentElement.parentElement.querySelector("VIDEO") | |
if (videl.tagName != "VIDEO") { | |
el.remove() | |
} else { | |
if (videl.loop) { | |
el.style.color = "" | |
el.style.opacity = "" | |
videl.loop = false | |
} else { | |
el.style.color = "var(--brand-experiment)" | |
el.style.opacity = 1 | |
videl.loop = true | |
} | |
} | |
el.parentElement.classList.remove("ChangingLoop") | |
} | |
} | |
} | |
} catch {} | |
}) | |
Array.prototype.forEach.call(document.querySelectorAll("[class*=" + ElementClasses.audioControls + "]"), function(el) { | |
try { | |
if (!el.classList.contains("AddedLoop")) { | |
el.classList.add("AddedLoop") | |
el.insertBefore(document.createElement("div"), el.children[1]) | |
el.children[1].innerHTML = '<svg class="' + ElementClasses.controlIcon + '" aria-hidden="false" width="16" height="16" viewBox="0 0 24 24"><path fill="currentColor" d="m 17.673205,7.3499186 2.828428,-2.8284271 h -7.071068 v 7.0710675 l 2.828427,-2.8284268 c 2.340523,2.3405238 2.340523,6.1447578 -2e-6,8.4852828 -2.340524,2.340524 -6.144758,2.340524 -8.4852815,1e-6 -2.3405235,-2.340524 -2.3405234,-6.144758 5e-7,-8.4852824 L 6.3594955,7.34992 c -3.1254128,3.125413 -3.1254126,8.188297 -7e-7,11.313709 3.125412,3.125412 8.1882962,3.125412 11.3137092,0 3.125413,-3.125414 3.125413,-8.188298 1e-6,-11.3137104 z M 6.3267946,18.696329 3.4983675,21.524757 h 7.0710675 v -7.071068 l -2.8284268,2.828427 c -2.3405235,-2.340524 -2.3405235,-6.144758 0,-8.4852815 2.3405238,-2.3405235 6.1447578,-2.3405235 8.4852818,0 2.340523,2.3405235 2.340523,6.1447575 0,8.4852815 l 1.414213,1.414213 c 3.125412,-3.125412 3.125412,-8.188296 0,-11.3137081 -3.125412,-3.125412 -8.1882964,-3.125412 -11.3137084,0 -3.125412,3.1254121 -3.125412,8.1882961 0,11.3137081 z"></path></svg>' | |
el.children[1].id = "AudioLoopButton" | |
el.children[1].onclick = function(preel) { | |
let el = preel.srcElement | |
if (el.tagName.toLowerCase() == "path") { | |
el = el.parentElement | |
} | |
if (!el.parentElement.classList.contains("ChangingLoop")) { | |
el.parentElement.classList.add("ChangingLoop") | |
let audioel = el | |
audioel = el.parentElement.parentElement.parentElement.parentElement.querySelector("AUDIO") | |
if (audioel.tagName != "AUDIO") { | |
el.remove() | |
} else { | |
if (audioel.loop) { | |
el.style.color = "" | |
el.style.opacity = "" | |
audioel.loop = false | |
} else { | |
el.style.color = "var(--brand-experiment)" | |
el.style.opacity = 1 | |
audioel.loop = true | |
} | |
} | |
el.parentElement.classList.remove("ChangingLoop") | |
} | |
} | |
} | |
} catch {} | |
}) | |
} | |
} |
Oh, thank you.
…On Mon, Feb 26, 2024, 10:55 PM FrostBird347 ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
- Click on the "View Raw
<https://gist.github.com/FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c/raw/476aae9dcff3b4d7ac5a3192a046fc04894fbdb3/VideoLoop.plugin.js>"
button in the top right corner of the code (or open on the link).
- Do Command/Control+S or right click and save the file
- Place the file in BetterDiscord's plugin folder, making sure the
file name ends in ".plugin.js"
- You can find the plugin folder by opening discord's settings,
opening the "plugin" page and then clicking the "Open Plugins Folder"
button.
- Once it's added you probably will need to enable it by clicking the
checkmark (checkmark.png (view on web)
<https://gist.github.com/assets/39435218/d5abb857-2615-496e-98c5-83c3f1dc2e64>
)
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c#gistcomment-4943830>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A6VRTG5QNJ63PIQB4EJBSG3YVVKJXBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTAOBQGY2TQNBZU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.plugin.js
"