Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda