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

214
Views
¿Por qué el botón Copiar copia 'indefinido' en lugar de copiar el valor de html dom?

Estoy tratando de hacer mi propia secuencia de comandos de usuario para https://mlwbd.ltd/movie/don-2022

Deseo copiar el valor de la entrada oculta especificada

 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])

El código HTML es

tipo de entrada = "oculto" nombre = "FU" valor = "https://songslyric.site/links/46905/"
Quiero copiar el valor de name="FU" cuando hago clic en el botón. El código que pegué se crea a partir de fragmentos de Google Chrome. Por favor, ayúdame.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esto lo ayudará a comenzar:

 // ==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(); }

Notas:

  1. A pesar del carácter $ , este código no es jQuery (es javascript vainilla)
  2. Puede descomentar alert() y console.log para ver cómo funcionan las cosas en ese momento.
about 4 years ago · Juan Pablo Isaza Report

0

Prueba esto en tu otra pregunta:

 // ==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(); }

Notas:

  1. Puede comparar esta respuesta con la anterior y notará que solo ha cambiado una línea.

  2. El tema a estudiar para entender cómo hacer referencia al scaffolding HTML como lo hice yo se llama: "Selectores CSS". La directiva JavaScript querySelector() usa selectores CSS para apuntar específicamente a la etiqueta HTML deseada.

about 4 years ago · Juan Pablo Isaza Report
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!