Greasy Fork is available in English.

磁力链接百度网盘补完

磁力链接、百度网盘补完

Από την 17/05/2019. Δείτε την τελευταία έκδοση.

// ==UserScript==
// @name         磁力链接百度网盘补完
// @namespace    http://tampermonkey.net/
// @version      1.83
// @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})?\/.*$)/
// ==/UserScript==

(function () {
  'use strict';

  console.log("UrlLinePlugin");
  var MagnetMk = true;
  var BaiduMk = true;



  var PixivMk = false;
  var BilibiliMk = false;



  //字符串格式化方法
  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 && /</.test(new_val)) {
                  $(node).before(new_val);
                  remove.push(node);
                } else {
                  node.nodeValue = new_val;
                }
              }
            }
          }
        } while (node = node.nextSibling);
      }

      // Time to remove those elements!
      remove.length && $(remove).remove();
    });
  };


  //默认配置参数  default settings
  var defaults = {
    pixivPattern: /(?=.{6,20}\b)(?=(\b[Pp])|\b(id|Id|ID))[^0-9?]{0,12}(\d{6,10})(?![:.\-\!\?])/g,
    hcagPattern: /(\u672c\u7ad9\u6682?\u4e0d\u63d0\u4f9b(\u6587\u4ef6)?\u4e0b\u8f7d)/g,
    bilibiliPattern: /(av|Av|AV)(\u53f7)?([0-9]{5,10})(?![:.\-\!\?/\d])/g,
    magnetPattern2: /不提供(文件)?下载/g,
    magnetPattern: /(magnet:\?)?(xt=)?(urn:btih:)?(?=.{0,31}[0-9])(?=.{0,31}[a-z])([0-9A-Z]{32,40})(?![:.\-\!\?a-z0-9])/gi,
    pixivurl: "<a href='https://www.pixiv.net/member_illust.php?mode=medium&illust_id={0}' target='_blank'>{1}</a>",
    bilibiliurl: "<a href='https://www.bilibili.com/video/av{0}/' target='_blank'>{1}</a>",
    magneturl: "<a href='magnet:?xt=urn:btih:{0}' target='_blank'>magnet:?xt=urn:btih:{1}</a>",
    baiduurl1: "<a href='https://pan.baidu.com/s/1{0}' target='_blank' urlline='true'>" + "https://pan.baidu.com/s/1{1}</a>",
    baiduurl2: "<a href='https://pan.baidu.com/s/1{0}#{1}' target='_blank' urlline='true' >{2}</a>",
    baiduurl3: "<a href='https://pan.baidu.com/s/1{0}' target='_blank' urlline='true' >{1}</a>",
    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}))/,
    baiduPattern: /(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})/,
    common_reg: /\s*(提取密碼|提取密码|提取码|提取碼|提取|密碼|密码|百度|百度云|云盘|yun|通关口令|本帖隐藏的内容)[::]?\s*(<[^>]+>)?\s*([0-9a-zA-Z]{4,})\s*/,
    common_r: "\\s*({0})[::]?\\s*(<[^>]+>)?\\s*([0-9a-zA-Z]{4,})\\s*",
    Pwnum: 5
  };

  function UrlLinePlugin(options) {
    this.settings = $.extend({}, defaults, options);
    this._defaults = defaults;
    this.init();
  }
  UrlLinePlugin.prototype = {
    init: function () {
      //obj = this;
    },
    Star: function () {
      var e = this;
      console.log("star");
      e.StarReplace.call(e);
    },
    StarReplace: function () {
      var obj = this;
      if (PixivMk) obj.PixivReplace(obj);
      if (BilibiliMk) obj.BilibiliReplace(obj);
      if (MagnetMk) obj.MagnetReplace(obj);
      if (BaiduMk) obj.BaiduReplace(obj);
    },
    PixivReplace: function (obj) {
      try {
        obj._subPixivReplace(obj);
      } catch (err) {
        console.log("Pixiv replace Error:" + err.message);
      }
    },
    BilibiliReplace: function (obj) {
      try {
        obj._subBilibiliReplace(obj);
      } catch (err) {
        console.log("Bilibili replace Error:" + err.message);
      }
    },
    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");
          //填寫密碼
          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);
          }
        } else {
          obj._subBaiduReplace(obj);
        }
      } catch (err) {
        console.log("baidu replace Error:" + err.message);
      }
    },
    _subPixivReplace: function (obj) {
      function pixivReplacer(match, p1, p2, p3) {
        return obj.settings.pixivurl.UrlLineformat(p3, match);
      }
      $("*").not("script").replaceText(obj.settings.pixivPattern, pixivReplacer);
      console.log(location.href + "is pixiv replace");
    },
    _subBilibiliReplace: function (obj) {
      function bilibiliReplacer(match, p1, p2, p3) {
        return obj.settings.bilibiliurl.UrlLineformat(p3, match);
      }
      $("*").not("script").replaceText(obj.settings.bilibiliPattern, bilibiliReplacer);
      console.log(location.href + "is bilibili replace");
    },
    _subMagnetReplace: function (obj) {
      $("*").replaceText(obj.settings.hcagPattern, "");
      $("*").replaceText(obj.settings.magnetPattern2, "");
      function magnetReplacer(match, p1, p2, p3, p4) {
        var value = match.replace("magnet:?", "").replace("xt=", "").replace("urn:btih:", "");
        return obj.settings.magneturl.UrlLineformat(value, match);
      }
      $("*").not("script").replaceText(obj.settings.magnetPattern, magnetReplacer);
      console.log(location.href + "is magnet replace");
    },

    _subBaiduReplace: function (obj) {
      function fetchPid(e) {
        let t2 = obj.settings.baiduPattern0.exec(e);
        var v = t2[3] ? t2[3] : (t2[5] ? t2[5] : (t2[6] ? t2[6] : t2[7]));
        return v;
      }
      function GetDownUrl(value, Pid, pw) {
        if (!pw) {
          return obj.settings.baiduurl1.UrlLineformat(Pid, Pid);
        } else {
          return obj.settings.baiduurl2.UrlLineformat(Pid, pw, pw);
        }
      }
      function Geturl(Pid, match) {
        return obj.settings.baiduurl3.UrlLineformat(Pid, match);
      }
      function baiducheck(text) {
        return obj.settings.baiduPattern0.test(text)
      }
      function GetPw(text) {
        let p;
        var pw = (p = obj.settings.common_reg.exec(text)) && 4 === p.length ? p[3] : null;
        return pw;
      }

      function Getnextnode(node) {
        var loopnum = obj.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 = obj.settings.Pwnum;
        var bnode = Getnextnode(node);
        if (bnode) {
          do {
            var bh = bnode.nodeValue ? bnode.nodeValue : bnode.outerHTML;
            var bt = bnode.nodeValue ? bnode.nodeValue : bnode.innerText;
            if (bnode && bt) {
              if (baiducheck(bt)) break;
              var pw = GetPw(bt);
              if (pw != null) {
                var retext = GetDownUrl(pw, Pid, pw);
                var h = bh.replace(pw, retext);
                $(bnode).replaceWith(h);
                //$(bnode).remove();
                break;
              }
            }
            bnode = !bnode.nextSibling ? Getnextnode(bnode) : bnode.nextSibling;
            if (!bnode) break;
            loopnum--;
          } while (loopnum >= 0);
        }
      }

      function ReplaceorPw(node, e, n) {
        var Pid = fetchPid(n[0]);
        if (!Pid) return e;
        var retext = GetDownUrl(n[0], Pid);
        var v = e.replace(n[0], retext);
        var pw = GetPw(e);
        var ischeck = false;
        if (!pw) {
          var s = e.substring(e.indexOf(Pid) + Pid.length);
          if (baiducheck(s)) {
            ischeck = true;
          }
          else {
            let ss;
            pw = (ss = /[::]?\s*(<[^>]+>)?\s*([0-9a-zA-Z]{4,8})/.exec(s)) && 3 === ss.length ? ss[2] : null;
          }
        }
        if (pw) {
          var retext2 = GetDownUrl(pw, Pid, pw);
          v = v.replace(pw, retext2);
        } else {
          FindNextPw(node, Pid);
        }
        if (ischeck) {
          v = ReplaceorPw(node, v, [s]);
        }
        return v;
      }

      function baiduReplacer(match, p1, p2, p3) {
        var Pid = fetchPid(match);
        return Geturl(Pid, match);
      }

      $("*").not("script").not("a").replaceText(obj.settings.baiduPattern0, baiduReplacer, ReplaceorPw);


      $("a[urlline!='true']").each(function () {
        var h = $(this).attr("href");
        if (baiducheck(h)) {
          var Pid = fetchPid(h);
          FindNextPw(this, Pid);
        } else {
          if (/\.bdimg.com/.test(h)) {
            var t = $(this).text()
            if (baiducheck(t)) {
              var tPid = fetchPid(t);
              FindNextPw(this, tPid);
            }
          }
        }
      });
      console.log(location.href + "is baidu replace");
    }

  };

  var e = new UrlLinePlugin();
  e.Star();

})();