AutoUnlock

自动跳转并解锁百度网盘、Mega分享

  1. // ==UserScript==
  2. // @name AutoUnlock
  3. // @namespace https://greasyfork.org/scripts/31324-autounlock
  4. // @version 0.5.0
  5. // @description 自动跳转并解锁百度网盘、Mega分享
  6. // @author MaiJZ
  7. // @homepageURL https://github.com/maijz128/AutoUnlock
  8. // @supportURL https://github.com/maijz128/AutoUnlock
  9. // @match *://pan.baidu.com/share/init?*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. /*
  14. 百度网盘
  15. 链接的格式:pan.baidu.com/share/init?surl=1miHVd8k&password=hg9j
  16. 没有password不起效
  17. */
  18.  
  19. const Util = {
  20. hrefContains: function (str) {
  21. return location.href.indexOf(str) > 1;
  22. },
  23. GetQueryString: function (name) {
  24. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  25. var r = window.location.search.substr(1).match(reg);
  26. if (r !== null)
  27. return (r[2]);
  28. else
  29. return null;
  30. }
  31. };
  32.  
  33.  
  34. (function () {
  35. 'use strict';
  36. run();
  37. })();
  38.  
  39. function run() {
  40. var isBaiduShareInitSite = Util.hrefContains("pan.baidu.com/share/init");
  41.  
  42. if (isBaiduShareInitSite) {
  43. BaiduPan();
  44. }
  45. }
  46.  
  47.  
  48.  
  49.  
  50. function BaiduPan() {
  51. if (Util.hrefContains("password=")) {
  52. unlockBaidu();
  53. }
  54.  
  55. function unlockBaidu() {
  56. const value = Util.GetQueryString("password");
  57. if (value !== null || value !== "null") {
  58. var password = decodeURIComponent(value);
  59. console.log("password=" + password);
  60. _unlockBaidu(password);
  61. }
  62. }
  63.  
  64.  
  65. function _unlockBaidu(password, count) {
  66. const MAX_TIME = 10 * 1000;
  67. const INTERVAL = 50;
  68. const MAX_COUNT = MAX_TIME / INTERVAL;
  69. count = count || 1;
  70.  
  71. console.log("password: " + password + " count: " + count);
  72. if (count < MAX_COUNT && password) {
  73.  
  74. var inputs = document.querySelectorAll("input");
  75. var input = inputs[0];
  76. var submitBtn = document.querySelector("a[title='提取文件']");
  77. if (input && submitBtn) {
  78. input.value = password;
  79. submitBtn.click();
  80. }
  81.  
  82. setTimeout(function () {
  83. _unlockBaidu(password, count + 1);
  84. }, INTERVAL);
  85. }
  86. }
  87.  
  88. }