您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
各种开车网站的优化
当前为
// ==UserScript== // @name tianteng // @namespace https://greasyfork.org/xmlspy // @version 1.4.4 // @description 各种开车网站的优化 // @author xmlspy // @license MIT // @require https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js // @include * // @connect * // @run-at document-start // @grant GM_xmlhttpRequest // @grant GM.setClipboard // @grant GM.xmlhttpRequest // @grant GM_openInTab // @grant unsafeWindow // @grant GM_log // @grant GM_info // ==/UserScript== /* 1. 以下开车的网站经常换域名,本程序使用特征识别,不使用网址进行判断, 即使域名换了也能识别并进入本程序(skrbt,javbus,紳士漫畫,JAVLibrary,BTSOW,松鼠症倉庫) 2. javbus, * 所有页面,搜索按钮后面都添加"粘贴&搜索"按钮,点击后复制剪贴板的内容到搜索框并自动点击搜索按钮 * 所有页面,添加"打开skrbt"的链接 * 所有页面,添加"打开今日新帖"按钮,一键打开老司机福利讨论区的今日新帖,最多30个 * 影片明细页面,添加复制车牌号按钮,删除磁链的onclick事件(否则会执行两次打开磁链事件),添加 在javlibrary中打开 * 论坛明细页面,为每个磁力链后面添加"复制磁链"和"打开磁链"按钮,为每个回复添加"复制所有磁链","打开所有磁链","复制所有磁链(不含点评)"和"打开所有磁链(不含点评) 4个按钮(气死各种课代表) 3. 松鼠症倉庫,去除点击广告 4. 紳士漫畫, * 明细页面,添加搜索框 * 下拉阅读页面,图片由一列改为两列 * 所有页面, 为搜索框后面添加 粘贴&搜索 按钮 5. JAVLibrary, * 所有页面,添加 打开skrbt 链接 * 所有页面,添加 粘贴&搜索 按钮 * 所有页面,删除 url重定向 * 详情页面,添加 复制车牌 按钮 * 详情页面,添加 javbus中查询 链接 * 详情页面,删除 名称中的链接,否则很容易误点,又不容易复制文字 6. BTSOW,添加 粘贴&搜索 按钮 7. skrbt, * 所有页面,添加 粘贴&搜索 按钮 * 搜索结果列表页面,每条结果后面都添加 "复制磁链"和"点击磁链"按钮,不用进入明细页面 8. 知乎,添加 粘贴&搜索 按钮 9. 百度,添加 粘贴&搜索 按钮 ====================更新记录 * 2024-7-18 * javbus * 所有页面,添加"打开今日新帖"按钮,一键打开老司机福利讨论区的今日新帖,最多30个 * 2024-7-16 * javbus * 影片明细页面添加 在javlibrary中打开; * 论坛明细页面,为每个回复添加"复制所有磁链","打开所有磁链","复制所有磁链(不含点评)"和"打开所有磁链(不含点评) 4个按钮 */ (function () { "use strict"; /** * skrbt */ const skrbtDomain = "skrbtqx"; const skrbtHost = skrbtDomain + ".top"; const skrbtUrl = "https://" + skrbtHost; /** * javbus */ const javbusDomain = "busfan"; const javabusUrl = `https://www.${javbusDomain}.shop`; /** * javLibrary */ var javLibDomain = "y78k"; var javLibUrl = "https://www." + javLibDomain + ".com"; let javLibRegx = "(" + javLibDomain + "|javlib|javlibrary)"; const enableDebug = true; let seq = 0; // function (){} // // 获取 HTMLElement 构造函数 // const HTMLElementConstructor = HTMLElement; // // 创建一个代理对象来拦截 HTMLElement 的构造函数 // const HTMLElementProxy = new Proxy(HTMLElementConstructor, { // construct(target, args, newTarget) { // console.log("Creating a new HTMLElement instance"); // // 创建一个新的 HTMLElement 实例 // const instance = new target(...args); // // 返回一个新的代理对象来拦截实例的属性和方法 // return new Proxy(instance, { // get(target, prop, receiver) { // console.log(`Accessing property: ${prop}`); // return Reflect.get(target, prop, receiver); // }, // set(target, prop, value, receiver) { // console.log(`Setting property: ${prop} to ${value}`); // return Reflect.set(target, prop, value, receiver); // }, // has(target, prop) { // console.log(`Checking if property exists: ${prop}`); // return Reflect.has(target, prop); // }, // deleteProperty(target, prop) { // console.log(`Deleting property: ${prop}`); // return Reflect.deleteProperty(target, prop); // }, // ownKeys(target) { // console.log(`Enumerating properties`); // return Reflect.ownKeys(target); // }, // getOwnPropertyDescriptor(target, prop) { // console.log(`Getting property descriptor for: ${prop}`); // return Reflect.getOwnPropertyDescriptor(target, prop); // }, // defineProperty(target, prop, descriptor) { // console.log(`Defining property: ${prop}`); // return Reflect.defineProperty(target, prop, descriptor); // }, // }); // }, // }); // // 替换全局的 HTMLElement 构造函数 // Object.defineProperty(window, "HTMLElement", { // value: HTMLElementProxy, // writable: false, // configurable: false, // }); // // 测试 // const div = document.createElement("div"); // div.innerHTML = "Hello, World!"; // console.log(div.innerHTML); // div.innerHTML = "Hello, Proxy!"; // console.log(div.innerHTML); ///////////////////////////////////////////////////////////////////////////// // 事件拦截 ///////////////////////////////////////////////////////////////////////////// debug(document.querySelector("title")); //松鼠症倉庫 地址发布页 https://ahrilist.top/ const ep = EventTarget.prototype; // setTimeout(function () { // if (!isNativeCode(ep.addEventListener)) { // debug(`addEventListener 原型被更改为:${ep.addEventListener.toString()}`); // } // }); // if(!ep.constructorOriginal){ // ep.constructorOriginal = ep.constructor; // ep.constructor=function(){ // debug('构造器'); // this.constructorOriginal(); // } // } // function monster1(disposition) { // this.disposition = disposition; // } // const handler1 = { // construct(target, args) { // console.log(`Creating a ${target.name}`); // // Expected output: "Creating a monster1" // return new target(...args); // }, // }; // const proxy1 = new Proxy(monster1, handler1); // console.log(new proxy1('fierce').disposition); if (!ep.addEventListenerOriginal) { ep.addEventListenerOriginal = ep.addEventListener; ep.addEventListener = function (type, callback, options) { // if (/ahri8\.top/.test(window.location.href)) { // debug(`添加事件监听器:target: ${this} type: ${type} callback: ${callback} options: ${options}`); if (this) { ///////////////////////////////////////////////////////////////////////////// // 松鼠症倉庫 ///////////////////////////////////////////////////////////////////////////// if ( this.className && this.className.includes && this.className.includes("apo") ) { debug("禁止点击广告", "松鼠症倉庫"); return; } // } this.allListeners = this.allListeners || []; this.allListeners.push({ type, callback, options }); // this.addEventListenerOriginal(type, callback, options); this.addEventListenerOriginal.apply(this, arguments); } else { debug( `[this] is bad. type: ${type} callback: ${callback} options: ${options}`, "addEventListenerHook" ); } }; } if (!ep.removeEventListenerOriginal) { ep.removeEventListenerOriginal = ep.removeEventListener; ep.removeEventListener = function (type, callback, options) { if (this) { this.removeEventListenerOriginal.apply(this, arguments); this.allListeners = this.allListeners || []; const index = this.allListeners.indexOf({ type, callback, options }); if (index != -1) { this.allListeners.splice(index, 1); } } else { debug( `[this] is bad. type: ${type} callback: ${callback} options: ${options}`, "removeEventListenerHook" ); } }; } ///////////////////////////////////////////////////////////////////////////// // 节点变化监控 ///////////////////////////////////////////////////////////////////////////// new MutationObserver(function (mutationsList, observer) { // Use traditional 'for loops' for IE 11 // console.log(mutationsList); for (let mutation of mutationsList) { if (mutation.type === "childList") { const target = mutation.target; if (target["id"] == "magnet-table") { debug(mutation.addedNodes); } } else if (mutation.type === "attributes") { if (mutation.attributeName.startsWith("on")) { debug(mutation, "MutationObserver"); // debug(`target: ${mutation.target}`); } } } }).observe(document, { childList: true, subtree: true, attributes: true, //attributeFilter: [], attributeOldValue: true, characterData: false, characterDataOldValue: false, }); // execute(()=>{},()=>{}); /////////////////////////////////////////////////////////////////////////// // jquery.ready /////////////////////////////////////////////////////////////////////////// $(function () { // execute("松鼠症倉庫", /ahri8\.top/, () => { // removeEvents(document.querySelectorAll("a.apo"), "click"); // debug("-------------------------------------------------------xxxx"); // }); /////////////////////////////////////////////////////////////////////////// // oschina /////////////////////////////////////////////////////////////////////////// execute("开源中国", /oschina\.net/, () => { debug("修改首页某些链接无法中键点击问题.", "开源中国"); $(`[data-href]`).each(function () { const $this = $(this); const href = $this.attr("data-href"); const classCss = $this.attr("class"); const title = $this.attr("title"); const innerHtml = this.innerHTML; const html = `<a target="_blank" title="${title}" href="${href}" class="${classCss}">${innerHtml}</a>`; $this.replaceWith(html); }); debug("删除url中的重定向.", "开源中国"); $('a[href*="/action/GoToLink?url"]').each(function (index) { // https://www.oschina.net/action/GoToLink?url=https%3A%2F%2Fcode.visualstudio.com%2Fupdates%2Fv1_91 var url = getQueryVariable(this, "url"); this.href = decodeURIComponent(url); }); }); /////////////////////////////////////////////////////////////////////////// // gitee.com /////////////////////////////////////////////////////////////////////////// execute("gitee", /gitee\.com/, () => { debug("删除url中的重定向.", "gitee"); $('a[href*="/link?target"]').each(function (index) { var url = getQueryVariable(this, "target"); this.href = decodeURIComponent(url); }); }); /////////////////////////////////////////////////////////////////////////// // 紳士漫畫永久域名: wnacg.com 紳士漫畫永久地址發佈頁: wnacg.date /////////////////////////////////////////////////////////////////////////// execute("紳士漫畫", $('head>title:contains("紳士漫畫")'), () => { if (location.href.includes("photos-index-aid")) { debug("明细页面添加搜索框", "紳士漫畫"); const searchInput = ` <div class="search" style="float:right;"> <form id="album_search q-form" action="/search/" method="get" _lpchecked="1"> <div class="input-append" id="q-input"> <input type="text" class="search-query ui-autocomplete-input tips" name="q" value="" title="搜索漫畫" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"> <input style="display:none" type="radio" name="f" value="_all" checked=""> <input style="display:none" name="s" value="create_time_DESC"> <input style="display:none" name="syn" value="yes"> <button type="" name=""></button> </div> </form> </div> `; $("#bodywrap").prepend(searchInput); } if (location.href.includes("photos-slide-aid")) { debug("下拉阅读页面,图片由一列改为两列", "紳士漫畫"); const nodeToObserve = document.querySelector("#img_list"); $(nodeToObserve).css({ width: "100%", display: "flex", "flex-wrap": "wrap", "justify-content": "flex-start", "overflow-x": "hidden", }); const imgWidth = document.documentElement.clientWidth / 2 - 10; const imgHeight = document.documentElement.clientHeight - 50; new MutationObserver((mutations, observer) => { $("#img_list>div").css({ flex: "1", "background-color": "#cacaca", margin: "0 5px 5px 0", width: "calc((100% - 10px) / 2)", "min-width": "calc((100% - 10px) / 2)", "max-width": "calc((100% - 10px) / 2)", }); $("#img_list>div>img").on("load", (e) => { drawImage(e.target, imgWidth, imgHeight); }); }).observe(nodeToObserve, { childList: true }); } if ($("input.search-query").length > 0) { debug("为搜索框后面添加 粘贴&搜索 按钮", "紳士漫畫"); const $pasteAndSearchButton = $( `<button style="float:right;height:30px;">粘贴&搜索</button>` ); $("#bodywrap").prepend($pasteAndSearchButton); $pasteAndSearchButton.on("click", () => { navigator.clipboard.readText().then((clipText) => { if (clipText != null && $.trim(clipText) != "") { $("[name=q]").val($.trim(clipText)); $("#q-input > button").click(); } }); }); } }); /////////////////////////////////////////////////////////////////////////// // JAVLibrary /////////////////////////////////////////////////////////////////////////// execute("JAVLibrary", $('head>title:contains("JAVLibrary")'), () => { // ---- 所有页面 // 删除广告 $(".socialmedia,#bottombanner13,#topbanner11,#sidebanner11").remove(); $("#leftmenu>div>ul:nth-child(2)>li:nth-child(2)").remove(); // 调节UI $("#content").css("padding-top", "10px"); $("#toplogo").css("height", "50px"); $("#toplogo").find('img[src*="logo-top"]').attr("height", "40"); // 添加 打开skrbt 连接 $(".advsearch").append( ` <a href="${skrbtUrl}" target="_blank">打开skrbt</a>` ); // 添加 粘贴&搜索 按钮 const styleMap = {}; $("#idsearchbutton")[0] && $("#idsearchbutton")[0] .computedStyleMap() .forEach((value, key) => { styleMap[key] = value; }); const $pasteAndSearchButton = $( `<input type="button" value="粘贴&搜索" id="pasteAndSearch"></input>` ); $pasteAndSearchButton.css(styleMap); $pasteAndSearchButton.click(() => { navigator.clipboard.readText().then((clipText) => { if (clipText != null && $.trim(clipText) != "") { $("#idsearchbox").val(clipText); $("#idsearchbutton").click(); } }); }); $("#idsearchbutton").parent().append($pasteAndSearchButton); // 恢复原始url,删除重定向 $.each($("a[href^='redirect.php?url']"), function (index, a) { var url = getQueryVariable(a, "url"); a.href = decodeURIComponent(url); if (!a.href.startsWith("https")) { a.href = a.href.replace("http", "https"); } a.text = a.text + " " + a.href + " "; if (a.href.includes("yimuhe")) { $(a) .parentsUntil("tr") .closest(".t") .css("background-color", "#6B6C83"); a.style = "font-size:20px;"; } else { a.style = "font-size:20px;"; } }); // ---- 详情页面 if (/.*\?v=.*/.test(location.href)) { // 添加 复制车牌 按钮 let chePai = document.querySelector( "#video_id > table > tbody > tr > td.text" ).innerText; let toAppendElement = document.querySelector( "#video_id > table > tbody > tr > td.text" ); appendCopyButton(chePai, toAppendElement); // 添加 javbus中查询 链接 let trTag = document.querySelector("#video_id > table > tbody > tr"); let javdbQueryId = "javdbQueryId"; trTag.innerHTML = [ trTag.innerHTML, '<td><a id="', javdbQueryId, '"href="', javabusUrl, "/", chePai, '">javbus中查询</a></td>', ].join(""); // 添加 用SkrBt搜索 链接 $(trTag).append( [ '<td><a target="_blank" ', 'href="', skrbtUrl, "/search?keyword=", chePai, '">用SkrBt搜索 </a></td>', ].join("") ); // 删除名称中的链接,否则很容易误点,又不容易复制文字 const videoTitleNode = document.querySelector("#video_title > h3 > a"); if (videoTitleNode) { const videoTitle = videoTitleNode.getInnerHTML(); videoTitleNode.parentNode.innerText = videoTitle; } } }); /////////////////////////////////////////////////////////////////////////// // 永久域名:https://www.javbus.com 防屏蔽地址:https://www.fanbus.help // 防屏蔽地址:https://www.javsee.help 防屏蔽地址:https://www.buscdn.help /////////////////////////////////////////////////////////////////////////// execute( "javbus", [ $('head>title:contains("JavBus")'), // /genre/hd , /genre/sub $("body > nav > div > div.navbar-header.mh50 > a > img[alt='JavBus']"), // 论坛 "#toptb.jav-nav", ], () => { debug("添加 粘贴&搜索 按钮", "javbus"); const searchButton = $( "button[onclick=\"searchs('search-input')\"]:first" ); const searchInput = $("#search-input:first"); addPasteAndSearchButton(searchButton, searchInput); // 调整样式 $(".nav>li>a").attr("style", "padding-left:8px;padding-right:8px;"); debug("添加 打开skrbt 链接", "javbus"); //添加skrbt链接 $(".nav-title.nav-inactive:last,ul.nav.navbar-nav:first").append(` <li class="hidden-md hidden-sm"> <a href="${skrbtUrl}" target="_blank">打开skrbt</a> </li> `); debug("添加 打开今日新帖 按钮", "javbus"); let todayNewButton = $( `<button id="tiantengTodayNew" class="jav-button btn btn-default" title="打开老司机福利讨论区的今日新帖,最多30个" style="margin-top:7px;"> 打开今日新帖 </button>` ); $(".nav-title.nav-inactive:last,ul.nav.navbar-nav:first").append( todayNewButton ); todayNewButton.click(function () { const origin = location.origin; // 老司机福利讨论区 const talkUrl = `${origin}/forum/forum.php?mod=forumdisplay&fid=2&filter=author&orderby=dateline&dateline=86400`; // 求福利带带我 const askUrl = `${origin}/forum/forum.php?mod=forumdisplay&fid=36&filter=author&orderby=dateline&dateline=86400`; const now = new Date(); const today = `${now.getFullYear()}-${ now.getMonth() + 1 }-${now.getDate()}`; async function getPostData(url, date, pageNum) { // pageNum= pageNum ?? 1; // url = url+'&page='+'pageNum' const r = await GM.xmlHttpRequest({ url: url, headers: { Accept: `text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7`, "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9", "Cache-Control": "max-age=0", }, }).catch((e) => console.error(e)); const data = $(r.responseXML); const result = []; $(".post_inforight", data).each(function (index) { const date = $("span.dateline>span", $(this)).attr("title"); if (date === today) { let postUrl = $("a.s", $(this)).attr("href"); result.push(`${origin}/forum/${postUrl}`); // if (index == 29) { // //获取下一页数据 // await // } } }); return result; } getPostData(talkUrl).then(function (urlArray) { $(urlArray).each(function () { GM_openInTab(this, true); }); }); }); // ----- 明细页面 let chePaiNode = document.querySelector( "body > div.container > div.row.movie > div.col-md-3.info > p:nth-child(1) > span:nth-child(2)" ); if (chePaiNode) { debug("添加复制车牌号按钮", "javbus"); const chePai = chePaiNode.innerText.trim(); const toAppendElement = document.querySelector( "body > div.container > div.row.movie > div.col-md-3.info > p:nth-child(1)" ); appendCopyButton(chePai, toAppendElement); debug("删除磁力链接中的onclick事件", "javbus"); setInterval(() => $("#magnet-table td").removeAttr("onclick"), 1000); debug("添加 在javlibrary中打开", "javabus"); //https://www.y78k.com/cn/vl_searchbyid.php?keyword=SUJI-241 const javLibLink = `<a href="${javLibUrl}/cn/vl_searchbyid.php?keyword=${chePai}">在javlib中打开</a>`; $(toAppendElement).append(javLibLink); } // ---- 论坛明细页面 if (location.href.includes("mod=viewthread")) { debug("为磁链添加按钮", "javbus"); function toAlienMagnet(magnet, alien) { alien = alien ? alien : "-"; let part1 = magnet.slice(0, 21); let part2 = magnet.slice(21); return `${part1}${alien}${part2}`; } function toNormalMagnet(magnet, alien) { alien = alien ? alien : "-"; return magnet.replace(alien, ""); } function getMagnetRegExp(alien) { if (alien) { return new RegExp( `(?:magnet:\\?xt=urn:btih:)?(?:(?:[0-9a-f]{1}${alien}[0-9a-f]{39})|(?:[2-7a-zA-Z]${alien}[2-7a-zA-Z]{31}))`, "gim" ); } else { return /(?:magnet:\?xt=urn:btih:)?(?:[0-9a-fA-F]{40}|[2-7a-zA-Z]{32})/gim; } } function completeMagnet(magnet) { if (!magnet) { return magnet; } if (magnet.length === 32 || magnet.length === 40) { return `magnet:?xt=urn:btih:${magnet}`; } return magnet; } // 所有按钮的点击事件处理 $(document).on( "click", 'button[class*="tianteng-button"]', function (e) { let button = $(e.target); let buttonType = button.data("tiantengButton"); // 复制磁链 if (buttonType === "copy") { let magnet = button.data("tiantengMagnet"); GM.setClipboard(toNormalMagnet(magnet), "text"); return; } // 打开磁链 if (buttonType === "click") { let magnet = button.data("tiantengMagnet"); setTimeout(() => window.open(toNormalMagnet(magnet)), 500); return; } // 复制所有磁链 if (buttonType === "copyAll") { let postId = button.data("tiantengPostId"); let magnets = ""; $(`[data-tianteng-button="copy"]`, $(`#${postId}`)).each( function () { let magnet = $(this).data("tiantengMagnet"); magnets = magnets + toNormalMagnet(magnet) + "\n"; } ); GM.setClipboard(magnets, "text"); return; } // 打开所有磁链 if (buttonType === "clickAll") { let postId = button.data("tiantengPostId"); $(`[data-tianteng-button="copy"]`, $(`#${postId}`)).each( function () { let magnet = $(this).data("tiantengMagnet"); magnet = toNormalMagnet(magnet); setTimeout(() => window.open(toNormalMagnet(magnet)), 500); } ); return; } // 复制所有磁链(不含点评) if (buttonType === "copyAllNot") { let postId = button.data("tiantengPostMessageId"); let magnets = ""; $(`[data-tianteng-button="copy"]`, $(`#${postId}`)).each( function () { let magnet = $(this).data("tiantengMagnet"); magnets = magnets + toNormalMagnet(magnet) + "\n"; } ); GM.setClipboard(magnets, "text"); return; } // 打开所有磁链(不含点评) if (buttonType === "clickAllNot") { let postId = button.data("tiantengPostMessageId"); $(`[data-tianteng-button="copy"]`, $(`#${postId}`)).each( function () { let magnet = $(this).data("tiantengMagnet"); magnet = toNormalMagnet(magnet); setTimeout(() => window.open(toNormalMagnet(magnet)), 500); } ); return; } } ); // end 所有按钮事件 let magnetRegExp = getMagnetRegExp(); // 先处理a标签元素中的磁链,加上标记 $(`div[id^="post_"] a[href^="magnet:?xt=urn:btih:"]`).each( function () { let magnetAlien = completeMagnet($(this).attr("href")); magnetAlien = toAlienMagnet(magnetAlien); // $(this).data('tiantengStatus','@'); let html = this.outerHTML.replace( magnetRegExp, (match, offset, str) => toAlienMagnet(completeMagnet(match), "@") ); html = html.replace("href", `data-tianteng-status="ok" href`); html = `${html} <button style="margin:0;padding:3px;" class="jav-button tianteng-button" data-tianteng-button="copy" data-tianteng-magnet="${magnetAlien}" type="button">复制磁链 </button> <button style="margin:0;padding:3px;" class="jav-button tianteng-button" data-tianteng-button="click" data-tianteng-magnet="${magnetAlien}" type="button">打开磁链 </button>`; this.outerHTML = html; } ); // 再处理所有文本节点,加上标记 $('div[id^="post_"]').each(function () { const treeWalker = document.createTreeWalker( this, NodeFilter.SHOW_TEXT ); while (treeWalker.nextNode()) { const node = treeWalker.currentNode; if (node.nodeValue && magnetRegExp.test(node.nodeValue)) { node.nodeValue = node.nodeValue.replace( magnetRegExp, (match, offset, str) => toAlienMagnet(completeMagnet(match), "tianteng") ); } } }); // 去除标记 $('div[id^="post_"]').each(function () { // 去除文本节点中磁链的标记 let magnetAlienRegExp = getMagnetRegExp("tianteng"); let html = this.innerHTML; html = html.replace(magnetAlienRegExp, function (match) { match = toNormalMagnet(match, "tianteng"); let magnetAlien = toAlienMagnet(match); return ` <a href="${match}" data-tianteng-status="ok">${match}</a> <button style="margin:0;padding:3px;" class="jav-button tianteng-button" data-tianteng-button="copy" data-tianteng-magnet="${magnetAlien}" type="button">复制磁链 </button> <button style="margin:0;padding:3px;" class="jav-button tianteng-button" data-tianteng-button="click" data-tianteng-magnet="${magnetAlien}" type="button">打开磁链 </button>`; }); // 去除A标签中磁链的标记 magnetAlienRegExp = getMagnetRegExp("@"); html = html.replace(magnetAlienRegExp, function (match) { return toNormalMagnet(match, "@"); }); this.innerHTML = html; const postId = $(this).attr("id"); const id = postId.replace("post_", ""); const postMessageId = `postmessage_${id}`; // 添加 4个 "所有" 按钮,在每个回复的开头和结尾,共8个 if ( $(`[data-tianteng-button="copy"]`, $(`#${postId}`)).length > 0 ) { let allButtonHtml = ` <button style="margin:0;padding:5px;" class="jav-button tianteng-button" data-tianteng-button="copyAll" data-tianteng-post-id="${postId}" data-tianteng-post-message-id="${postMessageId}" type="button">复制所有磁链 </button> <button style="margin:0;padding:5px;" class="jav-button tianteng-button" data-tianteng-button="clickAll" data-tianteng-post-id="${postId}" data-tianteng-post-message-id="${postMessageId}" type="button">打开所有磁链 </button> <button style="margin:0;padding:5px;margin-left:10px;" class="jav-button tianteng-button" data-tianteng-button="copyAllNot" data-tianteng-post-id="${postId}" data-tianteng-post-message-id="${postMessageId}" type="button">复制所有磁链(不含点评) </button> <button style="margin:0;padding:5px;" class="jav-button tianteng-button" data-tianteng-button="clickAllNot" data-tianteng-post-id="${postId}" data-tianteng-post-message-id="${postMessageId}" type="button">打开所有磁链(不含点评) </button>`; $(`#${postMessageId}`).prepend(allButtonHtml + "<br><br>"); $(`#${postMessageId}`).append("<br><br>" + allButtonHtml); } }); } // end if 论坛明细页面 } // end callback ); /////////////////////////////////////////////////////////////////////////// // BTSOW https://btsow.motorcycles https://btsow.com /////////////////////////////////////////////////////////////////////////// execute("btsow", $('head>title:contains("BTSOW")'), () => { const $searchButton = $( "form.form-inline>div.input-group>span.input-group-btn" ), $searchInput = $( `form.form-inline>div.input-group>input[name="keyword"]` ), $pasteAndSearchButton = $(` <span class="input-group-btn"> <button type="button" class="btn btn-default"> <span class="glyphicon glyphicon-search" aria-hidden="true"></span> 粘贴&搜索 </button> </span>`); $searchButton.after($pasteAndSearchButton); $pasteAndSearchButton.click(() => { navigator.clipboard.readText().then((clipText) => { if (clipText != null && $.trim(clipText) != "") { $searchInput.val($.trim(clipText)); document.querySelector("body > div.container > form").submit(); } }); }); }); /////////////////////////////////////////////////////////////////////////// // https://skrbtqx.top 永久地址: skrfabu.top skrso.link /////////////////////////////////////////////////////////////////////////// execute("skrbt", $(`head>link[rel='shortcut icon'][href*='skrbt']`), () => { const $searchButton = $("button.search-btn"); const $searchInput = $(`input.search-input[name='keyword']`); const $pasteAndSearchButton = addPasteAndSearchButton( $searchButton, $searchInput ); // 调整'粘贴&搜索'按钮样式 $pasteAndSearchButton.removeAttr("style"); $pasteAndSearchButton.css("margin-left", "3px"); $pasteAndSearchButton.attr("class", $searchButton.attr("class")); // 删除广告 function removeAd() { const $container = $(".col-md-6:eq(2)"); $container.remove(".label.label-primary"); $container .find('a.rrt.common-link[href^="http"]') .parent() .parent() .remove(); } removeAd(); ///搜索结果列表页面 if (location.href.includes("search")) { let buttonsHtml = ` <span class="rrmiv"><button class="btn btn-danger copy" type="button">复制磁链</button></span> <span class="rrmiv"><button class="btn btn-danger click" type="button">点击磁链</button></span>`; addButtonsForSkrbt(buttonsHtml, $(".col-md-6:eq(2)"), (el) => { const classValue = $(el).attr("class"); if (classValue && classValue.includes("copy")) { return "copy"; } if (classValue && classValue.includes("click")) { return "click"; } return "other"; }); // 自动分页插件兼容,删除广告 const nodeToObserve = document.querySelectorAll(".col-md-6")[2]; new MutationObserver((mutationRecords, observer) => { $("a.rrt.common-link").each((index, el) => { if ($(el).parent().find(".btn.btn-danger.copy").length === 0) { $(el).after(buttonsHtml); } }); removeAd(); }).observe(nodeToObserve, { childList: true }); } // end if }); /////////////////////////////////////////////////////////////////////////// // 知乎 /////////////////////////////////////////////////////////////////////////// execute("知乎", /zhihu\.com/, () => { const searchButton = $(`button[class*="SearchBar-searchButton"]`); const $searchInput = $(`#Popover1-toggle`); addPasteAndSearchButton(searchButton, searchInput); }); /////////////////////////////////////////////////////////////////////////// // 百度 /////////////////////////////////////////////////////////////////////////// execute("百度", /baidu\.com/, () => { const $searchButton = $(`#su`); const $searchInput = $(`#kw`); addPasteAndSearchButton(searchButton, searchInput); }); }); ///////////////////////////////////////////////////////////////////////////// // 公共方法 ///////////////////////////////////////////////////////////////////////////// function execute(title, condition, callback) { if (checkCondition(condition) === true) { if (callback) { debug(condition.toString(), title); callback(title, condition); } } } /** * * @param {RegExp|Function|Boolean|String|jQuery} condition * @returns {Boolean} */ function checkCondition(condition) { if ($.type(condition) === "regexp") { return condition.test(window.location.href); } if ($.isFunction(condition)) { return condition() === true; } if ($.type(condition) === "boolean") { return condition === true; } if ($.type(condition) === "string") { return document.querySelector(condition) != null; } if (condition instanceof jQuery) { return condition.length > 0; } if ($.isArray(condition)) { for (let c of condition) { if (checkCondition(c)) { return true; } } } return false; } function addPasteAndSearchButton($searchButton, $searchInput, callback) { const styleMap = { "margin-left": "5px" }; $searchButton[0] && $searchButton[0].computedStyleMap().forEach((value, key) => { styleMap[key] = value; }); let $pasteAndSearchButton = $( `<input type="button" value="粘贴&搜索" id="pasteAndSearch"></input>` ); $pasteAndSearchButton.css(styleMap); $searchButton.after($pasteAndSearchButton); $pasteAndSearchButton.click(() => { navigator.clipboard.readText().then((clipText) => { if (clipText != null && $.trim(clipText) != "") { $searchInput.val($.trim(clipText)); $searchButton.click(); } }); }); callback && callback($searchButton, $searchInput, $pasteAndSearchButton); return $pasteAndSearchButton; } function appendCopyButton(chePai, toAppendElement) { var copyButton = document.createElement("button"); copyButton.innerHTML = "复 制"; copyButton.setAttribute("id", "copyButton"); toAppendElement.appendChild(copyButton); document.addEventListener("click", (e) => { if (e.target.getAttribute("id") === "copyButton") { GM.setClipboard(chePai, "text"); } }); } function debug(str, title) { if (enableDebug) { if (!str) { str = ""; } if (!Array.isArray(str)) { str = [str]; } seq++; console.log( `%c【tianteng ${GM_info.script.version}】 ${title ? title : "debug"}:`, "color: yellow;font-size: large;font-weight: bold;background-color: darkblue;", seq, ...str ); } } function isNativeCode(obj) { const nativeCodeTag = "[native code]"; return obj && obj.toString && obj.toString().includes(nativeCodeTag); } function getQueryVariable(anchor, variable) { var query = anchor.search.substring(1); var vars = query.split("&"); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } return false; } /** * 图片按宽高比例进行自动缩放 * @param ImgObj * 缩放图片源对象 * @param maxWidth * 允许缩放的最大宽度 * @param maxHeight * 允许缩放的最大高度 * @usage * 调用:<img src="图片" onload="javascript:drawImage(this,300,200)"> */ function drawImage(ImgObj, maxWidth, maxHeight) { var image = new Image(); //原图片原始地址(用于获取原图片的真实宽高,当<img>标签指定了宽、高时不受影响) image.src = ImgObj.src; // 用于设定图片的宽度和高度 var tempWidth; var tempHeight; if (image.width > 0 && image.height > 0) { //原图片宽高比例 大于 指定的宽高比例,这就说明了原图片的宽度必然 > 高度 if (image.width / image.height >= maxWidth / maxHeight) { if (image.width > maxWidth) { tempWidth = maxWidth; // 按原图片的比例进行缩放 tempHeight = (image.height * maxWidth) / image.width; } else { // 按原图片的大小进行缩放 tempWidth = image.width; tempHeight = image.height; } } else { // 原图片的高度必然 > 宽度 if (image.height > maxHeight) { tempHeight = maxHeight; // 按原图片的比例进行缩放 tempWidth = (image.width * maxHeight) / image.height; } else { // 按原图片的大小进行缩放 tempWidth = image.width; tempHeight = image.height; } } // 设置页面图片的宽和高 ImgObj.height = tempHeight; ImgObj.width = tempWidth; // 提示图片的原来大小 ImgObj.alt = image.width + "×" + image.height; } } /** * * @param {EventTarget|NodeList|Array|jQuery} elements * @param {undefined|null|String|Array} events */ function removeEvents(elements, events) { if (!elements) return; if (elements instanceof EventTarget) { elements = [elements]; } if (elements instanceof jQuery) { elements = elements.toArray(); } if (!events) { elements.forEach((element) => { for (let t in element) { if (t.startsWith("on") && element[t] != null) { element[t] = null; console.log("cleanup removed listener from " + element.nodeName, t); } } for (let t of element.allListeners || []) { element.removeEventListener(t.type, t.callback, t.options); console.log( "cleanup removed listener from " + element.nodeName, t.type ); } element.allListeners = []; }); } else { if (typeof events === "string") { events = [events]; } if (!Array.isArray(events)) { return; } events.forEach((event) => { const onEvent = "on" + event; elements.forEach((element) => { for (let t in element) { if (t.startsWith(onEvent) && element[t] != null) { element[t] = null; console.log( "cleanup removed listener from " + element.nodeName, t ); } } // const toRemoved = []; element.allListeners = element.allListeners || []; let allListenersNew; element.allListeners.forEach((t, i) => { if (t.type === event) { element.removeEventListener(t.type, t.callback, t.options); allListenersNew = element.allListeners.slice(i, 1); // toRemoved.push(i); console.log( "cleanup removed listener from " + element.nodeName, t.type ); } }); // toRemoved.forEach((item, index) => { // element.allListeners = element.allListeners.slice(item, 1); // }); if (allListenersNew) { element.allListeners = allListenersNew; } }); }); } } function addButtonsForSkrbt( buttonsHtml, delegateElement, buttonTypeCallback ) { delegateElement.find("a.rrt.common-link").after(buttonsHtml); delegateElement.click((event) => { const buttonType = buttonTypeCallback(event.target); if ("copy" !== buttonType && "click" !== buttonType) { return; } let liNode = $(event.target).parent().parent(); const exeButtonClick = () => { if ("copy" === buttonType) { navigator.clipboard.writeText(liNode.find(".magnet").attr("href")); } else { // liNode.find('.magnet').trigger('click'); //不好使 liNode.find(".magnet")[0].click(); } }; if (liNode.find(".magnet").length != 0) { // 磁链已经添加过 exeButtonClick(); return; } let detailUrl = liNode.find("a.rrt.common-link").attr("href"); detailUrl = `${skrbtUrl}${detailUrl}`; $.get(detailUrl, function (data, textStatus, jqXHR) { liNode.find("#errorTip").remove(); //成功后在页面添加磁链 const magnet = $(data).find("#magnet").attr("href"); if (magnet) { const aHtml = '<a class="magnet" href="' + magnet + '">' + magnet + "</a>"; liNode.append(aHtml); exeButtonClick(); } else { liNode.append( '<span id="errorTip">1.获取磁链失败,等会儿再试一试! 若仍然有问题请刷新网页.</span>' ); } }).fail(function (e) { //失败后在页面提示 liNode.append( '<span id="errorTip">2.获取磁链失败,等会儿再试一试! 若仍然有问题请刷新网页.</span>' ); console.log(e); }); }); } })();