Created
February 11, 2023 18:52
-
-
Save Kyiro/6877eef00c1083c8e519e9cf81bb73f7 to your computer and use it in GitHub Desktop.
Userscript that replaces the Dbree audio player with the browser default
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
// ==UserScript== | |
// @name Dbree Alt Player | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Replaces the Dbree audio player with the browser default | |
// @author Kyiro | |
// @match *://dbree.org/v/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=dbree.org | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
const audioExtensions = { | |
"aac": true, | |
"mp3": true, | |
"wav": true, | |
"flac": true, | |
"m4a": true, | |
"mp4": false, | |
"ogg": false, | |
"webm": false, | |
}; | |
function getExtension(url) { | |
return url.split(/[#?]/)[0].split('.').pop().trim(); | |
} | |
function replacePlayer(fileURL) { | |
const embed = document.getElementById("embed"); | |
const fileExtension = getExtension(fileURL); | |
const mediaPlayer = document.createElement(audioExtensions[fileExtension] ? "audio" : "video"); | |
mediaPlayer.controls = true; | |
mediaPlayer.src = fileURL; | |
mediaPlayer.style.width = "100%"; | |
mediaPlayer.style.height = "100%"; | |
embed.parentElement.appendChild(mediaPlayer); | |
embed.remove(); | |
} | |
(function main() { | |
const scriptTags = document.getElementsByTagName("script"); | |
for (const scriptTag of scriptTags) { | |
const matches = scriptTag.innerHTML.match(/'file':\s?'([^']+)'/); | |
if (!matches || matches.length < 1) continue; | |
replacePlayer(matches[1]); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment