Injected javascript on youtube with violentmonkey in hopes to make the download button link to a yt1s with current video url. Can't get the DOM of the download button after changing video (the button in question changes / site doesn't reset but maintains the current instance from what I understand).
// ==UserScript==
// @name Usable youtube download button
// @namespace Violentmonkey Scripts
// @match https://www.youtube.com/watch
// @include https://*.youtube.com/*
// @grant none
// @version 1.0
// @author Nojyto
// ==/UserScript==
(function() {
const API = "https://yt1s.com/en/youtube-to-mp3?q="
console.log("-----------start--------------")
function waitForElm(selector){
return new Promise(resolve => {
if(document.querySelector(selector)){
return resolve(document.querySelector(selector))
}
const observer = new MutationObserver(mutations => {
if(document.querySelector(selector)){
resolve(document.querySelector(selector))
observer.disconnect()
}
})
observer.observe(document.body, {
childList: true,
subtree: true
})
})
}
function updateButton(){
waitForElm("#top-level-buttons-computed > ytd-download-button-renderer > ytd-button-renderer > a:nth-child(1)").then((url) => {
console.log("-----------change btn--------------")
if(url.id === "changed" || !document.body.contains(url)){
url.remove()
console.log("removed")
updateButton()
return
}
url.href = API + encodeURIComponent(window.location.href)
url.target = "_blank"
url.id = "changed"
url.style.color = "lightblue"
console.log(url)
console.log(url.href)
//console.log(url.href)
//console.log("-----------Script end--------------")
//document.getElementsByTagName("tp-yt-paper-dialog")[0].remove()
//document.getElementsByTagName("ytd-popup-container")[0].remove()
})
}
window.onload = updateButton;
window.addEventListener("yt-navigate-start", updateButton, true)
})()