// ==UserScript== // @name 链接助手 // @namespace https://github.com/oneNorth7 // @include * // @version 1.9.4 // @author 一个北七 // @run-at document-body // @description 支持全网主流网盘和小众网盘自动填写密码; 资源站点下载页网盘密码预处理; 跳转页面自动跳转; 文本转链接; 净化跳转链接; 维基百科及镜像、开发者文档、谷歌商店自动切换中文, 维基百科、谷歌开发者、谷歌商店、Github链接转为镜像链接; 新标签打开链接; (外部)链接净化直达 // @icon https://gitee.com/oneNorth7/pics/raw/master/picgo/link-helper.png // @compatible chrome 69+ // @compatible firefox 78+ // @compatible edge Latest // @noframes // @license GPL-3.0 License // @grant GM_registerMenuCommand // @grant GM_unregisterMenuCommand // @grant GM_notification // @grant GM_info // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_openInTab // @grant GM_addStyle // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js // @require https://cdn.jsdelivr.net/npm/sweetalert2@10.15.5/dist/sweetalert2.all.min.js // @created 2021年3月19日 09:48:14 // @downloadURL none // ==/UserScript== $(function () { "use strict"; const scriptInfo = GM_info.script, locHost = location.host, locHref = location.href, locHash = location.hash, locPath = location.pathname; let t = { showNotice(msg) { GM_notification({ text: msg, title: scriptInfo.name, image: scriptInfo.icon, highlight: false, silent: false, timeout: 1500, }); }, clog() { console.group('[链接助手]'); for (let m of arguments) { if (void 0 !== m) console.log(m); } console.groupEnd(); }, get(name, def) { return GM_getValue(name, def); }, set(name, value) { GM_setValue(name, value); }, delete(name) { GM_deleteValue(name); }, registerMenu(title, func) { return GM_registerMenuCommand(title, func); }, unregisterMenu(menuID) { GM_unregisterMenuCommand(menuID); }, open(url, options = { active: true, insert: true, setParent :true }) { GM_openInTab(url, options); }, http(link, s = false) { return link.startsWith("http") ? link : (s ? "https://" : "http://") + link; }, title(a, mark='') { if (a.title) a.title += "\n" + mark + decodeURIComponent(a.href); else a.title = mark + decodeURIComponent(a.href); }, hashcode(l=location) { return l.hash.slice(1); }, search(l=location, p = 'password') { let args = l.search.slice(1).split('&'); for (let a of args) { if (a.includes(p + '=')) return a.replace(p + '=', ''); } return ''; }, clean(src, str) { for (let s of str) { src = src.replace(s, ""); } return src; }, loop(func, times) { let tid = setInterval(() => { if (times <= 0) clearInterval(tid); func(); this.clog(times); times--; }, 100); }, confirm(title, yes, no = () => {}, deny = false) { let option = { toast: true, showCancelButton: true, position: 'center', title, confirmButtonText: '是', cancelButtonText: '否', showDenyButton: deny, denyButtonText: '取消', }; return Swal.fire(option).then((res) => { if (res.isConfirmed) yes(); else if (res.isDismissed) no(); else if (res.isDenied) deny(); }); }, increase() { success_times = +this.get("success_times") + 1; this.set("success_times", success_times); }, subscribe() { let isFollowed = t.get('isFollowed', false), least_times = t.get('least_times', 30); success_times = +this.get("success_times"); if (success_times > least_times && !isFollowed) { Swal.fire({ title: '\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e0d\u8ff7\u8def\uff01', html: $( `

\u7b2c\u4e00\u65f6\u95f4\u83b7\u53d6\u3010\u94fe\u63a5\u52a9\u624b\u3011\u66f4\u65b0\u63a8\u9001\uff01

` )[0], showCancelButton: true, allowOutsideClick: false, confirmButtonColor: '#d33', confirmButtonText: '\u5df2\u5173\u6ce8\uff0c\u4e0d\u518d\u63d0\u9192\uff01', cancelButtonColor: '#3085d6', cancelButtonText: '\u7a0d\u540e\u5173\u6ce8', }).then((result) => { if (result.isConfirmed) { Swal.fire({ position: 'center', icon: 'success', title: '\u611f\u8c22\u5173\u6ce8\uff01\uff01\uff01', text: '\u4e00\u4e2a\u5317\u4e03\u4f1a\u7ee7\u7eed\u4e0d\u9057\u4f59\u529b\u5730\u521b\u4f5c\u66f4\u591a\u5b9e\u7528\u5de5\u5177', showConfirmButton: false, timer: 2000 }); t.set('isFollowed', true); } else t.set('least_times', least_times + 30); }); } }, update(name, value) { if (this.get('updated_version', '') != scriptInfo.version) { let data = this.get(name, false); if (data) { for (let v of value) { if (!data.some(d => d == v)) { data.push(v); } } this.set('updated_version', scriptInfo.version); this.set(name, data); } } }, rand(min, max) { if (arguments.length == 1) max = min, min = 0; let random = Math.random(), randInt = Math.floor(random * (max + 1 - min)) + min; return randInt; }, }; let url_re_str = "((?p"), weiyun = null, mega = null; for (let p of paragraphs) { let text = $(p).text(); if (text.startsWith("链接:")) weiyun = $(p); if (weiyun && text.startsWith("密码:")) weiyun.text( weiyun.text() + "#" + text.replace("密码:", "") ); if (mega && text.startsWith("国外M盘:")) mega.text( mega.text() + "#" + text.replace("国外M盘:", "") ); if (text.startsWith("国外M盘:http")) mega = $(p); } } }, "www.olecn.com": function () { if ( /http:\/\/www\.olecn\.com\/download\.php\?id=\d+/.test(locHref) ) { let link = $("div.panel-body a"), pass = $("div.plus_l li:eq(3)"); if (link.length && pass.length) link[0].hash = pass .text() .trim() .replace("网盘提取码 :", ""); } }, "www.qiuziyuan.net": function () { if ( /https:\/\/www\.qiuziyuan\.net\/(?:pcrj\/|Android\/\d+\.html)/.test( locHref ) ) { let filetit = $("div.filetit:first"); for (let child of filetit.children()) { if (child.href) { let result = url_regexp.exec(child.innerHTML); if (result) child.href = t.http(result[1]); } if ( child.innerHTML.startsWith("90网盘:") || child.innerHTML.includes("90pan") ) { let dom = filetit.next().next(), result = /(?:90网盘:|\/\s*)(\d+)/.exec(dom.html()); if (result) child.href += "#" + result[1]; } } } }, "www.gopojie.net": function () { if (/https:\/\/www\.gopojie\.net\/download\?post_id=/.test(locHref)) { setTimeout(() => { let a = $('a.empty.button'), url = a.prop('href'), code = $('#tq').attr('data-clipboard-text'); if (url) a.prop('href', url + '#' + code); }, 1000); } }, "www.acgjc.com": function () { if (/http:\/\/www.acgjc.com\/storage-download\/\?code=/.test(locHref)) { let codeNode = $('#theme_custom_storage-0-download-pwd'); if (codeNode.length) { let code = codeNode.val(), link = codeNode.parents('div.fieldset-content').find('a'); if (link) link.prop('href', link[0].href + '#' + code); } } }, "www.bsh.me": function () { if (/https:\/\/www\.bsh\.me\/download\.php\?author=/.test(locHref)) { $('ul.list-group:last').find('a').each((i, a) => { let text = $(a).text(), codeNode = $(a).parents('ul.list-group').find(`span.item-title:contains("${text}"):last`), result = /\w{2,10}/.exec(codeNode.text()); if (a.search === "?%3E") a.search = ""; if (result) a.hash = result[0]; else a.hash = codeNode.parent().text().match("\\w{2,10}")[0]; }); $(".card div.text-center, footer.blockquote-footer").hide(); $("div.card-signup").css("margin-bottom", "20px"); } }, "www.zhiruanku.com": function () { if (/https:\/\/www\.zhiruanku\.com\/\d+/.test(locHref)) { $("div.wp-block-zibllblock-buttons a").each((i, a) => { a.href = a.dataset.id let result = a.textContent.match(":(\\w{2,10})"); if (result) a.hash = result[1]; }); } }, "zhidao.baidu.com": function () { if (/https:\/\/zhidao\.baidu\.com\/question\/\d+\.html.*/.test(locHref)) { $("baiduyun.ikqb-yun-box").each((i, e) => { let title = $(e).attr("data_title"), url = $(e).attr("data_sharelink") + "#" + $(e).attr("data_code"), p = $(e).parent("p"); p.before(`

预处理链接:${title}

