Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Can't get DOM of visible download button after site update

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)
})()
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!