// ==UserScript== // @name 磁力链接百度网盘补完 // @namespace http://tampermonkey.net/ // @version 2.00 // @description 磁力链接、百度网盘补完 // @author backrock12 // @include * // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js // @exclude /(^[^:\/#\?]*:\/\/([^#\?\/]*\.)?www\.gamersky\.com(:[0-9]{1,5})?\/.*$)/ // @exclude /(^[^:\/#\?]*:\/\/([^#\?\/]*\.)?www\.baidu\.com(:[0-9]{1,5})?\/.*$)/ // @exclude /(^[^:\/#\?]*:\/\/([^#\?\/]*\.)?www\.ciweimao\.com(:[0-9]{1,5})?\/.*$)/ // @downloadURL none // ==/UserScript== (function () { 'use strict'; console.log("UrlLinePlugin"); //字符串格式化方法 String.prototype.UrlLineformat = function (args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof args == "object") { for (var key in args) { if (args[key] != undefined) { var reg = new RegExp("({" + key + "})", "g"); result = result.replace(reg, args[key]); } } } else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { var reg = new RegExp("({)" + i + "(})", "g"); result = result.replace(reg, arguments[i]); } } } } return result; }; $.fn.replaceText = function (search, replace, action, text_only) { return this.each(function () { var node = this.firstChild, val, new_val,// Elements to be removed at the end. remove = []; if (node) { do { if (node.nodeType === 3) { val = node.nodeValue; if (val) { if (!action && replace) { new_val = val.replace(search, replace); } else { var t = search.exec(val) if (action && t && t.length > 0) new_val = action(node, val, t); else new_val = val; } if (new_val !== val) { if (!text_only && /{1}", bilibiliurl: "{1}", magneturl: "magnet:?xt=urn:btih:{1}", baiduurl1: "" + " https://pan.baidu.com/s/1{1} ", baiduurl2: "{2}", baiduurl3: "{1}", baiduurl4: " https://pan.baidu.com/s/1{2}#{3} ", baiduPattern0: /((https?:\/\/)?pan\.baidu\.com\/s\/1([a-zA-Z0-9_\-]{5,22})|(https?:\/\/)?pan\.baidu\.com\/share\/init\?surl=([a-zA-Z0-9_\-]{5,22})|[^a-zA-Z]s\/1([a-zA-Z0-9_\-]{5,22})|\bs\/1([a-zA-Z0-9_\-]{5,22}))/, baiduPattern1: /(https?:\/\/)?pan\.baidu\.com\/s\/1([a-zA-Z0-9_\-]{5,22})/, baiduPattern2: /(https?:\/\/)?pan\.baidu\.com\/share\/init\?surl=([a-zA-Z0-9_\-]{5,22})/, baiduPattern3: /\/?s\/1([a-zA-Z0-9_\-]{5,22})/, baiduPattern4: /\/?s?\/?1([a-zA-Z0-9_\-]{5,22})(?!\.)/, common_reg1: /\s*(提取密碼|提取密码|提取码|提取碼|提取|密碼|密码|百度|百度云|云盘|yun|通关口令|本帖隐藏的内容)[::]?\s*(<[^>]+>)?\s*([0-9a-zA-Z]{4,})\s*/, common_reg2: /\s*(提取密碼|提取密码|提取码|提取碼|提取|密碼|密码|百度|百度云|云盘|yun|通关口令|本帖隐藏的内容)[::]?\s*/, common_reg3: /\s*(<[^>]+>)?\s*([0-9a-zA-Z]{4,})\s*/, common_reg4: /[::]?\s*(<[^>]+>)?\s*([0-9a-zA-Z]{4,8})/, common_r: "\\s*({0})[::]?\\s*(<[^>]+>)?\\s*([0-9a-zA-Z]{4,})\\s*", Pwnum: 5 }; function FormatGet(key) { if (key == 'DownUrl') { if (!arguments[3]) { return default_settings.baiduurl1.UrlLineformat(arguments[2], arguments[2]); } else { return default_settings.baiduurl2.UrlLineformat(arguments[2], arguments[3], arguments[3]); } } else if (key == 'Url') { return default_settings.baiduurl3.UrlLineformat(arguments[0], arguments[1]); } else if (key == 'baiduurl4') { if (!arguments[2]) { return default_settings.baiduurl1.UrlLineformat(arguments[1], arguments[1]); } else { return default_settings.baiduurl4.UrlLineformat(arguments[1], arguments[2], arguments[1], arguments[2]); } } } function SettingCheck(key, value) { if (key == 'baiduPattern0') { return default_settings.baiduPattern0.test(value) } else if (key == 'common_reg2') { return default_settings.common_reg2.test(value) } } function SettingGet(key, value) { let ss; if (key == 'common_reg4') { return (ss = default_settings.common_reg4.exec(value)) && 3 === ss.length ? ss[2] : null; } else if (key == 'common_reg3') { return (ss = default_settings.common_reg3.exec(value)) && 3 === ss.length ? ss[2] : null; } else if (key == 'common_reg1') { return (ss = default_settings.common_reg1.exec(value)) && 4 === ss.length ? ss[3] : null; } else if (key == 'baiduPattern0') { ss = default_settings.baiduPattern0.exec(value); return ss[3] ? ss[3] : (ss[5] ? ss[5] : (ss[6] ? ss[6] : ss[7])); } else if (key == 'baiduPattern4') { return (ss = default_settings.baiduPattern4.exec(value)) && 2 === ss.length ? ss[1] : null; } } function Getnextnode(node) { var loopnum = default_settings.Pwnum; var bnode = node.nextSibling; if (!bnode) bnode = node.parentNode.nextSibling; while (node && !bnode && loopnum >= 0) { bnode = node.nextSibling; node = node.parentNode; loopnum--; } return bnode; } function FindNextPw(node, Pid) { var loopnum = default_settings.Pwnum; var bnode = Getnextnode(node); var isreg2 = false; if (bnode) { do { var bh = bnode.nodeValue ? bnode.nodeValue : bnode.outerHTML; var bt = bnode.nodeValue ? bnode.nodeValue : bnode.innerText; if (bnode && bt) { if (SettingCheck('baiduPattern0', bt)) break; var pw = SettingGet('common_reg1', bt); if (isreg2) pw = SettingGet('common_reg3', bt); if (pw != null) { var retext = FormatGet('DownUrl', '', Pid, pw); var h = bh.replace(pw, retext); $(bnode).replaceWith(h); //$(bnode).remove(); break; } else { if (SettingCheck('common_reg2', bt)) isreg2 = !isreg2; } } bnode = !bnode.nextSibling ? Getnextnode(bnode) : bnode.nextSibling; if (!bnode) break; loopnum--; } while (loopnum >= 0); } } function ReplaceorPw(node, e, n) { var Pid = SettingGet('baiduPattern0', n[0]); if (!Pid) return e; var retext = FormatGet('DownUrl', n[0], Pid); var v = e.replace(n[0], retext); var pw = SettingGet('common_reg1', e); var ischeck = false; if (!pw) { var s = e.substring(e.indexOf(Pid) + Pid.length); if (SettingCheck('baiduPattern0', s)) { ischeck = true; } else { pw = SettingGet('common_reg4', s); } } if (pw) { var retext2 = FormatGet('DownUrl', '', Pid, pw); v = v.replace(pw, retext2); } else { FindNextPw(node, Pid); } if (ischeck) { v = ReplaceorPw(node, v, [s]); } return v; } function UrlLinePlugin(options) { this.settings = $.extend({}, default_settings, options); this._defaults = default_settings; this.init(); } UrlLinePlugin.prototype = { init: function () { //obj = this; }, Star: function () { var t = this; console.log("star"); if (/tieba\.baidu\.com/.test(location.href)) { setTimeout(function () { console.log("tieba"); t.StarReplace.call(t); }, 2000); } else { t.StarReplace.call(t); } document.addEventListener("keydown", function (e) { /* CTR + Z */ if (e.keyCode == 90 && e.ctrlKey) { t.StarReplace.call(t); } else if (e.keyCode == 88 && e.ctrlKey) { t.BaiduFilter(t); } }); }, StarReplace: function () { var obj = this; obj.MagnetReplace(obj); obj.BaiduReplace(obj); }, MagnetReplace: function (obj) { try { obj._subMagnetReplace(obj); } catch (err) { console.log("Magnet replace Error:" + err.message); } }, BaiduReplace: function (obj) { try { if (/pan\.baidu\.com/.test(location.href)) { console.log("baiduPassword"); // $(".file-name").css('white-space','inherit'); $("[class*='global-icon-16']").css('float', 'left'); //填寫密碼 if (location.hash && location.hash.length == 5) { var pwinput = $(".QKKaIE"); if (!pwinput) pwinput = $(":contains('请输入提取码'):last").nextAll("input"); if (!pwinput) pwinput = $(":contains('请输入提取码'):last").next().find("input"); pwinput.val(location.hash.slice(1, 5)); setTimeout(function () { var pwbtn = $("a:contains('提取文件')"); pwbtn.click(); }, 50); } obj.AddPWButton(); } else { obj._subBaiduReplace(obj); } } catch (err) { console.log("baidu replace Error:" + err.message); } }, _subMagnetReplace: function (obj) { $("*").replaceText(default_settings.magnetPattern2, ""); function magnetReplacer(match, p1, p2, p3, p4) { var value = match.replace("magnet:?", "").replace("xt=", "").replace("urn:btih:", ""); return default_settings.magneturl.UrlLineformat(value, match); } $("*").not("script").not("a[urlline='true']").replaceText(default_settings.magnetPattern, magnetReplacer); console.log(location.href + "is magnet replace"); }, _subBaiduReplace: function (obj) { $("*").not("script").not("a").replaceText(default_settings.baiduPattern0, function (match, p1, p2, p3) { var Pid = SettingGet('baiduPattern0', match); return FormatGet('Url', Pid, match); }, ReplaceorPw); $("a[urlline!='true']").each(function () { var h = $(this).attr("href"); if (SettingCheck('baiduPattern0', h)) { var Pid = SettingGet('baiduPattern0', h); FindNextPw(this, Pid); } else { if (/\.bdimg.com/.test(h)) { var t = $(this).text() if (SettingCheck('baiduPattern0', t)) { var tPid = SettingGet('baiduPattern0', t); FindNextPw(this, tPid); } } } }); console.log(location.href + "is baidu replace"); }, BaiduFilter: function (obj) { var r = window.getSelection(); if (r.rangeCount > 0) { for (i = 0; i < r.rangeCount; i++) { var s = r.getRangeAt(i); var seltext = s.toString(); console.log('Selection' + seltext); var filtertext = seltext.replace(/([\u4e00-\u9fa5]|[::??!!])+/, ''); var Pid, purl, pw; if (SettingCheck('baiduPattern0', filtertext)) { Pid = SettingGet('baiduPattern0', filtertext); } if (!Pid) Pid = SettingGet('baiduPattern4', filtertext); if (Pid) { var lasttext = $.trim(filtertext.substring(filtertext.indexOf(Pid) + Pid.length)); if (lasttext) { pw = SettingGet('common_reg1', lasttext); if (!pw) pw = SettingGet('common_reg4', lasttext); } purl = FormatGet('baiduurl4', Pid, pw) } if (purl) { var a = $(purl)[0]; try { s.insertNode(a); var span = $('')[0]; s.surroundContents(span);//将创建的元素环绕在光标选中的文字周围 s.collapse(false); console.log('Selection Success' + s); } catch (e) { console.log('Selection Error' + e.message); } } } } }, AddPWButton: function () { console.log('AddPWButton'); $('div.slide-show-right').css('width', '500px'); var Pbutton = $(''); var button_a = $(''); var button_a_span = $('PanDown'); var Pbutton_span = $(''); button_a.append(button_a_span); Pbutton.append(button_a).append(Pbutton_span); Pbutton.click(function () { let url = window.location.href; url = url.replace('baidu.com', 'baiduwp.com'); window.open(url, "_blank"); }); $('div.module-share-top-bar div.bar div.x-button-box').append(Pbutton); //Pbutton.insertBefore($("a:contains('请输入提取码')")); } }; var e = new UrlLinePlugin(); e.Star(); })();