`); }); } }, "yun.hei521.cn": function () { let text = $("#comments .ds-comment-body p:contains('码')").text(); if (text) { let codes = text.match(/[a-z\d]{4}/g); if (codes) $("div.jumbotron a:contains('http')").each((i, a) => { let result = a.nextSibling && a.nextSibling.nodeValue && a.nextSibling.nodeValue.match(/[a-z\d]{4}/); if (result) a.hash = "#" + result[0]; else if (codes[i]) a.hash = "#" + codes[i]; }); } }, }; if (Preprocess[locHost]) Preprocess[locHost](); let YunDisk = { sites: { "pan.baidu.com": { // 百度云 inputSelector: "#accessCode", buttonSelector: "#submitBtn", regStr: "[a-z\\d]{4}", }, "eyun.baidu.com": { // 百度企业网盘 inputSelector: "input.share-access-code", buttonSelector: "a.g-button", regStr: "[a-z\\d]{4,6}", }, "cloud.189.cn": { // 天翼云 inputSelector: "#code_txt", buttonSelector: "a.btn-primary", regStr: "[a-z\\d]{4}", timeout: 1000, inputEvent: true, noNotice: true, }, "h5.cloud.189.cn": { // 手机天翼云 inputSelector: "input.access-code-input", buttonSelector: "div.button", regStr: "[a-z\\d]{4}", timeout: 100, password: true, inputEvent: true, }, "lanzou.com": { // 蓝奏云 inputSelector: "#pwd", buttonSelector: "#sub, .passwddiv-btn", regStr: "[a-z\\d]{2,10}", redirect: true, noNotice: true, }, "ct.ghpym.com": { // 果核城通网盘 inputSelector: "#passcode", buttonSelector: "button.btn-primary", regStr: "[a-z\\d]{4,6}", timeout: 500, // >=125 }, "www.90pan.com": { // 90网盘 inputSelector: "#code", buttonSelector: "button.btn-info", regStr: "[a-z\\d]{4,6}", }, "vdisk.weibo.com": { // 微盘 inputSelector: "#keypass", buttonSelector: "div.search_btn_wrap>a", regStr: "[a-z\\d]{4}", }, "pan.xunlei.com": { // 迅雷云盘 inputSelector: "#__nuxt input.td-input__inner", buttonSelector: "#__nuxt button.td-button", regStr: "[a-z\\d]{4}", timeout: 1200, store: true, inputEvent: true, }, "share.weiyun.com": { // 微云 inputSelector: "input.input-txt", buttonSelector: "button.btn-main", regStr: "[a-z\\d]{4,6}", timeout: 500, inputEvent: true, }, "115.com": { // 115网盘 inputSelector: "input.text", buttonSelector: "a.btn-large", regStr: "[a-z\\d]{4}", timeout: 500, password: true, }, "quqi.com": { // 曲奇云 inputSelector: "div.webix_el_box>input", buttonSelector: "button.webixtype_base", regStr: "[a-z\\d]{6}", timeout: 800, }, "caiyun.139.com": { // 和彩云 inputSelector: "input", buttonSelector: "a.btn-token", regStr: "[a-z\\d]{4}", timeout: 100, clickTimeout: 10, inputEvent: true, store: true, }, "mo.own-cloud.cn": { // 小麦魔方 inputSelector: "#pwd", buttonSelector: "button.MuiButton-root", regStr: "[a-z\\d\\u4e00-\\u9fa5]{2,8}", timeout: 500, password: true, }, "moecloud.cn": { // 萌云 inputSelector: "#pwd", buttonSelector: "button.MuiButton-root", regStr: "[a-z\\d]{3,8}", timeout: 500, password: true, }, "www.wenshushu.cn": { // 文叔叔 inputSelector: "input.ivu-input", buttonSelector: "button.m-mg_t40", regStr: "[a-z\\d]{4}", timeout: 1000, inputEvent: true, }, "mega.nz": { regStr: "[a-z\\d\\-_]{22}", }, "gofile.me": { inputSelector: "#login_passwd", buttonSelector: 'button[aria-label="进入"]', regStr: "[a-z\\d]{4}", clickTimeout: 1000, store: true, }, "www.jianguoyun.com": { // 坚果云 inputSelector: "#access-pwd", buttonSelector: "button.action-button", regStr: "[a-z\\d]{6}", }, "yunpan.360.cn": { // 360安全云盘 inputSelector: "input.pwd-input", buttonSelector: "input.submit-btn", regStr: "[a-z\\d]{4}", }, "pan-yz.chaoxing.com": { // 超星云盘 inputSelector: "input.tqInp", buttonSelector: "a.blueBgBtn", regStr: "[a-z\\d]{6}", }, "shandianpan.com": { // 闪电盘 inputSelector: 'input[placeholder="请输入文件密码"]', buttonSelector: "div.btn", regStr: "[a-z\\d]{4}", timeout: 500, inputEvent: true, store: true, }, "my.sharepoint.com": { // OneDrive inputSelector: '#txtPassword', buttonSelector: "#btnSubmitPassword", regStr: "[a-z\\d]{3,4}", }, "u.163.com": { // 网易网盘 inputSelector: "#pickupCode", buttonSelector: "#wpDownloadHref", regStr: "[a-z\\d]{8}", }, "www.aliyundrive.com": { // 阿里云盘 inputSelector: "input.ant-input", buttonSelector: "button.button--fep7l", regStr: "[a-z\\d]{4}", timeout: 1500, multiEvent: true, }, "disk.yandex.com": {}, // YandexDisk }, pans: [ "cowtransfer.com", // 奶牛快传 "www.mediafire.com", // MediaFire "drive.google.com", // GoogleDrive "down.52pojie.cn", // 爱盘 "www.yunzhongzhuan.com", // 云中转 "yiqixie.qingque.cn", // 一起写 "www.androiddownload.net", "www.dropbox.com", // Dropbox "www.kufile.net", // 库云 "www.kdocs.cn", // 金山文档 "pan.bitqiu.com", // 比特球云盘 "www.feimaoyun.com", // 飞猫云 "www.fangcloud.com", // 亿方云 "gd.188988.xyz", // GD DISK "www.yun.cn", // UC网盘 "www.yuque.com", // 语雀 "shimo.im", // 石墨 ], mapHost(host) { return host .replace(/^yun.baidu.com/, 'pan.baidu.com') .replace(/.*lanzou[isx]?.com/, 'lanzou.com') .replace(/^(?:[a-z]\d{3}|\d{3}[a-z])\.com$/, 'ct.ghpym.com') .replace('dl.sixyin.com', 'ct.ghpym.com') .replace('ct.bsh.me', 'ct.ghpym.com') .replace(/quqi\.\w+\.com/, 'quqi.com') .replace('feixin.10086.cn', '139.com') .replace('ws28.cn', 'www.wenshushu.cn') .replace('zb.my.to:5000', 'gofile.me') .replace('cloud.dnxshare.cn', 'drive.dnxshare.cn') .replace(/\w+\-my\.sharepoint\.(?:com|cn)/, 'my.sharepoint.com') .replace(/\w{6}.link.yunpan.360.cn|yunpan.cn/, 'yunpan.360.cn') .replace('mofile.own-cloud.cn', 'mo.own-cloud.cn') .replace('cloud.qingstore.cn', 'moecloud.cn') .replace('pan.mebk.org', 'moecloud.cn') .replace('cncncloud.com', 'moecloud.cn') .replace('ilolita945.softether.net:5212', 'moecloud.cn') .replace('my-file.cn', 'moecloud.cn') .replace('pan.bilnn.com', 'moecloud.cn') .replace('bx.qingstore.cn', 'moecloud.cn') .replace('drive.dnxshare.cn', 'moecloud.cn') .replace('pan.mba', 'moecloud.cn') .replace('yadi.sk', 'disk.yandex.com') .replace('nf.mail.163.com', 'u.163.com'); }, autoFill(host) { let site = this.sites[host]; // 百度云文档 if (host === "pan.baidu.com" && locPath.startsWith('/doc/share/')) site = { inputSelector: "input.u-input__inner", buttonSelector: "div.dialog-footer button.u-btn.u-btn--primary", regStr: "[a-z\\d]{4}", inputEvent: true, timeout: 500, clickTimeout: 10, }; // 自动填写密码 if (site.timeout) setTimeout(fillOnce, site.timeout); else fillOnce(); function fillOnce() { if (site.inputSelector) { let input = $(site.inputSelector), button = $(site.buttonSelector), code = null; function click() { if (site.clickTimeout) setTimeout(() => { button = $(site.buttonSelector); button[0].click(); }, site.clickTimeout); else button[0].click(); } if (input.length) { if (site.store) code = t.get(host); else if (site.password) code = decodeURIComponent(t.search()); else code = t.hashcode(); if (code) { let codeRe = RegExp("^" + site.regStr + "$", "i"); if (codeRe.test(code)) { if (site.inputEvent) { let tid = setInterval(() => { input.val(code); if (input.val() !== "") { if (InputEvent) { input[0].dispatchEvent( new InputEvent("input") ); } else if (KeyboardEvent) { input[0].dispatchEvent( new KeyboardEvent("input") ); } clearInterval(tid); click(); } }, 1000); } else if (site.multiEvent) { input.attr("value", code); button.attr("data-is-disabled", false); let data = JSON.stringify({share_id: location.pathname.replace('/s/', ''), share_pwd: code}); $.ajax("https://api.aliyundrive.com/v2/share_link/get_share_token", { type: "POST", data, success: res => localStorage.setItem('shareToken', JSON.stringify(res)) }).then(() => location.reload(), () => t.showNotice("提取码错误,请反馈网盘链接来源地址给作者处理!")); } else if (site.react) { let lastValue = input.val(); input.val(code); let tracker = input[0]._valueTracker; if (tracker) tracker.setValue(lastValue); input.trigger("input"); click(); } else if (site.password) { input.val(code); click(); } else { input.val(code); click(); } t.increase(); if (!site.Notice) t.subscribe(); } else { t.clog("未找到合适的提取码!"); } } else { t.clog("未找到提取码!"); } } else { t.clog("无需填写密码!"); } } } }, addCode(a) { // 手机百度云 if (a.host === "pan.baidu.com" && a.pathname.startsWith('/wap/')) a.pathname = a.pathname.replace('/wap/', '/share/'); let mapped = this.mapHost(a.host), site = this.sites[mapped], codeRe = new RegExp("^" + site.regStr + "$", "i"); if (site) { if (site.password) { let result = a.hash && /#(\/s\/\w{6})/.exec(a.hash); if (result) if (a.pathname == '/') { a.pathname = result[1]; a.hash = ''; } } else if (site.redirect) { a.host = a.host.replace('lanzous', 'lanzoux'); } if (!codeRe.test(t.hashcode(a)) && !codeRe.test(t.search(a))) { let reg = new RegExp( "\\s*(?:提[取示]|访问|查阅|密\\s*|艾|Extracted-code|key|password|pwd)[码碼]?\\s*[\\u4e00-\\u9fa5]?[:: ((是]?\\s*(" + site.regStr + ")|^[码碼]?\\s*[::【\\[ ((]?\\s*(" + site.regStr + ")[】\\]))]?$", "i" ), code = reg.exec($(a).text().trim()); for ( let i = 10, current = a; current && current.localName != "body" && !code && i > 0; i--, current = current.parentElement ) { if (locHost === "yun.hei521.cn" && current.className === "row row-offcanvas row-offcanvas-right") break; let next = current; while (!code) { if (!next) break; else code = reg.exec($(next).text().trim()); if (a.host === "www.aliyundrive.com") next = next.previousSibling; else next = next.nextSibling; } } if (code) { let c = code[1] || code[2]; if (site.store) t.set(mapped, c); else if (site.password) { if (!t.search(a)) a.search = a.search ? a.search + '&' + 'password=' + encodeURIComponent(c) : 'password=' + encodeURIComponent(c); } else a.hash = c; } else { if (site.store) t.delete(mapped); t.clog("找不到code!"); } } } }, }; let success_times = t.get("success_times"); if (!success_times) t.set("success_times", 0); let dealedHost = YunDisk.mapHost(locHost); if (YunDisk.sites[dealedHost]) YunDisk.autoFill(dealedHost); else { let RedirectPage = { sites: { "show.bookmarkearth.com": { // 书签地球 include: "http://show.bookmarkearth.com/view/", selector: "a.open-in-new-window, div.actions>a", }, "t.cn": { // 新浪短链 include: "http://t.cn/", selector: "a.m-btn-orange", }, "sunbox.cc": { // 阳光盒子 include: "https://sunbox.cc/wp-content/themes/begin/go.php?url=", selector: "a.alert-btn", }, "www.itdaan.com": { // 开发者知识库 include: "https://www.itdaan.com/link/", selector: "a.c-footer-a1", }, "to.redircdn.com": { include: "https://to.redircdn.com/?action=image&url=", selector: "a.bglink", }, "link.csdn.net": { // CSDN include: "https://link.csdn.net/?target=", selector: "a.loading-btn", timeout: 100, }, "support.qq.com": { // 兔小巢 include: "support.qq.com/products/", selector: "span.link_url", }, "c.pc.qq.com": { // QQ非官方页面 include: "c.pc.qq.com/middlem.html?pfurl=", selector: "#url", }, "docs.qq.com": { // 腾讯文档 include: "docs.qq.com/scenario/link.html?url=", selector: "span.url-src", timeout: 500, }, "www.tianyancha.com": { // 天眼查 include: "www.tianyancha.com/security?target=", selector: "div.security-link", }, "www.yuque.com": { // 语雀 include: "www.yuque.com/r/goto?url=", selector: "button.ant-btn-primary>a", timeout: 300, }, "jump.bdimg.com": { // 百度贴吧 include: "jump.bdimg.com/safecheck/index?url=", selector: "div.warning_info.fl>a", }, "jump2.bdimg.com": { // 百度贴吧 include: "jump2.bdimg.com/safecheck/index?url=", selector: "div.warning_info.fl>a", }, "iphone.myzaker.com" : { // Zaker include: "iphone.myzaker.com/zaker/link.php?", selector: "a.btn", }, "game.bilibili.com": { // 哔哩哔哩游戏 include: "/linkfilter/?url=", selector: "#copy-url", }, "www.chinaz.com": { // 站长之家 include: "/go.shtml?url=", selector: "div.link-bd__text", }, }, redirect(host) { let site = this.sites[host]; if (locHref.includes(site.include)) { if (site.timeout) setTimeout(redirect, site.timeout); else redirect(); function redirect() { let target = $(site.selector); if (target.length) location.replace(t.http(target[0].href || target[0].innerText)); else if (locHost == "t.cn" && $("div.text:contains('绿色上网')").length) fetch(locHref).then(res => location.replace(res.headers.get("location"))); else t.clog('找不到跳转目标!'); t.increase(); } } }, wiki() { let isZh = locHost.includes("zh"), jumpToZh = t.get("jumpToZh", true), a = $("a.interlanguage-link-target[lang='zh']"); if (!isZh && jumpToZh) { history.pushState(null, null, locHref); if (a.length) location.replace(a[0].href); else t.showNotice("没有找到中文页面!"); } let menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); function autoJump() { jumpToZh = !jumpToZh; t.set("jumpToZh", jumpToZh); t.unregisterMenu(menuID); menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); if (!isZh && jumpToZh) { history.pushState(null, null, locHref); if (a.length) location.replace(a[0].href); else t.showNotice("没有找到中文页面!"); }// else history.back(); } }, mozilla() { let isZh = locPath.includes("zh-"), jumpToZh = t.get("jumpToZh", true); jump(); function jump() { if (!isZh && jumpToZh) { let result = /developer\.mozilla\.org\/(.+?)\//.exec( locHref ), options = $("#language-selector").children(), flag = ""; if (result) { for (let i = options.length; i > 0; i--) { if (options[i - 1].value.startsWith("zh-")) { if (flag) { flag = options[i - 1].value; break; } flag = options[i - 1].value; } } if (flag) { let zh_url = locHref.replace(result[1], flag); history.pushState(null, null, locHref); location.replace(zh_url); } else t.showNotice("没有找到中文页面!"); } } } let menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); function autoJump() { jumpToZh = !jumpToZh; t.set("jumpToZh", jumpToZh); t.unregisterMenu(menuID); menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); jump(); } }, MSDocs() { let isZh = locPath.includes("zh-cn"), jumpToZh = t.get("jumpToZh", true); if (!isZh && jumpToZh) { history.pushState(null, null, locHref); location.replace(locHref.replace(/docs.microsoft.com\/[a-z\-]{5}\//i, 'docs.microsoft.com/zh-cn/')); } let menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); function autoJump() { jumpToZh = !jumpToZh; t.set("jumpToZh", jumpToZh); t.unregisterMenu(menuID); menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); if (!isZh && jumpToZh) { history.pushState(null, null, locHref); location.replace(locHref.replace(/docs.microsoft.com\/[a-z\-]{5}\//i, 'docs.microsoft.com/zh-cn/')); } } }, chrome() { if (location.search.includes('hl=')) { let isZh = location.search.includes('hl=zh-CN'), jumpToZh = t.get("jumpToZh", true); if (!isZh && jumpToZh) { history.pushState(null, null, locHref); location.search = location.search.replace(/hl=[a-zA-Z]{2}-[a-zA-Z]{2}/, 'hl=zh-CN'); } let menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); } else location.search += location.search ? '&hl=zh-CN' : '?hl=zh-CN'; function autoJump() { jumpToZh = !jumpToZh; t.set("jumpToZh", jumpToZh); t.unregisterMenu(menuID); menuID = t.registerMenu( `${jumpToZh ? "[✔]" : "[✖]"}自动切换中文`, autoJump ); if (!isZh && jumpToZh) { history.pushState(null, null, locHref); location.search = location.search.replace(/hl=[a-zA-Z]{2}-[a-zA-Z]{2}/, 'hl=zh-CN'); } } }, }; if (locHost.match(/.+wiki(?:\.sxisa|pedia)\.org/)) RedirectPage.wiki(); else if (locHost == "chrome.google.com") RedirectPage.chrome(); else { if (locHost === "developer.mozilla.org") RedirectPage.mozilla(); else if (locHost === "docs.microsoft.com") RedirectPage.MSDocs(); let isChromium = navigator.appVersion.includes("Chrome"); $(document).on("mouseup", (obj) => listener(obj)); if (isChromium && (locHost == "www.52pojie.cn" || /htm_(data|mob)\/\d+\/\d+\/\d+\.html|cl.\d+[xyz].xyz\/\w+\.php.*/.test(locHref))) $(document).on("selectstart", (obj) => listener(obj)); if (locHost.includes("blog.csdn.net")) document.body.addEventListener("click", function (obj) { let e = obj.target; if (e.nodeName.toLocaleLowerCase() === "a") { obj.stopImmediatePropagation(); window.open(e.href); obj.preventDefault(); } }, true); if (locHost === "www.yuque.com") { setTimeout(() => { let article = $("#content"); article.replaceWith(article.clone()); }, 3000); } // 移除登录和注册按钮 if (["hub.fastgit.org", "github.com.cnpmjs.org", "github.rc1844.workers.dev"].some(h => locHost === h)) { $(".HeaderMenu div.position-relative.mr-3, div.position-relative.mr-3+a, div.d-flex.flex-items-center>a").remove(); if (location.pathname === "/") $("form div.d-flex, div.home-nav-hidden>a").remove(); } async function listener(obj) { let e = obj.originalEvent.explicitOriginalTarget || obj.originalEvent.target, isTextToLink = false, isInput = false; if (e && !e.href) { let flag = true, selectNode = null; for ( let current = e, limit = 5; current.localName !== "html" && current.localName !== "body" && limit > 0; current = current.parentElement, limit-- ) { if (current.localName === "a") { e = current; break; } else if ( ["code", "pre"].some( (tag) => tag === current.localName ) ) { let selection = getSelection(), text = selection.toString(); if (url_regexp.test(text)) selectNode = selection.anchorNode || selection.focusNode; else flag = false; break; } else if (['input', 'textarea'].some((tag) => tag === current.localName) && current.className == 'direct-input') { let text = t.clean(current.value.replace(/点/g, '.'), [/[\u4e00-\u9fa5\u3002\uff1b\uff0c\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]+/g, /^[::]/, /App.*$/]), result = url_regexp.exec(text); if (result) { selectNode = document.createTextNode(text); isInput = true; } else flag = false; break; } } if (e.localName !== "a" && flag) { let node = selectNode || e; if (node && node.nodeValue) e = text2Link(node); else e = textToLink(e); if (e) isTextToLink = true; } } if (e && e.localName === "a" && e.href) { let a = e, isPrevent = false; if (locHref.includes("mod.3dmgame.com/mod/")) a.search = "3dmgame.com"; if (locHost == "bbs.nga.cn" || locHost == "nga.178.com" || locHost == "ngabbs.com") { if (!(a.host == "bbs.nga.cn" || a.host == "nga.178.com" || a.host == "ngabbs.com")) if (a.attributes.onclick && a.attributes.onclick.nodeValue.startsWith("ubbcode.showUrlAlert(event,this)")) a.onclick = null; } if (locHost == "twitter.com" && a.host == "t.co") a.href = t.http(a.innerText, true); if (locHost == "www.youtube.com" && a.href.includes("www.youtube.com/redirect?")) { if (!a.style.padding) { $("#secondary-links.ytd-c4-tabbed-header-renderer a.ytd-c4-tabbed-header-renderer").css({padding: "10px 10px 10px 2px", lineHeight: 0, display: "inline-block"}); $("#secondary-links.ytd-c4-tabbed-header-renderer a.ytd-c4-tabbed-header-renderer:first-child").css("padding-left", "10px"); } a.classList.remove("yt-simple-endpoint"); } if (locHost == "www.facebook.com") { a.onclick = function() { return false; }; t.open(a.href); } if (!cleanRedirectLink(a) && RegExp("^" + url_re_str + "$", "i").test(a.innerText)) { if (isLinkText(a)) { t.title(a, '【替换】'); a.href = t.http(a.innerText, true); t.increase(); } else if (!isTextToLink && !a.parentElement.className.includes('text2Link') && !a.parentElement.className.includes('textToLink') && locHost != 'www.facebook.com' && a.host != 'download.downsx.org' && isDifferent(a)) { a.onclick = function() { return false; }; isPrevent = true; await t.confirm("是否使用链接文本替换目标链接后打开?", () => { // 是 let linkTextPrefixes = t.get("linkTextPrefixes", []), reg = /(?:http|https|\/|\%2F).*?\?.+?=|.*?\?/, result = reg.exec(a.href); if (result) { linkTextPrefixes.push(result[0]); t.set("linkTextPrefixes", linkTextPrefixes); } t.title(a, '【替换】'); a.href = t.http(a.innerText, true); t.increase(); }, () => { // 否 }, () => { // 取消 isPrevent = false; a.onclick = null; }); } } if (jumpToMirror) { if (a.host.includes("wikipedia.org")) { // 维基百科 if (!locHost == "www.bing.com" || !locHost.includes("www.google.")) a.host = a.host.replace( "wikipedia.org", "wiki.sxisa.org" ); } else if (a.host.includes("developers.google.com")) { // 谷歌开发者 if (!locHost == "developers.google.com") a.host = a.host.replace( "developers.google.com", "developers.google.cn" ); } else if (locHost !== "github.com" && a.host === "github.com") { // Github let mirrors = [ ["fastgit", "hub.fastgit.org"], ["cnpmjs", "github.com.cnpmjs.org"], ["rc1844", "github.rc1844.workers.dev"] ], rand = t.rand(1, 9) % 3, mirror = mirrors[rand], next = mirrors[(rand + 1) % 3]; a.onclick = function() { return false; }; isPrevent = true; await t.confirm(`是否跳转到【${mirror[0]}】镜像站?`, () => { // 是 a.host = a.host.replace("github.com", mirror[1]); t.title(a, `已替换为【${mirror[0]}】镜像链接,请不要登录帐号!!!`); setTimeout(() => t.showNotice("镜像站请不要登录账号!!!\n镜像站请不要登录账号!!!\n镜像站请不要登录账号!!!"), 1000); }, () => { // 否 }, () => { // 取消 isPrevent = false; a.onclick = null; }); } else if (a.host.includes("chrome.google.com")) { // 谷歌应用商店 if (isChromium) { a.onclick = function() { return false; }; isPrevent = true; await t.confirm('是否跳转到【crx4chrome】镜像站?', () => { // 是 t.title(a); a.href = a.href.replace(/chrome\.google\.com\/webstore\/detail[\/\w\-%]*(?=\w{32})/i, 'www.crx4chrome.com/extensions/'); }, () => { // 否 }, () => { // 取消 isPrevent = false; a.onclick = null; }); } } } let pan = YunDisk.sites[YunDisk.mapHost(a.host)]; if (pan) YunDisk.addCode(a); if (isTextToLink) { let isClicked = false; if (pan || t.get("autoClickSites", []).concat(YunDisk.pans).some(h => h == a.host) || /^magnet:\?xt=urn:btih:|^ed2k:\/\/\|file\||^thunder:\/\//i.test(a.href)) { a.click(); isClicked = true; } if (isInput) { if (!isClicked) a.click(); $('#L_DirectInput').val(''); } } if (/^magnet:\?xt=urn:btih:|^ed2k:\/\/\|file\||^thunder:\/\//i.test(a.href)) $(a).removeAttr('target'); add_blank(a); if (isPrevent) { a.onclick = null; a.click(); } } } // 注册菜单项添加文本转链接后自动跳转域名 t.registerMenu('添加自动跳转域名', addAutoClick); function addAutoClick() { let autoClickSites = t.get("autoClickSites", []), input = prompt("输入的域名的链接文本转链接后会自动跳转", locHost); if (input) { if (/[\w]+(\.[\w]+)+/.test(input)) { if (!autoClickSites.some((s) => s.includes(input))) { autoClickSites.push(input); t.set("autoClickSites", autoClickSites); } else t.showNotice(`域名 <${input}> 已存在!!!`); } else t.showNotice(`<${input}> 不是有效域名!!!`); } } // 注册菜单项自动切换镜像 let jumpToMirror = t.get("jumpToMirror", true); let menuID = t.registerMenu( `${jumpToMirror ? "[✔]" : "[✖]"}自动切换镜像`, autoJump ); function autoJump() { jumpToMirror = !jumpToMirror; t.set("jumpToMirror", jumpToMirror); t.unregisterMenu(menuID); menuID = t.registerMenu( `${jumpToMirror ? "[✔]" : "[✖]"}自动切换镜像`, autoJump ); } if (RedirectPage.sites[locHost]) RedirectPage.redirect(locHost); let textLength = t.get("textLength", 200); // t.registerMenu( // `设置文本字数限制(${textLength})`, // limitText // ); // function limitText() { // let input = prompt( // "请输入文本字数限制: ", // t.get("textLength", 200) // ); // } let url_regexp_g = new RegExp(url_regexp, "ig"); function textToLink(e) { if ( !["body", "code", "pre", "select", "main", "input", "textarea"].some( (tag) => tag === e.localName ) && !["www.google."].some((h) => locHost.includes(h)) ) { let span = null, count = 0; if (e.childNodes.length < 10) for ( let i = e.childNodes.length - 1; i >= 0; i-- ) { let child = e.childNodes[i]; if ( !["a", "br", "code", "pre", "img", "script", "option", "input", "textarea"].some( (tag) => tag === child.localName ) && child.className !== "textToLink" && child.textContent.length < textLength ) { let text = child.textContent, result = url_regexp_g.test(text); if (result) { span = $(""); span.html( text.replace(url_regexp_g, function ($1) { count++; if ($1.includes("@")) return `${$1}`; return $1.startsWith("http") ? `${$1}` : $1.includes("magnet") || $1.includes("ed2k") ? `${$1}` : /^thunder:\/\//i.test($1) ? `${$1}` : `${$1}`; }) ); $(child).replaceWith(span); } } } if (count) t.increase(); return count == 1 && span && span.children()[0]; } } function text2Link(node) { if (node.nodeValue.length < textLength) { let text = node.nodeValue, result = url_regexp_g.test(text), span = null, count = 0; if (result) { span = $(""); span.html( text.replace(url_regexp_g, function ($1) { count++; if ($1.includes("@")) return `${$1}`; return $1.startsWith("http") ? `${$1}` : $1.includes("magnet") || $1.includes("ed2k") ? `${$1}` : /^thunder:\/\//i.test($1) ? `${$1}` : `${$1}`; })/*.replace(/点/g, '.')*/ ); $(node).replaceWith(span); } if (!result) { result = /\b\w{40}\b/i.exec(text); if (result) { span = $(""); span.html( text.replace(/\w{40}/i, function ($1) { count++; return `${$1}`; }) ); $(node).replaceWith(span); } } if (count) t.increase(); return count == 1 && span && span.children()[0]; } } function isLinkText(a) { let keywords = [ "niao.su/go", "www.sunweihu.com/go/?url=", "jump.bdimg.com/safecheck/index?url=", "jump2.bdimg.com/safecheck/index?url=", "zhouxiaoben.info/wp-content/themes/begin/go.php?url=", "www.423down.com/wp-content/plugins/momgo/go.php?url=", "www.423down.com/go.php?url=", "www.ccava.net/xc_url/?url=", "www.imaybes.cc/wl?url=", "iphone.myzaker.com/zaker/link.php?pk=", "www.qiuziyuan.net/e/DownSys/DownSoft/?classid=", ], linkTextPrefixes = t.get("linkTextPrefixes", []); return keywords.some((k) => a.href.includes(k)) || linkTextPrefixes.some((k) => a.href.includes(k)); } function isDifferent(a) { if (/(?:http|https|\/|\%2F).*?\?.+?=|.*?\?/.test(a.href)) { let hash = a.hash, search = a.search, password = t.search(a); a.hash = ""; if (password) a.search = ""; let text = decodeURIComponent(a.innerText).toLowerCase().replace(/^https?:\/\/|\/$/, '').replace(hash, ''), href = decodeURIComponent(a.href).toLowerCase().replace(/^https?:\/\/|\/$/, ''); a.hash = hash; if (password) a.search = search; return !(text.includes('...') || !text.includes('/') || text == href); } return false; } let excludeSites = [ "v.qq.com", "v.youku.com", "blog.csdn.net", "cloud.tencent.com", "translate.google.com", "domains.live.com", "passport.yandex.ru", "www.iconfont.cn", "www.kdocs.cn", "help.aliyun.com", "cn.bing.com", "service.weibo.com", "zhannei.baidu.com", "pc.woozooo.com", "play.google.com", "nimg.ws.126.net", ]; t.update('excludeSites', excludeSites); excludeSites = t.get("excludeSites", excludeSites); t.registerMenu("添加例外域名", addExcludeSite); // 添加例外域名 function addExcludeSite() { let input = prompt("输入的域名下的链接不会被净化: ", locHost); if (input) { if (/[\w]+(\.[\w]+)+/.test(input)) { if (!excludeSites.some((s) => s.includes(input))) { excludeSites.push(input); t.set("excludeSites", excludeSites); } else t.showNotice(`例外域名 <${input}> 已存在!!!`); } else t.showNotice(`<${input}> 不是有效域名!!!`); } } function cleanRedirectLink(a) { // 小众软件 if (locHost == 'www.appinn.com' && (a.search.includes('ref=appinn') || a.hash.includes('ref=appinn'))) { t.title(a, '【净化】'); a.search = a.search.replace(/[?&]ref=appinn$/, ''); a.hash = a.hash.replace(/[#&]ref=appinn$/, ''); t.increase(); return true; } // 净化跳转链接 let hosts = ['dalao.ru', 'niao.su', 'iao.su', 'nicelinks.site', 'www.appinn.com', 'support.qq.com', locHost]; for (let h of hosts) { let reg = RegExp(`\\?(?:utm_source=)?${h}$`), result = reg.exec(a.href); if (result) { t.title(a, '【净化】'); a.href = a.href.replace(result[0], ''); t.increase(); } } // 移除链接末尾的&z和%26z/ if (/htm_(data|mob)\/\d+\/\d+\/\d+\.html|cl.\d+[xyz].xyz\/\w+\.php.*/.test(locHref)) { a.href = a.href.replace('https://to.redircdn.com/?', '').replace(/(?:%26|&)z\/?$|%26%23160%3B$/i, '').replace(/______/g, '.'); return true; } // 语雀 if (locHost === "www.yuque.com" && a.search.includes('fileGuid=')) { t.title(a, '【净化】'); a.search = a.search.replace(/[?&]fileGuid=\w{16}$/, ''); t.increase(); return true; } // 那些免费的砖 if (locHost === "www.thosefree.com") { if (a.search.match("\\?from=thosefree\\.com")) { t.title(a, '【净化】'); a.search = ''; } } let reg = new RegExp('^((?:http|https|\\/|\\%2F)(?:.*?[?&].+?=|.*?[?&]))' + url_re_str, "i"), result = reg.exec(decodeURIComponent(a.href)); if (result) { let temp = decodeURIComponent( decodeURIComponent(result[2]) ).replace(/https?:\/\//, ''); if ( !( decodeURIComponent(locHref).replace(/https?:\/\//, '').includes( temp.split("&")[0] ) || ['login', 'oauth'].some(k => locHref.includes(k)) || /登录|注册|log|sign/i.test(a.textContent) || excludeSites.some((s) => result[1].includes(s)) || YunDisk.sites[YunDisk.mapHost(a.host)] ) ) { if (!/t\d+\.html/i.test(temp)) { let href = decodeURIComponent( decodeURIComponent( t.http(result[2]) ) ); t.title(a, '【净化】'); if (["c.pc.qq.com","mail.qq.com", "m.sogou.com", "www.douban.com", "www.google.com", "txt.guoqiangti.ga", "g.luciaz.me"].some((h) => a.host == h)) a.href = href.split("&")[0]; else a.href = href; } t.increase(); return true; } } } let defaultTargetSites = t.get("defaultTargetSites", ['shuax.com', 'app.infinityfree.net']); let isAddBlank = t.get("isAddBlank", false); let isDefault = defaultTargetSites.some((s) => s == location.host); // 注册菜单项该站链接保持默认打开方式 if (!isDefault) { let menuID2 = t.registerMenu( "该站链接保持默认打开方式", function () { defaultTargetSites.push(location.host); t.set("defaultTargetSites", defaultTargetSites); isDefault = defaultTargetSites.some( (s) => s == location.host ); t.unregisterMenu(menuID2); t.unregisterMenu(menuID); } ); // 注册菜单项启停在新标签打开链接 let menuID = t.registerMenu( `${isAddBlank ? "[✔]" : "[✖]"}在新标签打开链接`, addBlank ); // 启停在新标签打开链接 function addBlank() { isAddBlank = !isAddBlank; t.set("isAddBlank", isAddBlank); t.unregisterMenu(menuID); menuID = t.registerMenu( `${isAddBlank ? "[✔]" : "[✖]"}在新标签打开链接`, addBlank ); } } // 给链接添加[target="_blank"]属性 function add_blank(a) { if (isAddBlank && !isDefault) { let result = a.href == "" || a.target == "_blank" || /javascript[\w:;()]+/.test(a.href) || /\/\w+-\d+-\d+\.html|.+page\/\d+|category-\d+_?\d*/.test( a.href ) || /[前后後上下首末].+[页頁篇张張]|^\.*\s*\d+\s*\.*$|^next$|^previous$|^[<>]$/i.test( a.innerText ) || ["prev", "next"].some( (r) => r == a.attributes.rel && a.attributes.rel.nodeValue ) || ["prev", "next", "nxt"].some((r) => a.className.includes(r) ) || a.href == location.origin + "/" || a.href.endsWith(".user.js"), relative = t.get("relative", false); if (!relative) result = result || !/^(?:https?|\/\/).+/.test( a.attributes.href && a.attributes.href.nodeValue ); if (!result) a.target = "_blank"; } } // 添加链接直达输入框 let addDirectTo = t.get('addDirectTo', true); if (addDirectTo) add_direct(); let menuID2 = t.registerMenu(`${addDirectTo ? "[✔]" : "[✖]"}显示链接直达输入框`, directToMenu); function directToMenu() { addDirectTo = !addDirectTo; t.set('addDirectTo', addDirectTo); t.unregisterMenu(menuID2); menuID2 = t.registerMenu(`${addDirectTo ? "[✔]" : "[✖]"}显示链接直达输入框`, directToMenu); if (addDirectTo) add_direct(); else if ($('#L_DirectTo').length) $('#L_DirectTo').remove(); } function add_direct() { $('body').append(`
`); GM_addStyle(`#L_DirectTo input { outline: none; } #L_DirectTo { position: fixed; left: 0; top: 25%; } #L_DirectButton { width: 30px; height: 30px; position: absolute; z-index: 1; left: -16px; user-select: none; } #L_DirectInput { width: 300px; height: 22px; position: absolute; left: -350px; border: 3px solid #b52bff; border-radius: 20px; background-color: #99adf7; padding-left: 10px; box-sizing: content-box; user-select: none; } `); let direct = $('#L_DirectTo'), input = $('#L_DirectInput'), button = $('#L_DirectButton'); input.on('click', obj => listener(obj)); input.on('paste', () => { setTimeout(() => input[0].click(), 500); }); input.val(''); button.on('click', () => { if (button.hasClass('open')) { input.animate({ left: '-350px' }).val('').blur(); button.removeClass('open'); button.prop('title', '点击展开输入框'); } else { button.addClass('open'); input.focus().animate({ left: '28px' }); button.prop('title', '点击收起输入框'); } }) .on('mouseover', () => { button.animate({ left: 0 }); if (!button.hasClass('open')) button.click(); }) .on('mouseout', () => { if (!button.hasClass('open')) button.animate({ left: '-16px' }); }); let timeId = null; direct.on('mouseout', () => { timeId = setTimeout(() => { if (button.hasClass('open')) { button.click(); button.animate({ left: '-16px' }); } }, 5000); }) .on('mouseover', () => { if (timeId) clearTimeout(timeId); }); } } } });