Skip to content

Instantly share code, notes, and snippets.

@FrostBird347
Last active March 29, 2024 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrostBird347/6abad7503698db0c95a94ad3a2d0ca6c to your computer and use it in GitHub Desktop.
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.
/**
* @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 {}
})
}
}
@FrostBird347
Copy link
Author

FrostBird347 commented Feb 22, 2021

Source ↑

Update Log

1.1.8

  • Discord changed the class names of everything
  • Replaced hardcoded colours with variables, thus making the plugin compatible with themes

1.1.7

  • Updated deprecated BdApi functions

1.1.6

  • Discord changed the class names of everything

1.1.5

  • Improved variable declaration

1.1.4

  • Discord appears to have removed jQuery.

1.1.3

  • Added an extremely simple update notifier

1.1.2

  • Updated classes

1.1.1

  • Normalised Classes were removed recently, disabling this plugin in versions prior to 1.1.1.

1.1.0

  • Added support for audio files

1.0.2

  • Updated source link and added update link

1.0.1

  • Improved code and fixed a ton of bugs
  • Uploaded to github

1.0.0

  • Created plugin

@Gokusolos3
Copy link

Gokusolos3 commented Feb 23, 2024

Does this work for the browser? Or is it only the app itself? I don't understand GitHub well but it doesn't seem to be working for either the browser or the app.

@FrostBird347
Copy link
Author

FrostBird347 commented Feb 23, 2024

It won't run in the browser on it's own, however it wouldn't be that difficult to modify the plugin to work in the browser.
(Note that this is a betterdiscord plugin)

@Gokusolos3
Copy link

Thank you so much I just now realized this😭🙏

@Gokusolos3
Copy link

So remember when I said "I don't understand GitHub well"? I don't, I don't know what I'm doing at all. 😭

@FrostBird347
Copy link
Author

FrostBird347 commented Feb 27, 2024

  • Click on the "View Raw" button in the top right corner of the code (or open on the link).
  • Press Command/Control+S or right click and click on "save as"
  • 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)

@Gokusolos3
Copy link

Gokusolos3 commented Feb 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment