// ==UserScript== // @name 追新番复制所有磁力链接 // @include *zhuixinfan.com/viewtvplay* // @namespace http://tampermonkey.net/ // @version 2.0 // @description 追新番快捷复制所有磁力链接 // @author leeyang1990@gmail.com // @grant GM_xmlhttpRequest // @downloadURL none // ==/UserScript== (function() { "use strict"; createAllMagnetLinkButton(); })(); function createAllMagnetLinkButton() { const filterTabElement = document.querySelectorAll(".filter-tab"); if (filterTabElement && filterTabElement[0]) { const span = document.createElement("span"); span.className = "a y"; span.setAttribute("style", `margin:auto 2px;cursor:pointer`); const a = document.createElement("a"); a.textContent = "复制全部磁力链接"; span.appendChild(a); span.addEventListener( "click", function() { onAllMagnetLinkClick(onRequstAllMagnetLinkFinish); }, false ); filterTabElement[0].appendChild(span); } } //复制全部磁力链接按钮的回调 function onAllMagnetLinkClick(callback) { const list = getAllEpisodeUrls(); const all = []; for (let index = 0; index < list.length; index++) { const link = list[index]; getDocument(link, document => { all.push(getMagnetLink(document)); if (all.length == list.length) { console.log("done"); callback(all.join("\n")); } }); } } function onRequstAllMagnetLinkFinish(murl) { window.Clipboard.copy(murl); } //获取全部剧集的url function getAllEpisodeUrls() { const urls = []; const list = document.getElementById("ajax_tbody").querySelectorAll(".td2"); for (let i = 0; i < list.length; i++) { urls.push(list[i].children[0].href); } return urls; } function getDocument(_url, callback) { GM_xmlhttpRequest({ method: "GET", url: _url, overrideMimeType: "text/html", onload: function(response) { const parser = new DOMParser(); const doc = parser.parseFromString(response.responseText, "text/html"); callback(doc); } }); } function getMagnetLink(document) { return document.getElementById("torrent_url").innerText; } window.Clipboard = (function(window, document, navigator) { let textArea, copy; // 判断是不是ios端 function isOS() { return navigator.userAgent.match(/ipad|iphone/i); } //创建文本元素 function createTextArea(text) { textArea = document.createElement("textArea"); textArea.value = text; document.body.appendChild(textArea); } //选择内容 function selectText() { let range, selection; if (isOS()) { range = document.createRange(); range.selectNodeContents(textArea); selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range); textArea.setSelectionRange(0, 999999); } else { textArea.select(); } } //复制到剪贴板 function copyToClipboard() { try { if (document.execCommand("Copy")) { alert("复制成功!"); } else { alert("复制失败!请手动复制!"); } } catch (err) { alert("复制错误!请手动复制!"); } document.body.removeChild(textArea); } copy = function(text) { createTextArea(text); selectText(); copyToClipboard(); }; return { copy: copy }; })(window, document, navigator);