Copiar TODOS los elinks en CRG

Anade un boton javascript para copiar TODOS los elinks

当前为 2019-12-03 提交的版本,查看 最新版本

// ==UserScript==
// @name     Copiar TODOS los elinks en CRG
// @version  2.1
// @description  Anade un boton javascript para copiar TODOS los elinks
// @author       El intruso
// @match        http://lamansion-crg.net/forum/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @namespace https://greasyfork.org/users/407027
// @grant    none
// ==/UserScript==

var htmlBoton = "<button type='button' id='botonJS' style='position: absolute;top:0;left:0;'><img src='http://lamansion-crg.net/forum/style_images/nuevo/p_elinks.gif'/>Copiar elinks</button>";
var patronEd2k = /^ed2k:///i ;
var textoACopiar = '';

$('a').each(function (index, value) {
  var href = $(this).attr('href');
  if (patronEd2k.test(href))  //console.log('a' + index + ':' + href);
  	textoACopiar += href + '\n';
});
  
console.log(textoACopiar);

if(textoACopiar){
  $(document.body).append(htmlBoton);
  $("#botonJS").bind('click',function(){
    copiarAlPortapapeles(textoACopiar);
    var audio = new Audio('http://lamansion-crg.net/forum/indexado/ding.mp3');
    audio.play();
  } );
}


function copiarAlPortapapeles(text) {
                var id = "mycustom-clipboard-textarea-hidden-id";
                var existsTextarea = document.getElementById(id);

                if (!existsTextarea) {
                    console.log("Creating textarea");
                    var textarea = document.createElement("textarea");
                    textarea.id = id;
                    // Place in top-left corner of screen regardless of scroll position.
                    textarea.style.position = 'fixed';
                    textarea.style.top = 0;
                    textarea.style.left = 0;

                    // Ensure it has a small width and height. Setting to 1px / 1em
                    // doesn't work as this gives a negative w/h on some browsers.
                    textarea.style.width = '1px';
                    textarea.style.height = '1px';

                    // We don't need padding, reducing the size if it does flash render.
                    textarea.style.padding = 0;

                    // Clean up any borders.
                    textarea.style.border = 'none';
                    textarea.style.outline = 'none';
                    textarea.style.boxShadow = 'none';

                    // Avoid flash of white box if rendered for any reason.
                    textarea.style.background = 'transparent';
                    document.querySelector("body").appendChild(textarea);
                    console.log("The textarea now exists :)");
                    existsTextarea = document.getElementById(id);
                } else {
                    console.log("The textarea already exists :3")
                }

                existsTextarea.value = text;
                existsTextarea.select();

                try {
                    var status = document.execCommand('copy');
                    if (!status) {
                        console.error("Cannot copy text");
                    } else {
                        console.log("The text is now on the clipboard");
                    }
                } catch (err) {
                    console.log('Unable to copy.');
                }
}