Last active
January 24, 2023 02:17
-
-
Save Kyiro/a31c201d67781ca0715e13bb2ba1ccaa to your computer and use it in GitHub Desktop.
Media Player for anonfiles.com
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 Anonfiles Audio Player | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Adds a media player to anonfiles.com | |
// @author Kyiro | |
// @match *://anonfiles.com/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=anonfiles.com | |
// @grant none | |
// @run-at document-body | |
// ==/UserScript== | |
// Not the best solution but whatever | |
const audioExtensions = { | |
"aac": true, | |
"mp3": true, | |
"wav": true, | |
"flac": true, | |
"mp4": false, | |
"ogg": false, | |
"webm": false, | |
}; | |
function getExtension(url) { | |
return url.split(/[#?]/)[0].split('.').pop().trim(); | |
} | |
function main() { | |
const downloadButton = document.getElementById("download-url"); | |
const footer = document.getElementById("footer"); | |
if (!downloadButton || !footer) return; | |
const downloadURL = downloadButton.href; | |
const fileExtension = getExtension(downloadURL); | |
if (audioExtensions[fileExtension] == undefined) return; | |
const container = document.createElement("div"); | |
container.style.marginTop = "20px"; | |
const mediaPlayer = document.createElement(audioExtensions[fileExtension] ? "audio" : "video"); | |
mediaPlayer.controls = true; | |
mediaPlayer.src = downloadURL; | |
mediaPlayer.style.width = "100%"; | |
container.appendChild(mediaPlayer); | |
footer.insertBefore(container, footer.firstChild); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment