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

216
Visualizações
Why does Copy button copy 'undefined' instead of copying value from html dom?

I'm trying to make my own user script for https://mlwbd.ltd/movie/don-2022

I wish to copy the value of specified hidden input

preTag = document.getElementsByName("FU");
p = preTag[0];
console.log(p);

Ekra = document.getElementsByClassName("linktabs");
q = Ekra[0];
console.log(q);

function copy(ele) {
    let temp = document.createElement('textarea');
    document.body.appendChild(temp);
    temp.value = ele.textContent;
    temp.select();
    document.execCommand('copy');
    temp.remove();
}

btn = document.createElement("button");
btn.innerHTML = "copy"
btn.onclick = function(){
    copy("p");
};

q.insertBefore(document.createElement("br"), q.childNodes[0])
q.insertBefore(btn, q.childNodes[0])

The Html code is

input type="hidden" name="FU" value="https://songslyric.site/links/46905/" 
I want to copy the Value of name="FU" when I click the button. The code I pasted is created from google chrome snippets. Please help me.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This will get you started:

// ==UserScript==
// @name         mlwbd.ltd
// @namespace    http://tampermonkey.net/
// @version      0.1
// @match        https://mlwbd.ltd/movie/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const $ = document.querySelector.bind(document);

    $('body').insertAdjacentHTML('beforeend', init_css() );

    setTimeout(() => {
        $('#mybutt').addEventListener('click', () => {
            //alert('hi');
            const fu = $('#download table form input[name=FU]');
            //console.log(fu.value);
            copy2clip(fu);
        });
    },500);


})();
function init_css(){
    return `
    <button id="mybutt">Copy2Clip</button>
    <style id="myInitCss">
        #mybutt{position:absolute;top:90px;left:45%;height:30px;width:120px;}
        #mybutt{background:#0073ea;color:white;padding-top:5px;text-align:center;}
        #mybutt{z-index:99999;}
    </style>
    `;
}
function copy2clip(ele) {
    let temp = document.createElement('textarea');
    document.body.appendChild(temp);
    temp.value = ele.value;
    temp.select();
    document.execCommand('copy');
    temp.remove();
}

Notes:

  1. Despite the $ character, this code is not jQuery (it is vanilla javascript)
  2. You can uncomment the alert() and console.log to see how things are working at that point.
about 4 years ago · Juan Pablo Isaza Relatório

0

Try this on your other question:

    // ==UserScript==
    // @name         adsgo.digital
    // @namespace    http://tampermonkey.net/
    // @version      0.1
    // @include        https://adsgo.digital/
    // @include        https://adsgo.digital/*
    // @grant        none
    // ==/UserScript==

    (function() {
        'use strict';
        const $ = document.querySelector.bind(document);

        $('body').insertAdjacentHTML('beforeend', init_css() );

        setTimeout(() => {
            $('#mybutt').addEventListener('click', () => {
                //alert('hi');
                const fu = $('.posts-dynamic.posts-container form input[name=FU6]');
                //console.log(fu.value);
                copy2clip(fu);
            });
        },500);


    })();
    function init_css(){
        return `
        <button id="mybutt">Copy2Clip</button>
        <style id="myInitCss">
            #mybutt{position:absolute;top:90px;left:45%;height:30px;width:120px;}
            #mybutt{background:#0073ea;color:white;padding-top:5px;text-align:center;}
            #mybutt{z-index:99999;}
        </style>
        `;
    }
    function copy2clip(ele) {
        let temp = document.createElement('textarea');
        document.body.appendChild(temp);
        temp.value = ele.value;
        temp.select();
        document.execCommand('copy');
        temp.remove();
    }

Notes:

  1. You can compare this answer to the previous one and you'll notice that only one line has changed.

  2. The topic to study to understand how to reference the HTML scaffolding as I did is called: "CSS Selectors". The JavaScript querySelector() directive uses CSS selectors to specifically target the desired HTML tag.

about 4 years ago · Juan Pablo Isaza Relatório
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