当前位置:   article > 正文

使用tampermonkey 脚本愉快上网_tampermonkey 上网

tampermonkey 上网

一:下载tampermonkey插件

tampermonkey对于大部分浏览器均可以使用,如谷歌、火狐、360浏览器、Edge等。下载该插件均可以在其扩展中心下载,这里以windows10自带的Edge为例:

在应用商店搜索tampermonkey下载安装即可,安装好后重启浏览器,右上角会有图标。

二、配置脚本

点击tampermonkey图标,打开“添加脚本”

将会出现如下界面:

 

我们可以添加几个比较实用的脚本,添加之前把上面的模板内容先删除再粘贴进去,添加一个保存一个。

(1)AC重定向脚本,该脚本可以重定向网页地址及调整网页风格。这是我提供的免积分下载链接

(2)网页优化脚本

  1. // ==UserScript==
  2. // @name 网页优化助手
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.8
  5. // @description 1、简化百度页面,去除广告,美化搜索结果,页面滚动到下方自动加载;2、修改部分网站超链打开窗口为新窗口方式;3、Github搜索列表自动翻译,修改列表展示方式,滚动自动加载,readme划词翻译
  6. // @author Yisin
  7. // @require https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js
  8. // @match *://www.baidu.com/*
  9. // @match *://www.google.com.hk/*
  10. // @match *://bbs.125.la/*
  11. // @match *://github.com/*
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_addStyle
  14. // ==/UserScript==
  15. (function () {
  16. 'use strict';
  17. $(window).on('load', function () {
  18. var start = function () {
  19. var host = document.location.host;
  20. // 百度
  21. if(host == 'www.baidu.com'){
  22. new BaiduHelper().listener();
  23. } else if(host == 'github.com'){
  24. // Guthub
  25. new GitHubHelper().listener();
  26. }
  27. // 超链接
  28. new HrefHelp().ready();
  29. };
  30. start();
  31. });
  32. /**
  33. * 百度助手
  34. */
  35. function BaiduHelper() {
  36. this.pageIndex = 1;
  37. this.first = '________________';
  38. }
  39. BaiduHelper.prototype = {
  40. listener: function () {
  41. var that = this;
  42. setInterval(function () {
  43. var href = document.location.href;
  44. if (href == 'https://www.baidu.com/') {
  45. that.homeClearAd();
  46. }
  47. var t = $('.result.c-container .t:eq(0)').text();
  48. if (that.first != t) {
  49. that.first = t;
  50. setTimeout(function () {
  51. that.pageIndex = 1;
  52. that.clearAd();
  53. }, 200);
  54. }
  55. }, 200);
  56. },
  57. // 去广告
  58. homeClearAd: function () {
  59. $('#s_wrap').remove();
  60. document.body.style.overflow = 'hidden';
  61. },
  62. clearAd: function () {
  63. var href = document.location.href;
  64. if (href.substring(0, 24) == 'https://www.baidu.com/s?') {
  65. document.body.style.overflow = 'auto';
  66. $('#content_right,#rs,#foot').remove();//#page,
  67. var cleard = function () {
  68. $('#content_left > div').each(function () {
  69. var that = $(this);
  70. if (!that.hasClass('result') || that.find('.m').text() == '广告') {
  71. that.remove();
  72. }
  73. });
  74. }
  75. setInterval(cleard, 200);
  76. cleard();
  77. this.autoLoadSearch();
  78. this.pageFormat();
  79. }
  80. },
  81. // 页面美化document.body.clientWidth
  82. pageFormat: function () {
  83. // var iw = 500;
  84. // var ch = 160;
  85. // var cw = parseInt(iw / 3) - 23;
  86. // if(cw < 300){
  87. // cw = parseInt(iw / 2) - 23;
  88. //}
  89. var iw = 240;
  90. var cw =600;
  91. var ch = 180;//每个搜索条目高度
  92. var styleText = ".result.c-container{border:1px solid #dedede;margin: 5px;padding: 3px;height: "+ch+"px;float: left;overflow-y: auto;width: " + cw + "px;}";
  93. GM_addStyle('#page{display:none;}#container{width:100%;} #content_left{width: calc(100% - 10px);padding-left:0; padding-top:0;padding:5px;} ' + styleText);
  94. },
  95. // 自动加载搜索下一页
  96. autoLoadSearch: function () {
  97. var that = this;
  98. var loadstatus = false;
  99. var max = $('#page a').length - 1;
  100. var startload = function () {
  101. loadstatus = true;
  102. var kw = $('#kw').val();
  103. var num = that.pageIndex * 10;
  104. var url = formatByJson("https://www.baidu.com/s?wd={wd}&pn={pn}", {
  105. wd: kw, pn: num
  106. });
  107. loadHtml(url, function (res) {
  108. loadstatus = false;
  109. try {
  110. var $html = $(res);
  111. if ($html) {
  112. var items = $html.find('#content_left > div.result');
  113. if (items && items.length) {
  114. $('#content_left').append(items);
  115. that.pageIndex++;
  116. if($('body').height() < $(window).height() && that.pageIndex < max && that.pageIndex < 4){
  117. startload();
  118. }
  119. }
  120. }
  121. } catch (e1) {
  122. }
  123. });
  124. }
  125. startload();
  126. $(window).unbind('scroll').scroll(function (e, i) {
  127. if ($(window).scrollTop() + $(window).height() >= $(document).height() - 10) {
  128. if (!loadstatus) {
  129. startload();
  130. }
  131. }
  132. });
  133. }
  134. };
  135. var githubcss = `
  136. .container-lg {
  137. max-width: 10120px;
  138. }
  139. .paginate-container {
  140. float: left;
  141. width: 100%;
  142. }
  143. .container-lg .float-left.px-md-2 {
  144. width: 210px;
  145. }
  146. .codesearch-results {
  147. width: calc(100% - 210px) !important;
  148. }
  149. .repo-list-item {
  150. width: 530px;
  151. height: 250px;
  152. float: left;
  153. padding: 5px;
  154. overflow-y: auto;
  155. overflow-x: hidden;
  156. border: 1px solid #dddddd;
  157. }
  158. .repo-list-item > div:nth-child(1) {
  159. width: calc(100% - 130px) !important;
  160. }
  161. .repo-list-item > div:nth-child(1) p {
  162. width: 100% !important;
  163. }
  164. .repo-list-item .d-flex {
  165. width: 130px !important;
  166. display: block !important;
  167. float: left;
  168. }
  169. .repo-list-item .d-flex > div {
  170. float: left !important;
  171. width: 230px !important;
  172. height: 30px !important;
  173. text-align: left !important;
  174. }
  175. .paginate-container {
  176. display: none !important;
  177. }
  178. #____github_loading{
  179. position: fixed;
  180. right: 10px;
  181. top: 9px;
  182. z-index: 100;
  183. margin: 0 auto;
  184. text-align: center;
  185. color: #ffffff;
  186. background-color: rgba(134, 0, 0, 0.6);
  187. width: 140px;
  188. padding: 10px;
  189. border: 1px solid #eaaa1a;
  190. box-shadow: 2px 2px 2px #a06800;
  191. }
  192. #js-pjax-container a.u-photo img, #js-pjax-container .js-profile-editable-area {
  193. width: 230px !important;
  194. }
  195. div#user-repositories-list > ul > li {
  196. width: 45%!important;
  197. height: 200px;
  198. float: left;
  199. margin: 10px;
  200. overflow-y: auto;
  201. overflow-x: hidden;
  202. }
  203. `;
  204. /**
  205. * GitHub助手
  206. */
  207. function GitHubHelper() {
  208. this.first = '______';
  209. this.pageIndex = 2;
  210. this.itemw = 530;
  211. }
  212. GitHubHelper.prototype = {
  213. searchPage: function () {
  214. var href = document.location.href;
  215. if (href.substring(0, 26) == 'https://github.com/search?') {
  216. var $inpo = $('input.header-search-input');
  217. if ($inpo && !$inpo.val()) {
  218. $inpo.val('search:start');
  219. }
  220. this.searchFanyi();
  221. var hash = document.location.hash;
  222. var iv = "";
  223. if(hash && hash.length > 1){
  224. iv = hash.substring(1);
  225. }
  226. $('.HeaderMenu div.d-lg-flex').prepend(`
  227. <div class="d-lg-flex">
  228. <select id="_s_key">
  229. <option value="">快速搜索</option>
  230. <option value="1">最新发布、倒序</option>
  231. <option value="2">Start最多,倒序</option>
  232. <option value="3">Fork最多,倒序</option>
  233. </select>
  234. </div>
  235. `);
  236. setTimeout(function(){
  237. $('.HeaderMenu #_s_key').val(iv).on('change', function(){
  238. var v = $(this).val();
  239. var url = "https://github.com/search?";
  240. if(v == 1){
  241. var d = new Date();
  242. url += "o=desc&q=pushed%3A" + (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate()) + "&s=updated&type=Repositories#" + v;
  243. } else if(v == 2){
  244. url += "o=desc&q=stars%3A>1&s=stars&type=Repositories#" + v;
  245. } else if(v == 3){
  246. url += "o=desc&q=stars%3A>1&s=forks&type=Repositories#" + v;
  247. }
  248. if(v){
  249. document.location.href = url;
  250. }
  251. });
  252. }, 300);
  253. }
  254. },
  255. searchFanyi: function () {
  256. var that = this;
  257. var $p = $('.repo-list .repo-list-item p.d-inline-block');
  258. if ($p && $p.length) {
  259. var i1 = 0;
  260. var startFY = function (i2) {
  261. if($p[i2].fy){
  262. i1++;
  263. startFY(i1);
  264. return;
  265. }
  266. var text = $p[i2].innerText;
  267. fanyi(text, function (res) {
  268. if (res) {
  269. i1++;
  270. $p[i2].innerHTML = $p[i2].innerHTML + '<br><div style="color:red">' + res + '</div>';
  271. $p[i2].fy = true;
  272. if (i1 < $p.length) {
  273. startFY(i1);
  274. } else {
  275. $('.repo-list-item a').attr('target', "_blank");
  276. }
  277. }
  278. });
  279. }
  280. startFY(i1);
  281. }
  282. $('.repo-list .repo-list-item').css('width', that.itemw);
  283. },
  284. autoLoad: function () {
  285. var href = document.location.href;
  286. var hash = document.location.hash;
  287. if(hash){
  288. href = href.replace(hash, "");
  289. }
  290. if (href.substring(0, 26) != 'https://github.com/search?') {
  291. return;
  292. }
  293. $('.pagination .previous_page, .pagination .next_page').remove();
  294. var that = this;
  295. var alist = $('.pagination a');
  296. var max = alist.length + 1;
  297. if($('.pagination .current').length){
  298. var t = $('.pagination .current').data('total-pages');
  299. if(t){
  300. max = parseInt(t);
  301. }
  302. }
  303. ("console" in window) && console.info("max page ", max);
  304. var p = "&p=1";
  305. try{
  306. p = href.match(/&p=[0-9]+/g)[0];
  307. }catch(exx){
  308. p = "&p=1";
  309. href += p;
  310. }
  311. var loadstatus = false;
  312. var startload = function () {
  313. if (that.pageIndex > max) {
  314. return;
  315. }
  316. loadstatus = true;
  317. var url = href.replace(p, '&p=' + that.pageIndex);
  318. if(!url.includes("&p=")){
  319. url += '&p=' + that.pageIndex;
  320. }
  321. ("console" in window) && console.info("auto load ", url);
  322. var $load = $('#____github_loading');
  323. if(!$load.length){
  324. $load = $('<div id="____github_loading">正在加载数据...</div>');
  325. $('body').append($load);
  326. }
  327. $load.show();
  328. loadHtml(url, function (res) {
  329. loadstatus = false;
  330. $load.hide();
  331. try {
  332. var $html = $(res);
  333. if ($html) {
  334. var items = $html.find('.repo-list .repo-list-item');
  335. if (items && items.length) {
  336. $('.repo-list').append(items);
  337. that.pageIndex++;
  338. that.searchFanyi();
  339. }
  340. }
  341. } catch (e1) {
  342. }
  343. });
  344. };
  345. $(window).unbind('scroll').scroll(function (e, i) {
  346. if ($(window).scrollTop() + $(window).height() >= $(document).height() - 60) {
  347. if (!loadstatus && startload) {
  348. startload();
  349. }
  350. }
  351. });
  352. var ch = document.body.clientWidth - 226;
  353. if(ch){
  354. var ih = (ch - 32) / 3;
  355. if(ih < 500){
  356. ih = (ch - 32) / 2;
  357. if(ih < 500){
  358. ih = (ch - 32);
  359. }
  360. }
  361. that.itemw = ih;
  362. }
  363. },
  364. projectPage: function () {
  365. var href = document.location.href;
  366. if (href.substring(0, 19) == 'https://github.com/') {
  367. var redme = $('article.entry-content');
  368. redme.on('mouseup', function (ex) {
  369. var $the = $(ex.target);
  370. if($the.attr('id') == '____res' || ($the.parent().length && $the.parent().attr('id') == '____res')){
  371. return;
  372. }
  373. var t1 = selectText();
  374. if (t1 && !/^[\s]+$/g.test(t1)) {
  375. fanyi(t1, function (res) {
  376. if (res) {
  377. var ___res = redme.find('#____res');
  378. if (!___res.length) {
  379. ___res = $("<div>");
  380. ___res.attr('id', '____res');
  381. ___res.css({
  382. position: 'fixed',
  383. right: '10px',
  384. top: '245px',
  385. width: '240px',
  386. height: '400px',
  387. overflow: 'auto',
  388. padding: '5px',
  389. border: '1px solid #eaeaea',
  390. boxShadow: '1px 1px 2px #ababab'
  391. });
  392. redme.append(___res);
  393. ___res.on('click', '.___btn', function(){
  394. ___res.hide();
  395. });
  396. }
  397. ___res.html(t1 + '<br><font color="red">' + res + '</font><br><br><button class="___btn">关闭</button>').show();
  398. }
  399. });
  400. }
  401. });
  402. var span1 = $('.repository-content .f4 span.mr-2');
  403. var t2 = span1.text();
  404. if (t2 && t2.length > 10) {
  405. var b2 = document.createElement("button");
  406. b2.innerText = '翻译';
  407. b2.addEventListener('click', function () {
  408. fanyi(t2, function (res2) {
  409. if (res2) {
  410. span1[0].removeChild(b2);
  411. span1.append('<br><font color="red">' + res2 + '</font>');
  412. }
  413. });
  414. });
  415. span1[0].appendChild(b2)
  416. }
  417. }
  418. },
  419. listener: function () {
  420. var that = this;
  421. setInterval(function () {
  422. var t = $('.repo-list .repo-list-item a:eq(0)').text();
  423. if (that.first != t) {
  424. that.first = t;
  425. that.searchPage();
  426. that.projectPage();
  427. }
  428. }, 200);
  429. that.autoLoad();
  430. GM_addStyle(githubcss);
  431. }
  432. }
  433. /**
  434. * 超链接部分
  435. */
  436. function HrefHelp() { }
  437. HrefHelp.prototype = {
  438. ready: function () {
  439. var eles = document.querySelectorAll('a');
  440. var host = document.location.host;
  441. if (eles && eles.length) {
  442. for (var i = 0; i < eles.length; i++) {
  443. var a = eles[i];
  444. if (a) {
  445. if (host == "www.google.com.hk") {
  446. a.target = "_blank";
  447. } else if (host == "bbs.125.la") {
  448. var f = "" + a.onclick;
  449. if (f.includes('atarget(this)')) {
  450. a.target = "_blank";
  451. a.onclick = null;
  452. }
  453. } else if (host == "github.com" && a.className == 'v-align-middle') {
  454. a.target = "_blank";
  455. }
  456. }
  457. }
  458. }
  459. }
  460. };
  461. function loadHtml(url, callback) {
  462. $.ajax({
  463. url: url,
  464. async: true,
  465. timeOut: 5000,
  466. type: "GET",
  467. dataType: "html"
  468. }).done(function (res) {
  469. callback(res);
  470. });
  471. }
  472. /**
  473. * 获取选择的文本
  474. */
  475. function selectText() {
  476. if (document.Selection) {
  477. //ie浏览器
  478. return document.selection.createRange().text;
  479. } else {
  480. //标准浏览器
  481. return window.getSelection().toString();
  482. }
  483. }
  484. /**
  485. * 翻译
  486. * @param {*} text
  487. * @param {*} callback
  488. */
  489. function fanyi(text, callback) {
  490. if(!text){
  491. return;
  492. }
  493. text = text.replace(/^[\r\n\t\s]+|[\r\n\t\s]+$/g, '').replace(/[\r\n\t]/g, '');
  494. var call = "YoudaoFanyier.Instance.updateTranslate";
  495. var time = new Date().valueOf();
  496. var param = "type=data&only=on&doctype=jsonp&version=1.1&relatedUrl=http%3A%2F%2Ffanyi.youdao.com%2Fopenapi%3Fpath%3Dweb-mode%26mode%3Dfanyier&keyfrom=test&key=null&callback=" + call + "&q=" + encodeURIComponent(text) + "&ts=" + time;
  497. GM_xmlhttpRequest({
  498. method: 'GET',
  499. url: "http://fanyi.youdao.com/openapi.do?" + param,
  500. headers: { "Accept": "*/*", "connection": "Keep-Alive", "Content-Type": "charset=utf-8", "Referer": "http://fanyi.youdao.com/openapi?path=web-mode&mode=fanyier" },
  501. contentType: "application/json",
  502. dataType: 'json',
  503. onload: function (response) {
  504. if (response.statusText == 'OK') {
  505. try {
  506. var res = response.responseText;
  507. if (/^YoudaoFanyier.Instance.updateTranslate/g.test(res)) {
  508. res = res.substring(call.length + 1, res.length - 2);
  509. }
  510. res = JSON.parse(res);
  511. if (callback && res.translation && res.translation.length) {
  512. callback(res.translation[0]);
  513. }
  514. } catch (e) {
  515. callback(response.statusText);
  516. }
  517. } else {
  518. callback(response.statusText);
  519. }
  520. }
  521. });
  522. }
  523. /**
  524. * 字符串格式化,json格式
  525. * @param {*} str
  526. * @param {*} json
  527. */
  528. function formatByJson(str, json) {
  529. if (json) {
  530. for (var key in json) {
  531. var exc = new RegExp('\{' + key + '\}', "g");
  532. str = str.replace(exc, json[key]);
  533. }
  534. }
  535. return str;
  536. }
  537. /**
  538. * 判断变量是否为对象
  539. * @param {*} obj
  540. */
  541. function _isObject(obj) {
  542. return Object.prototype.toString.call(obj) === '[object Object]';
  543. }
  544. })();

(3)百度云直接下载脚本

  1. // ==UserScript==
  2. // @name 百度网盘直接下载助手 直链加速版
  3. // @namespace https://github.com/syhyz1990/baiduyun
  4. // @version 2.0.0
  5. // @icon https://www.baidu.com/favicon.ico
  6. // @description 2019-02-01 满血复活,告别限速(详见Tips2)。支持IDM,迅雷下载,请先安装chrome插件
  7. // @author syhyz1990 <https://github.com/syhyz1990/baiduyun/issues>
  8. // @supportURL https://github.com/syhyz1990/baiduyun
  9. // @contributionURL https://i.loli.net/2018/08/25/5b80ba335f515.png
  10. // @match *://pan.baidu.com/disk/home*
  11. // @match *://yun.baidu.com/disk/home*
  12. // @match *://pan.baidu.com/s/*
  13. // @match *://yun.baidu.com/s/*
  14. // @match *://pan.baidu.com/share/link*
  15. // @match *://yun.baidu.com/share/link*
  16. // @require https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js
  17. // @run-at document-end
  18. // @grant unsafeWindow
  19. // @grant GM_setClipboard
  20. // ==/UserScript==
  21. (function () {
  22. 'use strict';
  23. var $ = $ || window.$;
  24. var log_count = 1;
  25. var wordMapHttp = {};
  26. $(function () {
  27. wordMapHttp['default-dom'] = ($('.icon-upload').parent().parent().parent().parent().parent().attr('class'));
  28. wordMapHttp['bar'] = ($('.icon-upload').parent().parent().parent().parent().attr('class'));
  29. });
  30. var wordMapHttps = {
  31. 'list': 'zJMtAEb',
  32. 'grid': 'fyQgAEb',
  33. 'list-grid-switch': 'auiaQNyn',
  34. 'list-switched-on': 'ewXm1e',
  35. 'grid-switched-on': 'kxhkX2Em',
  36. 'list-switch': 'rvpXm63',
  37. 'grid-switch': 'mxgdJgwv',
  38. 'checkbox': 'EOGexf',
  39. 'col-item': 'Qxyfvg',
  40. 'check': 'fydGNC',
  41. 'checked': 'EzubGg',
  42. 'chekbox-grid': 'cEefyz',
  43. 'list-view': 'vdAfKMb',
  44. 'item-active': 'jddPyQ',
  45. 'grid-view': 'JKvHJMb',
  46. 'bar-search': 'OFaPaO',
  47. //'default-dom':'qkk3LED',
  48. //'bar':'cfj3L8W',
  49. 'list-tools': 'QDDOQB'
  50. };
  51. var wordMap = location.protocol == 'http:' ? wordMapHttp : wordMapHttps;
  52. //console.log(wordMap);
  53. //替换网址为高级下载链接 默认不替换 http不用传
  54. function replaceDownloadLink(link, http) {
  55. var http = http || false;
  56. //是否强制将https替换为http
  57. if (http) {
  58. return link.replace('https://d.pcs.baidu.com', 'http://c.pcs.baidu.com');
  59. } else {
  60. return link.replace('d.pcs.baidu.com', 'c.pcs.baidu.com');
  61. }
  62. }
  63. function slog(c1, c2, c3) {
  64. c1 = c1 ? c1 : '';
  65. c2 = c2 ? c2 : '';
  66. c3 = c3 ? c3 : '';
  67. console.log('#' + log_count++ + '-BaiDuNetdiskHelper-log:', c1, c2, c3);
  68. }
  69. $(function () {
  70. switch (detectPage()) {
  71. case 'disk':
  72. var panHelper = new PanHelper();
  73. panHelper.init();
  74. return;
  75. case 'share':
  76. case 's':
  77. var panShareHelper = new PanShareHelper();
  78. panShareHelper.init();
  79. return;
  80. default:
  81. return;
  82. }
  83. });
  84. //网盘页面的下载助手
  85. function PanHelper() {
  86. var yunData, sign, timestamp, bdstoken, logid, fid_list;
  87. var fileList = [], selectFileList = [], batchLinkList = [], batchLinkListAll = [], linkList = [],
  88. list_grid_status = 'list';
  89. var observer, currentPage, currentPath, currentCategory, dialog, searchKey;
  90. var panAPIUrl = location.protocol + "//" + location.host + "/api/";
  91. var restAPIUrl = location.protocol + "//pcs.baidu.com/rest/2.0/pcs/";
  92. var clientAPIUrl = location.protocol + "//d.pcs.baidu.com/rest/2.0/pcs/";
  93. this.init = function () {
  94. yunData = unsafeWindow.yunData;
  95. slog('yunData:', yunData);
  96. if (yunData === undefined) {
  97. slog('页面未正常加载,或者百度已经更新!');
  98. return;
  99. }
  100. initParams();
  101. registerEventListener();
  102. createObserver();
  103. addButton();
  104. createIframe();
  105. dialog = new Dialog({addCopy: true});
  106. slog('网盘直接下载助手加载成功!');
  107. };
  108. function initParams() {
  109. sign = getSign();
  110. timestamp = getTimestamp();
  111. bdstoken = getBDStoken();
  112. logid = getLogID();
  113. currentPage = getCurrentPage();
  114. slog('Current display mode:', currentPage);
  115. if (currentPage == 'all')
  116. currentPath = getPath();
  117. if (currentPage == 'category')
  118. currentCategory = getCategory();
  119. if (currentPage == 'search')
  120. searchKey = getSearchKey();
  121. refreshListGridStatus();
  122. refreshFileList();
  123. refreshSelectList();
  124. }
  125. function refreshFileList() {
  126. if (currentPage == 'all') {
  127. fileList = getFileList();
  128. } else if (currentPage == 'category') {
  129. fileList = getCategoryFileList();
  130. } else if (currentPage == 'search') {
  131. fileList = getSearchFileList();
  132. }
  133. }
  134. function refreshSelectList() {
  135. selectFileList = [];
  136. }
  137. function refreshListGridStatus() {
  138. list_grid_status = getListGridStatus();
  139. }
  140. //获取当前的视图模式
  141. function getListGridStatus() {
  142. if ($('.' + wordMap['list']).is(':hidden')) {
  143. return 'grid'
  144. } else {
  145. return 'list'
  146. }
  147. }
  148. function registerEventListener() {
  149. registerHashChange();
  150. registerListGridStatus();
  151. registerCheckbox();
  152. registerAllCheckbox();
  153. registerFileSelect();
  154. }
  155. //监视地址栏#标签的变化
  156. function registerHashChange() {
  157. window.addEventListener('hashchange', function (e) {
  158. refreshListGridStatus();
  159. if (getCurrentPage() == 'all') {
  160. if (currentPage == getCurrentPage()) {
  161. if (currentPath == getPath()) {
  162. } else {
  163. currentPath = getPath();
  164. refreshFileList();
  165. refreshSelectList();
  166. }
  167. } else {
  168. currentPage = getCurrentPage();
  169. currentPath = getPath();
  170. refreshFileList();
  171. refreshSelectList();
  172. }
  173. } else if (getCurrentPage() == 'category') {
  174. if (currentPage == getCurrentPage()) {
  175. if (currentCategory == getCategory()) {
  176. } else {
  177. currentPage = getCurrentPage();
  178. currentCategory = getCategory();
  179. refreshFileList();
  180. refreshSelectList();
  181. }
  182. } else {
  183. currentPage = getCurrentPage();
  184. currentCategory = getCategory();
  185. refreshFileList();
  186. refreshSelectList();
  187. }
  188. } else if (getCurrentPage() == 'search') {
  189. if (currentPage == getCurrentPage()) {
  190. if (searchKey == getSearchKey()) {
  191. } else {
  192. currentPage = getCurrentPage();
  193. searchKey = getSearchKey();
  194. refreshFileList();
  195. refreshSelectList();
  196. }
  197. } else {
  198. currentPage = getCurrentPage();
  199. searchKey = getSearchKey();
  200. refreshFileList();
  201. refreshSelectList();
  202. }
  203. }
  204. });
  205. }
  206. //监视视图变化
  207. function registerListGridStatus() {
  208. var $a_list = $('a[data-type=list]');
  209. $a_list.click(function () {
  210. list_grid_status = 'list';
  211. });
  212. var $a_grid = $('a[data-type=grid]');
  213. $a_grid.click(function () {
  214. list_grid_status = 'grid';
  215. });
  216. }
  217. //文件选择框
  218. function registerCheckbox() {
  219. var $checkbox = $('span.' + wordMap['checkbox']);
  220. if (list_grid_status == 'grid') {
  221. $checkbox = $('.' + wordMap['chekbox-grid']);
  222. }
  223. $checkbox.each(function (index, element) {
  224. $(element).bind('click', function (e) {
  225. var $parent = $(this).parent();
  226. var filename;
  227. var isActive;
  228. if (list_grid_status == 'list') {
  229. filename = $('div.file-name div.text a', $parent).attr('title');
  230. isActive = $parent.hasClass(wordMap['item-active']);
  231. } else if (list_grid_status == 'grid') {
  232. filename = $('div.file-name a', $(this)).attr('title');
  233. isActive = !$(this).hasClass(wordMap['item-active'])
  234. }
  235. if (isActive) {
  236. slog('取消选中文件:' + filename);
  237. for (var i = 0; i < selectFileList.length; i++) {
  238. if (selectFileList[i].filename == filename) {
  239. selectFileList.splice(i, 1);
  240. }
  241. }
  242. } else {
  243. slog('选中文件:' + filename);
  244. $.each(fileList, function (index, element) {
  245. if (element.server_filename == filename) {
  246. var obj = {
  247. filename: element.server_filename,
  248. path: element.path,
  249. fs_id: element.fs_id,
  250. isdir: element.isdir
  251. };
  252. selectFileList.push(obj);
  253. }
  254. });
  255. }
  256. });
  257. });
  258. }
  259. function unregisterCheckbox() {
  260. //var $checkbox = $('span.checkbox');
  261. //var $checkbox = $('span.EOGexf');
  262. var $checkbox = $('span.' + wordMap['checkbox']);
  263. $checkbox.each(function (index, element) {
  264. $(element).unbind('click');
  265. });
  266. }
  267. //全选框
  268. function registerAllCheckbox() {
  269. //var $checkbox = $('div.col-item.check');
  270. //var $checkbox = $('div.Qxyfvg.fydGNC');
  271. var $checkbox = $('div.' + wordMap['col-item'] + '.' + wordMap['check']);
  272. $checkbox.each(function (index, element) {
  273. $(element).bind('click', function (e) {
  274. var $parent = $(this).parent();
  275. //if($parent.hasClass('checked')){
  276. //if($parent.hasClass('EzubGg')){
  277. if ($parent.hasClass(wordMap['checked'])) {
  278. slog('取消全选');
  279. selectFileList = [];
  280. } else {
  281. slog('全部选中');
  282. selectFileList = [];
  283. $.each(fileList, function (index, element) {
  284. var obj = {
  285. filename: element.server_filename,
  286. path: element.path,
  287. fs_id: element.fs_id,
  288. isdir: element.isdir
  289. };
  290. selectFileList.push(obj);
  291. });
  292. }
  293. });
  294. });
  295. }
  296. function unregisterAllCheckbox() {
  297. //var $checkbox = $('div.col-item.check');
  298. //var $checkbox = $('div.Qxyfvg.fydGNC');
  299. var $checkbox = $('div.' + wordMap['col-item'] + '.' + wordMap['check']);
  300. $checkbox.each(function (index, element) {
  301. $(element).unbind('click');
  302. });
  303. }
  304. //单个文件选中,点击文件不是点击选中框,会只选中该文件
  305. function registerFileSelect() {
  306. var $dd = $('div.' + wordMap['list-view'] + ' dd');
  307. $dd.each(function (index, element) {
  308. $(element).bind('click', function (e) {
  309. var nodeName = e.target.nodeName.toLowerCase();
  310. if (nodeName != 'span' && nodeName != 'a' && nodeName != 'em') {
  311. slog('shiftKey:' + e.shiftKey);
  312. if (!e.shiftKey) {
  313. selectFileList = [];
  314. var filename = $('div.file-name div.text a', $(this)).attr('title');
  315. slog('选中文件:' + filename);
  316. $.each(fileList, function (index, element) {
  317. if (element.server_filename == filename) {
  318. var obj = {
  319. filename: element.server_filename,
  320. path: element.path,
  321. fs_id: element.fs_id,
  322. isdir: element.isdir
  323. };
  324. selectFileList.push(obj);
  325. }
  326. });
  327. } else {
  328. selectFileList = [];
  329. //var $dd_select = $('div.list-view dd.item-active');
  330. //var $dd_select = $('div.vdAfKMb dd.prWzXA');
  331. var $dd_select = $('div.' + wordMap['list-view'] + ' dd.' + wordMap['item-active']);
  332. $.each($dd_select, function (index, element) {
  333. var filename = $('div.file-name div.text a', $(element)).attr('title');
  334. slog('选中文件:' + filename);
  335. $.each(fileList, function (index, element) {
  336. if (element.server_filename == filename) {
  337. var obj = {
  338. filename: element.server_filename,
  339. path: element.path,
  340. fs_id: element.fs_id,
  341. isdir: element.isdir
  342. };
  343. selectFileList.push(obj);
  344. }
  345. });
  346. });
  347. }
  348. }
  349. });
  350. });
  351. }
  352. function unregisterFileSelect() {
  353. //var $dd = $('div.list-view dd');
  354. //var $dd = $('div.vdAfKMb dd');
  355. var $dd = $('div.' + wordMap['list-view'] + ' dd');
  356. $dd.each(function (index, element) {
  357. $(element).unbind('click');
  358. });
  359. }
  360. //监视文件列表显示变化
  361. function createObserver() {
  362. var MutationObserver = window.MutationObserver;
  363. var options = {
  364. 'childList': true
  365. };
  366. observer = new MutationObserver(function (mutations) {
  367. unregisterCheckbox();
  368. unregisterAllCheckbox();
  369. unregisterFileSelect();
  370. registerCheckbox();
  371. registerAllCheckbox();
  372. registerFileSelect();
  373. });
  374. //var list_view = document.querySelector('.list-view');
  375. //var grid_view = document.querySelector('.grid-view');
  376. //var list_view = document.querySelector('.vdAfKMb');
  377. //var grid_view = document.querySelector('.JKvHJMb');
  378. var list_view = document.querySelector('.' + wordMap['list-view']);
  379. var grid_view = document.querySelector('.' + wordMap['grid-view']);
  380. //console.log(list_view);
  381. observer.observe(list_view, options);
  382. observer.observe(grid_view, options);
  383. }
  384. //添加助手按钮
  385. function addButton() {
  386. //$('div.bar-search').css('width','18%');//修改搜索框的宽度,避免遮挡
  387. //$('div.OFaPaO').css('width','18%');
  388. $('div.' + wordMap['bar-search']).css('width', '18%');
  389. var $dropdownbutton = $('<span class="g-dropdown-button"></span>');
  390. var $dropdownbutton_a = $('<a class="g-button" href="javascript:void(0);"><span class="g-button-right"><em class="icon icon-download" title="百度网盘下载助手"></em><span class="text" style="width: auto;">下载助手</span></span></a>');
  391. var $dropdownbutton_span = $('<span class="menu" style="width:96px"></span>');
  392. var $directbutton = $('<span class="g-button-menu" style="display:block"></span>');
  393. var $directbutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
  394. var $directbutton_a = $('<a class="g-button" href="javascript:void(0);"><span class="g-button-right"><span class="text" style="width:auto">直接下载</span></span></a>');
  395. var $directbutton_menu = $('<span class="menu" style="width:120px;left:79px"></span>');
  396. var $directbutton_download_button = $('<a id="download-direct" class="g-button-menu" href="javascript:void(0);">下载</a>');
  397. var $directbutton_link_button = $('<a id="link-direct" class="g-button-menu" href="javascript:void(0);">显示链接</a>');
  398. var $directbutton_batchhttplink_button = $('<a id="batchhttplink-direct" class="g-button-menu" href="javascript:void(0);">批量链接(HTTP)</a>');
  399. var $directbutton_batchhttpslink_button = $('<a id="batchhttpslink-direct" class="g-button-menu" href="javascript:void(0);">批量链接(HTTPS)</a>');
  400. $directbutton_menu.append($directbutton_download_button).append($directbutton_link_button).append($directbutton_batchhttplink_button).append($directbutton_batchhttpslink_button);
  401. $directbutton.append($directbutton_span.append($directbutton_a).append($directbutton_menu));
  402. $directbutton.hover(function () {
  403. $directbutton_span.toggleClass('button-open');
  404. });
  405. $directbutton_download_button.click(downloadClick);
  406. $directbutton_link_button.click(linkClick);
  407. $directbutton_batchhttplink_button.click(batchClick);
  408. $directbutton_batchhttpslink_button.click(batchClick);
  409. var $apibutton = $('<span class="g-button-menu" style="display:block"></span>');
  410. var $apibutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
  411. var $apibutton_a = $('<a class="g-button" href="javascript:void(0);"><span class="g-button-right"><span class="text" style="width:auto">API下载</span></span></a>');
  412. var $apibutton_menu = $('<span class="menu" style="width:120px;left:77px"></span>');
  413. var $apibutton_download_button = $('<a id="download-api" class="g-button-menu" href="javascript:void(0);">下载</a>');
  414. var $apibutton_link_button = $('<a id="httplink-api" class="g-button-menu" href="javascript:void(0);">显示链接</a>');
  415. var $apibutton_batchhttplink_button = $('<a id="batchhttplink-api" class="g-button-menu" href="javascript:void(0);">批量链接(HTTP)</a>');
  416. var $apibutton_batchhttpslink_button = $('<a id="batchhttpslink-api" class="g-button-menu" href="javascript:void(0);">批量链接(HTTPS)</a>');
  417. $apibutton_menu.append($apibutton_download_button).append($apibutton_link_button).append($apibutton_batchhttplink_button).append($apibutton_batchhttpslink_button);
  418. $apibutton.append($apibutton_span.append($apibutton_a).append($apibutton_menu));
  419. $apibutton.hover(function () {
  420. $apibutton_span.toggleClass('button-open');
  421. });
  422. $apibutton_download_button.click(downloadClick);
  423. $apibutton_link_button.click(linkClick);
  424. $apibutton_batchhttplink_button.click(batchClick);
  425. $apibutton_batchhttpslink_button.click(batchClick);
  426. var $outerlinkbutton = $('<span class="g-button-menu" style="display:none"></span>'); //改为block显示外链下载
  427. var $outerlinkbutton_span = $('<span class="g-dropdown-button g-dropdown-button-second" menulevel="2"></span>');
  428. var $outerlinkbutton_a = $('<a class="g-button" href="javascript:void(0);"><span class="g-button-right"><span class="text" style="width:auto">外链下载</span></span></a>');
  429. var $outerlinkbutton_menu = $('<span class="menu" style="width:120px;left:79px"></span>');
  430. var $outerlinkbutton_download_button = $('<a id="download-outerlink" class="g-button-menu" href="javascript:void(0);">下载</a>');
  431. var $outerlinkbutton_link_button = $('<a id="link-outerlink" class="g-button-menu" href="javascript:void(0);">显示链接</a>');
  432. var $outerlinkbutton_batchlink_button = $('<a id="batchlink-outerlink" class="g-button-menu" href="javascript:void(0);">批量链接</a>');
  433. $outerlinkbutton_menu.append($outerlinkbutton_download_button).append($outerlinkbutton_link_button).append($outerlinkbutton_batchlink_button);
  434. $outerlinkbutton.append($outerlinkbutton_span.append($outerlinkbutton_a).append($outerlinkbutton_menu));
  435. $outerlinkbutton.hover(function () {
  436. $outerlinkbutton_span.toggleClass('button-open');
  437. });
  438. $outerlinkbutton_download_button.click(downloadClick);
  439. $outerlinkbutton_link_button.click(linkClick);
  440. $outerlinkbutton_batchlink_button.click(batchClick);
  441. //$dropdownbutton_span.append($directbutton).append($apibutton).append($outerlinkbutton);
  442. $dropdownbutton_span.append($apibutton).append($outerlinkbutton);
  443. $dropdownbutton.append($dropdownbutton_a).append($dropdownbutton_span);
  444. $dropdownbutton.hover(function () {
  445. $dropdownbutton.toggleClass('button-open');
  446. });
  447. $('div.' + wordMap['default-dom'] + ' div.' + wordMap['bar'] + ' div.' + wordMap['list-tools']).prepend($dropdownbutton);
  448. $('div.' + wordMap['list-tools']).prepend($dropdownbutton)
  449. }
  450. // 我的网盘 - 下载
  451. function downloadClick(event) {
  452. //console.log('downloadClick');
  453. slog('选中文件列表:', selectFileList);
  454. var id = event.target.id;
  455. var downloadLink;
  456. if (id == 'download-direct') {
  457. var downloadType;
  458. if (selectFileList.length === 0) {
  459. alert("获取选中文件失败,请刷新重试!");
  460. return;
  461. } else if (selectFileList.length == 1) {
  462. if (selectFileList[0].isdir === 1)
  463. downloadType = 'batch';
  464. else if (selectFileList[0].isdir === 0)
  465. downloadType = 'dlink';
  466. //downloadType = selectFileList[0].isdir==1?'batch':(selectFileList[0].isdir===0?'dlink':'batch');
  467. } else if (selectFileList.length > 1) {
  468. downloadType = 'batch';
  469. }
  470. fid_list = getFidList(selectFileList);
  471. var result = getDownloadLinkWithPanAPI(downloadType);
  472. if (result.errno === 0) {
  473. if (downloadType == 'dlink')
  474. downloadLink = result.dlink[0].dlink;
  475. else if (downloadType == 'batch') {
  476. downloadLink = result.dlink;
  477. if (selectFileList.length === 1)
  478. downloadLink = downloadLink + '&zipname=' + encodeURIComponent(selectFileList[0].filename) + '.zip';
  479. } else {
  480. alert("发生错误!");
  481. return;
  482. }
  483. } else if (result.errno == -1) {
  484. alert('文件不存在或已被百度和谐,无法下载!');
  485. return;
  486. } else if (result.errno == 112) {
  487. alert("页面过期,请刷新重试!");
  488. return;
  489. } else {
  490. alert("发生错误!");
  491. return;
  492. }
  493. } else {
  494. if (selectFileList.length === 0) {
  495. alert("获取选中文件失败,请刷新重试!");
  496. return;
  497. } else if (selectFileList.length > 1) {
  498. alert("该方法不支持多文件下载!");
  499. return;
  500. } else {
  501. if (selectFileList[0].isdir == 1) {
  502. alert("该方法不支持目录下载!");
  503. return;
  504. }
  505. }
  506. if (id == 'download-api') {
  507. downloadLink = getDownloadLinkWithRESTAPIBaidu(selectFileList[0].path);
  508. } else if (id == 'download-outerlink') {
  509. var result = getDownloadLinkWithClientAPI(selectFileList[0].path);
  510. if (result.errno == 0) {
  511. downloadLink = result.urls[0].url;
  512. } else if (result.errno == 1) {
  513. alert('文件不存在!');
  514. return;
  515. } else if (result.errno == 2) {
  516. alert('文件不存在或者已被百度和谐,无法下载!');
  517. return;
  518. } else {
  519. alert('发生错误!');
  520. return;
  521. }
  522. }
  523. }
  524. execDownload(downloadLink);
  525. }
  526. //我的网盘 - 显示链接
  527. function linkClick(event) {
  528. //console.log('linkClick');
  529. slog('选中文件列表:', selectFileList);
  530. var id = event.target.id;
  531. var linkList, tip;
  532. if (id.indexOf('direct') != -1) {
  533. var downloadType;
  534. var downloadLink;
  535. if (selectFileList.length === 0) {
  536. alert("获取选中文件失败,请刷新重试!");
  537. return;
  538. } else if (selectFileList.length == 1) {
  539. if (selectFileList[0].isdir === 1)
  540. downloadType = 'batch';
  541. else if (selectFileList[0].isdir === 0)
  542. downloadType = 'dlink';
  543. } else if (selectFileList.length > 1) {
  544. downloadType = 'batch';
  545. }
  546. fid_list = getFidList(selectFileList);
  547. var result = getDownloadLinkWithPanAPI(downloadType);
  548. if (result.errno === 0) {
  549. if (downloadType == 'dlink')
  550. downloadLink = result.dlink[0].dlink;
  551. else if (downloadType == 'batch') {
  552. slog(selectFileList);
  553. downloadLink = result.dlink;
  554. if (selectFileList.length === 1)
  555. downloadLink = downloadLink + '&zipname=' + encodeURIComponent(selectFileList[0].filename) + '.zip';
  556. } else {
  557. alert("发生错误!");
  558. return;
  559. }
  560. } else if (result.errno == -1) {
  561. alert('文件不存在或已被百度和谐,无法下载!');
  562. return;
  563. } else if (result.errno == 112) {
  564. alert("页面过期,请刷新重试!");
  565. return;
  566. } else {
  567. alert("发生错误!");
  568. return;
  569. }
  570. var httplink = downloadLink.replace(/^([A-Za-z]+):/, 'http:');
  571. //httplink = replaceDownloadLink(httplink);
  572. var httpslink = downloadLink.replace(/^([A-Za-z]+):/, 'https:');
  573. //httpslink = replaceDownloadLink(httpslink);
  574. var filename = '';
  575. $.each(selectFileList, function (index, element) {
  576. if (selectFileList.length == 1)
  577. filename = element.filename;
  578. else {
  579. if (index == 0)
  580. filename = element.filename;
  581. else
  582. filename = filename + ',' + element.filename;
  583. }
  584. });
  585. linkList = {
  586. filename: filename,
  587. urls: [
  588. {url: httplink, rank: 1},
  589. {url: httpslink, rank: 2}
  590. ]
  591. };
  592. tip = '显示模拟百度网盘网页获取的链接,可以使用右键迅雷或IDM下载,复制到下载工具需要传递cookie,多文件打包下载的链接可以直接复制使用';
  593. dialog.open({title: '下载链接', type: 'link', list: linkList, tip: tip});
  594. } else {
  595. if (selectFileList.length === 0) {
  596. alert("获取选中文件失败,请刷新重试!");
  597. return;
  598. } else if (selectFileList.length > 1) {
  599. alert("该方法不支持多文件下载!");
  600. return;
  601. } else {
  602. if (selectFileList[0].isdir == 1) {
  603. alert("该方法不支持目录下载!");
  604. return;
  605. }
  606. }
  607. if (id.indexOf('api') != -1) {
  608. var downloadLink = getDownloadLinkWithRESTAPIBaidu(selectFileList[0].path);
  609. var httplink = downloadLink.replace(/^([A-Za-z]+):/, 'http:');
  610. var httpslink = downloadLink.replace(/^([A-Za-z]+):/, 'https:');
  611. linkList = {
  612. filename: selectFileList[0].filename,
  613. urls: [
  614. {url: httplink, rank: 1},
  615. {url: httpslink, rank: 2}
  616. ]
  617. };
  618. httplink = httplink.replace('266719', '266719');
  619. httpslink = httpslink.replace('266719', '266719');
  620. linkList.urls.push({url: httplink, rank: 3});
  621. linkList.urls.push({url: httpslink, rank: 4});
  622. tip = '显示模拟APP获取的链接(使用百度云ID),可以使用右键迅雷或IDM下载,复制到下载工具需要传递cookie';
  623. dialog.open({title: '下载链接', type: 'link', list: linkList, tip: tip});
  624. } else if (id.indexOf('outerlink') != -1) {
  625. var result = getDownloadLinkWithClientAPI(selectFileList[0].path);
  626. if (result.errno == 0) {
  627. linkList = {
  628. filename: selectFileList[0].filename,
  629. urls: result.urls
  630. };
  631. } else if (result.errno == 1) {
  632. alert('文件不存在!');
  633. return;
  634. } else if (result.errno == 2) {
  635. alert('文件不存在或者已被百度和谐,无法下载!');
  636. return;
  637. } else {
  638. alert('发生错误!');
  639. return;
  640. }
  641. tip = '显示模拟百度网盘客户端获取的链接,可以直接复制到下载工具使用,不需要cookie';
  642. dialog.open({
  643. title: '下载链接',
  644. type: 'link',
  645. list: linkList,
  646. tip: tip,
  647. showcopy: true,
  648. showedit: true
  649. });
  650. }
  651. }
  652. //dialog.open({title:'下载链接',type:'link',list:linkList,tip:tip});
  653. }
  654. // 我的网盘 - 批量下载
  655. function batchClick(event) {
  656. //console.log('batchClick');
  657. slog('选中文件列表:', selectFileList);
  658. if (selectFileList.length === 0) {
  659. alert('获取选中文件失败,请刷新重试!');
  660. return;
  661. }
  662. var id = event.target.id;
  663. var linkType, tip;
  664. linkType = id.indexOf('https') == -1 ? (id.indexOf('http') == -1 ? location.protocol + ':' : 'http:') : 'https:';
  665. batchLinkList = [];
  666. batchLinkListAll = [];
  667. if (id.indexOf('direct') != -1) {
  668. batchLinkList = getDirectBatchLink(linkType);
  669. tip = '显示所有选中文件的直接下载链接,文件夹显示为打包下载的链接';
  670. if (batchLinkList.length === 0) {
  671. alert('没有链接可以显示,API链接不要全部选中文件夹!');
  672. return;
  673. }
  674. dialog.open({title: '批量链接', type: 'batch', list: batchLinkList, tip: tip, showcopy: true});
  675. } else if (id.indexOf('api') != -1) {
  676. batchLinkList = getAPIBatchLink(linkType);
  677. tip = '显示所有选中文件的API下载链接,不显示文件夹';
  678. if (batchLinkList.length === 0) {
  679. alert('没有链接可以显示,API链接不要全部选中文件夹!');
  680. return;
  681. }
  682. dialog.open({title: '批量链接', type: 'batch', list: batchLinkList, tip: tip, showcopy: true});
  683. } else if (id.indexOf('outerlink') != -1) {
  684. batchLinkListAll = getOuterlinkBatchLinkAll();
  685. batchLinkList = getOuterlinkBatchLinkFirst(batchLinkListAll);
  686. tip = '显示所有选中文件的外部下载链接,不显示文件夹';
  687. if (batchLinkList.length === 0) {
  688. alert('没有链接可以显示,API链接不要全部选中文件夹!');
  689. return;
  690. }
  691. dialog.open({
  692. title: '批量链接',
  693. type: 'batch',
  694. list: batchLinkList,
  695. tip: tip,
  696. showcopy: true,
  697. alllist: batchLinkListAll,
  698. showall: true
  699. });
  700. }
  701. //dialog.open({title:'批量链接',type:'batch',list:batchLinkList,tip:tip,showcopy:true});
  702. }
  703. function getDirectBatchLink(linkType) {
  704. var list = [];
  705. $.each(selectFileList, function (index, element) {
  706. var downloadType, downloadLink, result;
  707. if (element.isdir == 0)
  708. downloadType = 'dlink';
  709. else
  710. downloadType = 'batch';
  711. fid_list = getFidList([element]);
  712. result = getDownloadLinkWithPanAPI(downloadType);
  713. if (result.errno == 0) {
  714. if (downloadType == 'dlink')
  715. downloadLink = result.dlink[0].dlink;
  716. else if (downloadType == 'batch')
  717. downloadLink = result.dlink;
  718. downloadLink = downloadLink.replace(/^([A-Za-z]+):/, linkType);
  719. //downloadLink = replaceDownloadLink(downloadLink);
  720. } else {
  721. downloadLink = 'error';
  722. }
  723. list.push({filename: element.filename, downloadlink: downloadLink});
  724. });
  725. return list;
  726. }
  727. function getAPIBatchLink(linkType) {
  728. var list = [];
  729. $.each(selectFileList, function (index, element) {
  730. if (element.isdir == 1)
  731. return;
  732. var downloadLink;
  733. downloadLink = getDownloadLinkWithRESTAPIBaidu(element.path);
  734. downloadLink = downloadLink.replace(/^([A-Za-z]+):/, linkType);
  735. list.push({filename: element.filename, downloadlink: downloadLink});
  736. });
  737. return list;
  738. }
  739. function getOuterlinkBatchLinkAll() {
  740. var list = [];
  741. $.each(selectFileList, function (index, element) {
  742. var result;
  743. if (element.isdir == 1)
  744. return;
  745. result = getDownloadLinkWithClientAPI(element.path);
  746. if (result.errno == 0) {
  747. //downloadLink = result.urls[0].url;
  748. list.push({filename: element.filename, links: result.urls});
  749. } else {
  750. //downloadLink = 'error';
  751. list.push({filename: element.filename, links: [{rank: 1, url: 'error'}]});
  752. }
  753. //list.push({filename:element.filename,downloadlink:downloadLink});
  754. });
  755. return list;
  756. }
  757. function getOuterlinkBatchLinkFirst(list) {
  758. var result = [];
  759. $.each(list, function (index, element) {
  760. result.push({filename: element.filename, downloadlink: element.links[0].url});
  761. });
  762. return result;
  763. }
  764. function getSign() {
  765. var signFnc;
  766. try {
  767. signFnc = new Function("return " + yunData.sign2)();
  768. } catch (e) {
  769. throw new Error(e.message);
  770. }
  771. return base64Encode(signFnc(yunData.sign5, yunData.sign1));
  772. }
  773. //获取当前目录
  774. function getPath() {
  775. var hash = location.hash;
  776. var regx = new RegExp("path=([^&]*)(&|$)", 'i');
  777. var result = hash.match(regx);
  778. //console.log(result);
  779. return decodeURIComponent(result[1]);
  780. }
  781. //获取分类显示的类别,即地址栏中的type
  782. function getCategory() {
  783. var hash = location.hash;
  784. var regx = new RegExp("path=([^&]*)(&|$)", 'i');
  785. var result = hash.match(regx);
  786. return decodeURIComponent(result[1]);
  787. }
  788. function getSearchKey() {
  789. var hash = location.hash;
  790. var regx = new RegExp("key=([^&]*)(&|$)", 'i');
  791. var result = hash.match(regx);
  792. return decodeURIComponent(result[1]);
  793. }
  794. //获取当前页面(all或者category或search)
  795. function getCurrentPage() {
  796. var hash = location.hash;
  797. //console.log(hash.substring(hash.indexOf('#') + 2, hash.indexOf('?')));
  798. return hash.substring(hash.indexOf('#') + 2, hash.indexOf('?'));
  799. }
  800. //获取文件列表
  801. function getFileList() {
  802. var filelist = [];
  803. var listUrl = panAPIUrl + "list";
  804. var path = getPath();
  805. logid = getLogID();
  806. var params = {
  807. dir: path,
  808. bdstoken: bdstoken,
  809. logid: logid,
  810. order: 'size',
  811. desc: 0,
  812. clienttype: 0,
  813. showempty: 0,
  814. web: 1,
  815. channel: 'chunlei',
  816. appid: 266719
  817. };
  818. $.ajax({
  819. url: listUrl,
  820. async: false,
  821. method: 'GET',
  822. data: params,
  823. success: function (response) {
  824. filelist = 0 === response.errno ? response.list : [];
  825. }
  826. });
  827. return filelist;
  828. }
  829. //获取分类页面下的文件列表
  830. function getCategoryFileList() {
  831. var filelist = [];
  832. var listUrl = panAPIUrl + "categorylist";
  833. var category = getCategory();
  834. logid = getLogID();
  835. var params = {
  836. category: category,
  837. bdstoken: bdstoken,
  838. logid: logid,
  839. order: 'size',
  840. desc: 0,
  841. clienttype: 0,
  842. showempty: 0,
  843. web: 1,
  844. channel: 'chunlei',
  845. appid: 266719
  846. };
  847. $.ajax({
  848. url: listUrl,
  849. async: false,
  850. method: 'GET',
  851. data: params,
  852. success: function (response) {
  853. filelist = 0 === response.errno ? response.info : [];
  854. }
  855. });
  856. return filelist;
  857. }
  858. function getSearchFileList() {
  859. var filelist = [];
  860. var listUrl = panAPIUrl + 'search';
  861. logid = getLogID();
  862. searchKey = getSearchKey();
  863. var params = {
  864. recursion: 1,
  865. order: 'time',
  866. desc: 1,
  867. showempty: 0,
  868. web: 1,
  869. page: 1,
  870. num: 100,
  871. key: searchKey,
  872. channel: 'chunlei',
  873. app_id: 266719,
  874. bdstoken: bdstoken,
  875. logid: logid,
  876. clienttype: 0
  877. };
  878. $.ajax({
  879. url: listUrl,
  880. async: false,
  881. method: 'GET',
  882. data: params,
  883. success: function (response) {
  884. filelist = 0 === response.errno ? response.list : [];
  885. }
  886. });
  887. return filelist;
  888. }
  889. //生成下载时的fid_list参数
  890. function getFidList(list) {
  891. var fidlist = null;
  892. if (list.length === 0)
  893. return null;
  894. var fileidlist = [];
  895. $.each(list, function (index, element) {
  896. fileidlist.push(element.fs_id);
  897. });
  898. fidlist = '[' + fileidlist + ']';
  899. return fidlist;
  900. }
  901. function getTimestamp() {
  902. return yunData.timestamp;
  903. }
  904. function getBDStoken() {
  905. return yunData.MYBDSTOKEN;
  906. }
  907. //获取直接下载地址
  908. //这个地址不是直接下载地址,访问这个地址会返回302,response header中的location才是真实下载地址
  909. //暂时没有找到提取方法
  910. function getDownloadLinkWithPanAPI(type) {
  911. var downloadUrl = panAPIUrl + "download";
  912. var result;
  913. logid = getLogID();
  914. var params = {
  915. sign: sign,
  916. timestamp: timestamp,
  917. fidlist: fid_list,
  918. type: type,
  919. channel: 'chunlei',
  920. web: 1,
  921. app_id: 266719,
  922. bdstoken: bdstoken,
  923. logid: logid,
  924. clienttype: 0
  925. };
  926. $.ajax({
  927. url: downloadUrl,
  928. async: false,
  929. method: 'GET',
  930. data: params,
  931. success: function (response) {
  932. result = response;
  933. }
  934. });
  935. return result;
  936. }
  937. function getDownloadLinkWithRESTAPIBaidu(path) {
  938. var link = restAPIUrl + 'file?method=download&app_id=266719&path=' + encodeURIComponent(path);
  939. return link;
  940. }
  941. function getDownloadLinkWithRESTAPIES(path) {
  942. var link = restAPIUrl + 'file?method=download&app_id=266719&path=' + encodeURIComponent(path);
  943. return link;
  944. }
  945. function getDownloadLinkWithClientAPI(path) {
  946. var result;
  947. var url = clientAPIUrl + 'file?method=locatedownload&app_id=266719&ver=4.0&path=' + encodeURIComponent(path);
  948. $.ajax({
  949. url: url,
  950. method: 'POST',
  951. xhrFields: {
  952. withCredentials: true
  953. },
  954. async: false,
  955. success: function (response) {
  956. result = JSON.parse(response);
  957. },
  958. statusCode: {
  959. 404: function (response) {
  960. result = response;
  961. }
  962. }
  963. });
  964. if (result) {
  965. if (result.error_code == undefined) {
  966. if (result.urls == undefined) {
  967. result.errno = 2;
  968. } else {
  969. $.each(result.urls, function (index, element) {
  970. result.urls[index].url = element.url.replace('\\', '');
  971. });
  972. result.errno = 0;
  973. }
  974. } else if (result.error_code == 31066) {
  975. result.errno = 1;
  976. } else {
  977. result.errno = -1;
  978. }
  979. } else {
  980. result = {};
  981. result.errno = -1;
  982. }
  983. return result;
  984. }
  985. function execDownload(link) {
  986. slog("下载链接:" + link);
  987. $('#helperdownloadiframe').attr('src', link);
  988. }
  989. function createIframe() {
  990. var $div = $('<div class="helper-hide" style="padding:0;margin:0;display:block"></div>');
  991. var $iframe = $('<iframe src="javascript:void(0)" id="helperdownloadiframe" style="display:none"></iframe>');
  992. $div.append($iframe);
  993. $('body').append($div);
  994. }
  995. }
  996. //分享页面的下载助手
  997. function PanShareHelper() {
  998. var yunData, sign, timestamp, bdstoken, channel, clienttype, web, app_id, logid, encrypt, product, uk,
  999. primaryid, fid_list, extra, shareid;
  1000. var vcode;
  1001. var shareType, buttonTarget, currentPath, list_grid_status, observer, dialog, vcodeDialog;
  1002. var fileList = [], selectFileList = [];
  1003. var panAPIUrl = location.protocol + "//" + location.host + "/api/";
  1004. var shareListUrl = location.protocol + "//" + location.host + "/share/list";
  1005. this.init = function () {
  1006. yunData = unsafeWindow.yunData;
  1007. slog('yunData:', yunData);
  1008. if (yunData === undefined || yunData.FILEINFO == null) {
  1009. slog('页面未正常加载,或者百度已经更新!');
  1010. return;
  1011. }
  1012. initParams();
  1013. addButton();
  1014. dialog = new Dialog({addCopy: false});
  1015. vcodeDialog = new VCodeDialog(refreshVCode, confirmClick);
  1016. createIframe();
  1017. if (!isSingleShare()) {
  1018. registerEventListener();
  1019. createObserver();
  1020. }
  1021. slog('分享直接下载加载成功!');
  1022. };
  1023. function initParams() {
  1024. shareType = getShareType();
  1025. sign = yunData.SIGN;
  1026. timestamp = yunData.TIMESTAMP;
  1027. bdstoken = yunData.MYBDSTOKEN;
  1028. channel = 'chunlei';
  1029. clienttype = 0;
  1030. web = 1;
  1031. app_id = 266719;
  1032. logid = getLogID();
  1033. encrypt = 0;
  1034. product = 'share';
  1035. primaryid = yunData.SHARE_ID;
  1036. uk = yunData.SHARE_UK;
  1037. if (shareType == 'secret') {
  1038. extra = getExtra();
  1039. }
  1040. if (isSingleShare()) {
  1041. var obj = {};
  1042. if (yunData.CATEGORY == 2) {
  1043. obj.filename = yunData.FILENAME;
  1044. obj.path = yunData.PATH;
  1045. obj.fs_id = yunData.FS_ID;
  1046. obj.isdir = 0;
  1047. } else {
  1048. obj.filename = yunData.FILEINFO[0].server_filename,
  1049. obj.path = yunData.FILEINFO[0].path,
  1050. obj.fs_id = yunData.FILEINFO[0].fs_id,
  1051. obj.isdir = yunData.FILEINFO[0].isdir
  1052. }
  1053. selectFileList.push(obj);
  1054. } else {
  1055. shareid = yunData.SHARE_ID;
  1056. currentPath = getPath();
  1057. list_grid_status = getListGridStatus();
  1058. fileList = getFileList();
  1059. }
  1060. }
  1061. //判断分享类型(public或者secret)
  1062. function getShareType() {
  1063. return yunData.SHARE_PUBLIC === 1 ? 'public' : 'secret';
  1064. }
  1065. //判断是单个文件分享还是文件夹或者多文件分享
  1066. function isSingleShare() {
  1067. return yunData.getContext === undefined ? true : false;
  1068. }
  1069. //判断是否为自己的分享链接
  1070. function isSelfShare() {
  1071. return yunData.MYSELF == 1 ? true : false;
  1072. }
  1073. function getExtra() {
  1074. var seKey = decodeURIComponent(getCookie('BDCLND'));
  1075. return '{' + '"sekey":"' + seKey + '"' + "}";
  1076. }
  1077. //获取当前目录
  1078. function getPath() {
  1079. var hash = location.hash;
  1080. var regx = new RegExp("path=([^&]*)(&|$)", 'i');
  1081. var result = hash.match(regx);
  1082. return decodeURIComponent(result[1]);
  1083. }
  1084. //获取当前的视图模式
  1085. function getListGridStatus() {
  1086. var status = 'list';
  1087. if ($('.list-switched-on').length > 0) {
  1088. status = 'list';
  1089. } else if ($('.grid-switched-on').length > 0) {
  1090. status = 'grid';
  1091. }
  1092. return status;
  1093. }
  1094. //添加下载助手按钮
  1095. function addButton() {
  1096. if (isSingleShare()) {
  1097. $('div.slide-show-right').css('width', '500px');
  1098. $('div.frame-main').css('width', '96%');
  1099. $('div.share-file-viewer').css('width', '740px').css('margin-left', 'auto').css('margin-right', 'auto');
  1100. } else
  1101. $('div.slide-show-right').css('width', '500px');
  1102. var $dropdownbutton = $('<span class="g-dropdown-button"></span>');
  1103. var $dropdownbutton_a = $('<a class="g-button" data-button-id="b200" data-button-index="200" href="javascript:void(0);"></a>');
  1104. var $dropdownbutton_a_span = $('<span class="g-button-right"><em class="icon icon-download" title="百度网盘下载助手"></em><span class="text" style="width: auto;">下载助手</span></span>');
  1105. var $dropdownbutton_span = $('<span class="menu" style="width:auto;z-index:41"></span>');
  1106. var $downloadButton = $('<a data-menu-id="b-menu207" class="g-button-menu" href="javascript:void(0);">直接下载</a>');
  1107. var $linkButton = $('<a data-menu-id="b-menu208" class="g-button-menu" href="javascript:void(0);">显示链接</a>');
  1108. $dropdownbutton_span.append($downloadButton).append($linkButton);
  1109. $dropdownbutton_a.append($dropdownbutton_a_span);
  1110. $dropdownbutton.append($dropdownbutton_a).append($dropdownbutton_span);
  1111. $dropdownbutton.hover(function () {
  1112. $dropdownbutton.toggleClass('button-open');
  1113. });
  1114. $downloadButton.click(downloadButtonClick);
  1115. $linkButton.click(linkButtonClick);
  1116. $('div.module-share-top-bar div.bar div.x-button-box').append($dropdownbutton);
  1117. }
  1118. function createIframe() {
  1119. var $div = $('<div class="helper-hide" style="padding:0;margin:0;display:block"></div>');
  1120. var $iframe = $('<iframe src="javascript:void(0)" id="helperdownloadiframe" style="display:none"></iframe>');
  1121. $div.append($iframe);
  1122. $('body').append($div);
  1123. }
  1124. function registerEventListener() {
  1125. registerHashChange();
  1126. registerListGridStatus();
  1127. registerCheckbox();
  1128. registerAllCheckbox();
  1129. registerFileSelect();
  1130. }
  1131. //监视地址栏#标签变化
  1132. function registerHashChange() {
  1133. window.addEventListener('hashchange', function (e) {
  1134. list_grid_status = getListGridStatus();
  1135. if (currentPath == getPath()) {
  1136. } else {
  1137. currentPath = getPath();
  1138. refreshFileList();
  1139. refreshSelectFileList();
  1140. }
  1141. });
  1142. }
  1143. function refreshFileList() {
  1144. fileList = getFileList();
  1145. }
  1146. function refreshSelectFileList() {
  1147. selectFileList = [];
  1148. }
  1149. //监视视图变化
  1150. function registerListGridStatus() {
  1151. var $a_list = $('a[data-type=list]');
  1152. $a_list.click(function () {
  1153. list_grid_status = 'list';
  1154. });
  1155. var $a_grid = $('a[data-type=grid]');
  1156. $a_grid.click(function () {
  1157. list_grid_status = 'grid';
  1158. });
  1159. }
  1160. //监视文件选择框
  1161. function registerCheckbox() {
  1162. //var $checkbox = $('span.checkbox');
  1163. var $checkbox = $('span.' + wordMap['checkbox']);
  1164. if (list_grid_status == 'grid') {
  1165. $checkbox = $('.' + wordMap['chekbox-grid']);
  1166. }
  1167. $checkbox.each(function (index, element) {
  1168. $(element).bind('click', function (e) {
  1169. var $parent = $(this).parent();
  1170. var filename;
  1171. var isActive;
  1172. if (list_grid_status == 'list') {
  1173. filename = $('div.file-name div.text a', $parent).attr('title');
  1174. isActive = $(this).parents('dd').hasClass('JS-item-active')
  1175. } else if (list_grid_status == 'grid') {
  1176. filename = $('div.file-name a', $(this)).attr('title');
  1177. isActive = !$(this).hasClass('JS-item-active')
  1178. }
  1179. if (isActive) {
  1180. slog('取消选中文件:' + filename);
  1181. for (var i = 0; i < selectFileList.length; i++) {
  1182. if (selectFileList[i].filename == filename) {
  1183. selectFileList.splice(i, 1);
  1184. }
  1185. }
  1186. } else {
  1187. slog('选中文件: ' + filename);
  1188. $.each(fileList, function (index, element) {
  1189. if (element.server_filename == filename) {
  1190. var obj = {
  1191. filename: element.server_filename,
  1192. path: element.path,
  1193. fs_id: element.fs_id,
  1194. isdir: element.isdir
  1195. };
  1196. selectFileList.push(obj);
  1197. }
  1198. });
  1199. }
  1200. });
  1201. });
  1202. }
  1203. function unregisterCheckbox() {
  1204. //var $checkbox = $('span.checkbox');
  1205. var $checkbox = $('span.' + wordMap['checkbox']);
  1206. $checkbox.each(function (index, element) {
  1207. $(element).unbind('click');
  1208. });
  1209. }
  1210. //监视全选框
  1211. function registerAllCheckbox() {
  1212. //var $checkbox = $('div.col-item.check');
  1213. var $checkbox = $('div.' + wordMap['col-item'] + '.' + wordMap['check']);
  1214. $checkbox.each(function (index, element) {
  1215. $(element).bind('click', function (e) {
  1216. var $parent = $(this).parent();
  1217. //if($parent.hasClass('checked')){
  1218. if ($parent.hasClass(wordMap['checked'])) {
  1219. slog('取消全选');
  1220. selectFileList = [];
  1221. } else {
  1222. slog('全部选中');
  1223. selectFileList = [];
  1224. $.each(fileList, function (index, element) {
  1225. var obj = {
  1226. filename: element.server_filename,
  1227. path: element.path,
  1228. fs_id: element.fs_id,
  1229. isdir: element.isdir
  1230. };
  1231. selectFileList.push(obj);
  1232. });
  1233. }
  1234. });
  1235. });
  1236. }
  1237. function unregisterAllCheckbox() {
  1238. //var $checkbox = $('div.col-item.check');
  1239. var $checkbox = $('div.' + wordMap['col-item'] + '.' + wordMap['check']);
  1240. $checkbox.each(function (index, element) {
  1241. $(element).unbind('click');
  1242. });
  1243. }
  1244. //监视单个文件选中
  1245. function registerFileSelect() {
  1246. //console.log('registerFileSelect');
  1247. //var $dd = $('div.list-view dd');
  1248. var $dd = $('div.' + wordMap['list-view'] + ' dd');
  1249. $dd.each(function (index, element) {
  1250. $(element).bind('click', function (e) {
  1251. var nodeName = e.target.nodeName.toLowerCase();
  1252. if (nodeName != 'span' && nodeName != 'a' && nodeName != 'em') {
  1253. selectFileList = [];
  1254. var filename = $('div.file-name div.text a', $(this)).attr('title');
  1255. slog('选中文件:' + filename);
  1256. $.each(fileList, function (index, element) {
  1257. if (element.server_filename == filename) {
  1258. var obj = {
  1259. filename: element.server_filename,
  1260. path: element.path,
  1261. fs_id: element.fs_id,
  1262. isdir: element.isdir
  1263. };
  1264. selectFileList.push(obj);
  1265. }
  1266. });
  1267. }
  1268. });
  1269. });
  1270. }
  1271. function unregisterFileSelect() {
  1272. //var $dd = $('div.list-view dd');
  1273. var $dd = $('div.' + wordMap['list-view'] + ' dd');
  1274. $dd.each(function (index, element) {
  1275. $(element).unbind('click');
  1276. });
  1277. }
  1278. //监视文件列表显示变化
  1279. function createObserver() {
  1280. var MutationObserver = window.MutationObserver;
  1281. var options = {
  1282. 'childList': true
  1283. };
  1284. observer = new MutationObserver(function (mutations) {
  1285. unregisterCheckbox();
  1286. unregisterAllCheckbox();
  1287. unregisterFileSelect();
  1288. registerCheckbox();
  1289. registerAllCheckbox();
  1290. registerFileSelect();
  1291. });
  1292. //var list_view = document.querySelector('.list-view');
  1293. //var grid_view = document.querySelector('.grid-view');
  1294. var list_view = document.querySelector('.' + wordMap['list-view']);
  1295. var grid_view = document.querySelector('.' + wordMap['grid-view']);
  1296. observer.observe(list_view, options);
  1297. observer.observe(grid_view, options);
  1298. }
  1299. //获取文件信息列表
  1300. function getFileList() {
  1301. var result = [];
  1302. if (getPath() == '/') {
  1303. result = yunData.FILEINFO;
  1304. } else {
  1305. logid = getLogID();
  1306. var params = {
  1307. uk: uk,
  1308. shareid: shareid,
  1309. order: 'other',
  1310. desc: 1,
  1311. showempty: 0,
  1312. web: web,
  1313. dir: getPath(),
  1314. t: Math.random(),
  1315. bdstoken: bdstoken,
  1316. channel: channel,
  1317. clienttype: clienttype,
  1318. app_id: app_id,
  1319. logid: logid
  1320. };
  1321. $.ajax({
  1322. url: shareListUrl,
  1323. method: 'GET',
  1324. async: false,
  1325. data: params,
  1326. success: function (response) {
  1327. if (response.errno === 0) {
  1328. result = response.list;
  1329. }
  1330. }
  1331. });
  1332. }
  1333. return result;
  1334. }
  1335. function downloadButtonClick() {
  1336. //console.log('点击直接下载按钮');
  1337. slog('选中文件列表:', selectFileList);
  1338. if (selectFileList.length === 0) {
  1339. alert('获取文件ID失败,请重试');
  1340. return;
  1341. }
  1342. buttonTarget = 'download';
  1343. var downloadLink = getDownloadLink();
  1344. //console.log(downloadLink);
  1345. if (downloadLink.errno == -20) {
  1346. vcode = getVCode();
  1347. if (vcode.errno !== 0) {
  1348. alert('获取验证码失败!');
  1349. return;
  1350. }
  1351. vcodeDialog.open(vcode);
  1352. } else if (downloadLink.errno == 112) {
  1353. alert('页面过期,请刷新重试');
  1354. } else if (downloadLink.errno === 0) {
  1355. var link;
  1356. if (selectFileList.length == 1 && selectFileList[0].isdir === 0)
  1357. link = downloadLink.list[0].dlink;
  1358. else
  1359. link = downloadLink.dlink;
  1360. //link = link.replace("https://d.pcs.baidu.com","http://c.pcs.baidu.com");
  1361. execDownload(link);
  1362. } else {
  1363. alert('获取下载链接失败!');
  1364. }
  1365. }
  1366. //获取验证码
  1367. function getVCode() {
  1368. var url = panAPIUrl + 'getvcode';
  1369. var result;
  1370. logid = getLogID();
  1371. var params = {
  1372. prod: 'pan',
  1373. t: Math.random(),
  1374. bdstoken: bdstoken,
  1375. channel: channel,
  1376. clienttype: clienttype,
  1377. web: web,
  1378. app_id: app_id,
  1379. logid: logid
  1380. };
  1381. $.ajax({
  1382. url: url,
  1383. method: 'GET',
  1384. async: false,
  1385. data: params,
  1386. success: function (response) {
  1387. result = response;
  1388. }
  1389. });
  1390. return result;
  1391. }
  1392. //刷新验证码
  1393. function refreshVCode() {
  1394. vcode = getVCode();
  1395. $('#dialog-img').attr('src', vcode.img);
  1396. }
  1397. //验证码确认提交
  1398. function confirmClick() {
  1399. var val = $('#dialog-input').val();
  1400. if (val.length === 0) {
  1401. $('#dialog-err').text('请输入验证码');
  1402. return;
  1403. } else if (val.length < 4) {
  1404. $('#dialog-err').text('验证码输入错误,请重新输入');
  1405. return;
  1406. }
  1407. var result = getDownloadLinkWithVCode(val);
  1408. //console.log(result);
  1409. if (result.errno == -20) {
  1410. vcodeDialog.close();
  1411. $('#dialog-err').text('验证码输入错误,请重新输入');
  1412. refreshVCode();
  1413. if (!vcode || vcode.errno !== 0) {
  1414. alert('获取验证码失败!');
  1415. return;
  1416. }
  1417. vcodeDialog.open();
  1418. } else if (result.errno === 0) {
  1419. vcodeDialog.close();
  1420. var link;
  1421. if (selectFileList.length == 1 && selectFileList[0].isdir === 0)
  1422. link = result.list[0].dlink;
  1423. else
  1424. link = result.dlink;
  1425. if (buttonTarget == 'download') {
  1426. execDownload(link);
  1427. } else if (buttonTarget == 'link') {
  1428. var filename = '';
  1429. $.each(selectFileList, function (index, element) {
  1430. if (selectFileList.length == 1)
  1431. filename = element.filename;
  1432. else {
  1433. if (index == 0)
  1434. filename = element.filename;
  1435. else
  1436. filename = filename + ',' + element.filename;
  1437. }
  1438. });
  1439. //link = replaceDownloadLink(link);
  1440. var linkList = {
  1441. filename: filename,
  1442. urls: [
  1443. {url: link, rank: 1}
  1444. ]
  1445. };
  1446. var tip = "显示获取的链接,可以使用右键迅雷或IDM下载,复制无用,需要传递cookie";
  1447. dialog.open({title: '下载链接', type: 'link', list: linkList, tip: tip});
  1448. }
  1449. } else {
  1450. alert('发生错误!');
  1451. }
  1452. }
  1453. //生成下载用的fid_list参数
  1454. function getFidList() {
  1455. var fidlist = [];
  1456. $.each(selectFileList, function (index, element) {
  1457. fidlist.push(element.fs_id);
  1458. });
  1459. return '[' + fidlist + ']';
  1460. }
  1461. function linkButtonClick() {
  1462. slog('选中文件列表:', selectFileList);
  1463. if (selectFileList.length === 0) {
  1464. alert('没有选中文件,请重试');
  1465. return;
  1466. }
  1467. buttonTarget = 'link';
  1468. var downloadLink = getDownloadLink();
  1469. if (downloadLink.errno == -20) {
  1470. vcode = getVCode();
  1471. if (!vcode || vcode.errno !== 0) {
  1472. alert('获取验证码失败!');
  1473. return;
  1474. }
  1475. vcodeDialog.open(vcode);
  1476. } else if (downloadLink.errno == 112) {
  1477. alert('页面过期,请刷新重试');
  1478. } else if (downloadLink.errno === 0) {
  1479. var link;
  1480. if (selectFileList.length == 1 && selectFileList[0].isdir === 0)
  1481. link = downloadLink.list[0].dlink;
  1482. else
  1483. link = downloadLink.dlink;
  1484. if (selectFileList.length == 1)
  1485. $('#dialog-downloadlink').attr('href', link).text(link);
  1486. else
  1487. $('#dialog-downloadlink').attr('href', link).text(link);
  1488. var filename = '';
  1489. $.each(selectFileList, function (index, element) {
  1490. if (selectFileList.length == 1)
  1491. filename = element.filename;
  1492. else {
  1493. if (index == 0)
  1494. filename = element.filename;
  1495. else
  1496. filename = filename + ',' + element.filename;
  1497. }
  1498. });
  1499. //link = replaceDownloadLink(link);
  1500. var linkList = {
  1501. filename: filename,
  1502. urls: [
  1503. {url: link, rank: 1}
  1504. ]
  1505. };
  1506. var tip = "显示获取的链接,可以使用右键迅雷或IDM下载,复制无用,需要传递cookie";
  1507. dialog.open({title: '下载链接', type: 'link', list: linkList, tip: tip});
  1508. } else {
  1509. alert('获取下载链接失败!');
  1510. }
  1511. }
  1512. //获取下载链接
  1513. function getDownloadLink() {
  1514. if (bdstoken === null) {
  1515. alert('脚本作者提示 : 百度升级, 请先登录百度云盘才能正常获取');
  1516. return '';
  1517. } else {
  1518. var result;
  1519. if (isSingleShare) {
  1520. fid_list = getFidList();
  1521. logid = getLogID();
  1522. var url = panAPIUrl + 'sharedownload?sign=' + sign + '&timestamp=' + timestamp + '&bdstoken=' + bdstoken + '&channel=' + channel + '&clienttype=' + clienttype + '&web=' + web + '&app_id=' + app_id + '&logid=' + logid;
  1523. var params = {
  1524. encrypt: encrypt,
  1525. product: product,
  1526. uk: uk,
  1527. primaryid: primaryid,
  1528. fid_list: fid_list
  1529. };
  1530. if (shareType == 'secret') {
  1531. params.extra = extra;
  1532. }
  1533. if (selectFileList[0].isdir == 1 || selectFileList.length > 1) {
  1534. params.type = 'batch';
  1535. }
  1536. $.ajax({
  1537. url: url,
  1538. method: 'POST',
  1539. async: false,
  1540. data: params,
  1541. success: function (response) {
  1542. result = response;
  1543. }
  1544. });
  1545. }
  1546. return result;
  1547. }
  1548. }
  1549. //有验证码输入时获取下载链接
  1550. function getDownloadLinkWithVCode(vcodeInput) {
  1551. var result;
  1552. if (isSingleShare) {
  1553. fid_list = getFidList();
  1554. var url = panAPIUrl + 'sharedownload?sign=' + sign + '&timestamp=' + timestamp + '&bdstoken=' + bdstoken + '&channel=' + channel + '&clienttype=' + clienttype + '&web=' + web + '&app_id=' + app_id + '&logid=' + logid;
  1555. var params = {
  1556. encrypt: encrypt,
  1557. product: product,
  1558. vcode_input: vcodeInput,
  1559. vcode_str: vcode.vcode,
  1560. uk: uk,
  1561. primaryid: primaryid,
  1562. fid_list: fid_list
  1563. };
  1564. if (shareType == 'secret') {
  1565. params.extra = extra;
  1566. }
  1567. if (selectFileList[0].isdir == 1 || selectFileList.length > 1) {
  1568. params.type = 'batch';
  1569. }
  1570. $.ajax({
  1571. url: url,
  1572. method: 'POST',
  1573. async: false,
  1574. data: params,
  1575. success: function (response) {
  1576. result = response;
  1577. }
  1578. });
  1579. }
  1580. return result;
  1581. }
  1582. function execDownload(link) {
  1583. slog('下载链接:' + link);
  1584. $('#helperdownloadiframe').attr('src', link);
  1585. }
  1586. }
  1587. function base64Encode(t) {
  1588. var a, r, e, n, i, s, o = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  1589. for (e = t.length, r = 0, a = ""; e > r;) {
  1590. if (n = 255 & t.charCodeAt(r++), r == e) {
  1591. a += o.charAt(n >> 2);
  1592. a += o.charAt((3 & n) << 4);
  1593. a += "==";
  1594. break;
  1595. }
  1596. if (i = t.charCodeAt(r++), r == e) {
  1597. a += o.charAt(n >> 2);
  1598. a += o.charAt((3 & n) << 4 | (240 & i) >> 4);
  1599. a += o.charAt((15 & i) << 2);
  1600. a += "=";
  1601. break;
  1602. }
  1603. s = t.charCodeAt(r++);
  1604. a += o.charAt(n >> 2);
  1605. a += o.charAt((3 & n) << 4 | (240 & i) >> 4);
  1606. a += o.charAt((15 & i) << 2 | (192 & s) >> 6);
  1607. a += o.charAt(63 & s);
  1608. }
  1609. return a;
  1610. }
  1611. function detectPage() {
  1612. var regx = /[\/].+[\/]/g;
  1613. var page = location.pathname.match(regx);
  1614. return page[0].replace(/\//g, '');
  1615. }
  1616. function getCookie(e) {
  1617. var o, t;
  1618. var n = document, c = decodeURI;
  1619. return n.cookie.length > 0 && (o = n.cookie.indexOf(e + "="), -1 != o) ? (o = o + e.length + 1, t = n.cookie.indexOf(";", o), -1 == t && (t = n.cookie.length), c(n.cookie.substring(o, t))) : "";
  1620. }
  1621. function getLogID() {
  1622. var name = "BAIDUID";
  1623. var u = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#¥%……&";
  1624. var d = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
  1625. var f = String.fromCharCode;
  1626. function l(e) {
  1627. if (e.length < 2) {
  1628. var n = e.charCodeAt(0);
  1629. return 128 > n ? e : 2048 > n ? f(192 | n >>> 6) + f(128 | 63 & n) : f(224 | n >>> 12 & 15) + f(128 | n >>> 6 & 63) + f(128 | 63 & n);
  1630. }
  1631. var n = 65536 + 1024 * (e.charCodeAt(0) - 55296) + (e.charCodeAt(1) - 56320);
  1632. return f(240 | n >>> 18 & 7) + f(128 | n >>> 12 & 63) + f(128 | n >>> 6 & 63) + f(128 | 63 & n);
  1633. }
  1634. function g(e) {
  1635. return (e + "" + Math.random()).replace(d, l);
  1636. }
  1637. function m(e) {
  1638. var n = [0, 2, 1][e.length % 3];
  1639. var t = e.charCodeAt(0) << 16 | (e.length > 1 ? e.charCodeAt(1) : 0) << 8 | (e.length > 2 ? e.charCodeAt(2) : 0);
  1640. var o = [u.charAt(t >>> 18), u.charAt(t >>> 12 & 63), n >= 2 ? "=" : u.charAt(t >>> 6 & 63), n >= 1 ? "=" : u.charAt(63 & t)];
  1641. return o.join("");
  1642. }
  1643. function h(e) {
  1644. return e.replace(/[\s\S]{1,3}/g, m);
  1645. }
  1646. function p() {
  1647. return h(g((new Date()).getTime()));
  1648. }
  1649. function w(e, n) {
  1650. return n ? p(String(e)).replace(/[+\/]/g, function (e) {
  1651. return "+" == e ? "-" : "_";
  1652. }).replace(/=/g, "") : p(String(e));
  1653. }
  1654. return w(getCookie(name));
  1655. }
  1656. function Dialog() {
  1657. var linkList = [];
  1658. var showParams;
  1659. var dialog, shadow;
  1660. function createDialog() {
  1661. var screenWidth = document.body.clientWidth;
  1662. var dialogLeft = screenWidth > 800 ? (screenWidth - 800) / 2 : 0;
  1663. var $dialog_div = $('<div class="dialog" style="width: 800px; top: 0px; bottom: auto; left: ' + dialogLeft + 'px; right: auto; display: hidden; visibility: visible; z-index: 52;"></div>');
  1664. var $dialog_header = $('<div class="dialog-header"><h3><span class="dialog-title" style="display:inline-block;width:740px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis"></span></h3></div>');
  1665. var $dialog_control = $('<div class="dialog-control"><span class="dialog-icon dialog-close">×</span></div>');
  1666. var $dialog_body = $('<div class="dialog-body" style="max-height:450px;overflow-y:auto;padding:0 20px;"></div>');
  1667. var $dialog_tip = $('<div class="dialog-tip" style="padding-left:20px;background-color:#faf2d3;border-top: 1px solid #c4dbfe;"><p></p></div>');
  1668. $dialog_div.append($dialog_header.append($dialog_control)).append($dialog_body);
  1669. //var $dialog_textarea = $('<textarea class="dialog-textarea" style="display:none;width"></textarea>');
  1670. var $dialog_radio_div = $('<div class="dialog-radio" style="display:none;width:760px;padding-left:20px;padding-right:20px"></div>');
  1671. var $dialog_radio_multi = $('<input type="radio" name="showmode" checked="checked" value="multi"><span>多行</span>');
  1672. var $dialog_radio_single = $('<input type="radio" name="showmode" value="single"><span>单行</span>');
  1673. $dialog_radio_div.append($dialog_radio_multi).append($dialog_radio_single);
  1674. $dialog_div.append($dialog_radio_div);
  1675. $('input[type=radio][name=showmode]', $dialog_radio_div).change(function () {
  1676. var value = this.value;
  1677. var $textarea = $('div.dialog-body textarea[name=dialog-textarea]', dialog);
  1678. var content = $textarea.val();
  1679. if (value == 'multi') {
  1680. content = content.replace(/\s+/g, '\n');
  1681. $textarea.css('height', '300px');
  1682. } else if (value == 'single') {
  1683. content = content.replace(/\n+/g, ' ');
  1684. $textarea.css('height', '');
  1685. }
  1686. $textarea.val(content);
  1687. });
  1688. var $dialog_button = $('<div class="dialog-button" style="display:none"></div>');
  1689. var $dialog_button_div = $('<div style="display:table;margin:auto"></div>');
  1690. var $dialog_copy_button = $('<button id="dialog-copy-button" style="display:none;width: 100px; margin: 5px 0 10px 0; cursor: pointer; background: #3b8cff; border: none; height: 30px; color: #fff; border-radius: 3px;">复制</button>');
  1691. var $dialog_edit_button = $('<button id="dialog-edit-button" style="display:none">编辑</button>');
  1692. var $dialog_exit_button = $('<button id="dialog-exit-button" style="display:none">退出</button>');
  1693. $dialog_button_div.append($dialog_copy_button).append($dialog_edit_button).append($dialog_exit_button);
  1694. $dialog_button.append($dialog_button_div);
  1695. $dialog_div.append($dialog_button);
  1696. $dialog_copy_button.click(function () {
  1697. var content = '';
  1698. if (showParams.type == 'batch') {
  1699. $.each(linkList, function (index, element) {
  1700. if (element.downloadlink == 'error')
  1701. return;
  1702. if (index == linkList.length - 1)
  1703. content = content + element.downloadlink;
  1704. else
  1705. content = content + element.downloadlink + '\n';
  1706. });
  1707. } else if (showParams.type == 'link') {
  1708. $.each(linkList, function (index, element) {
  1709. if (element.url == 'error')
  1710. return;
  1711. if (index == linkList.length - 1)
  1712. content = content + element.url;
  1713. else
  1714. content = content + element.url + '\n';
  1715. });
  1716. }
  1717. GM_setClipboard(content, 'text');
  1718. alert('已将链接复制到剪贴板!');
  1719. });
  1720. $dialog_edit_button.click(function () {
  1721. var $dialog_textarea = $('div.dialog-body textarea[name=dialog-textarea]', dialog);
  1722. var $dialog_item = $('div.dialog-body div', dialog);
  1723. $dialog_item.hide();
  1724. $dialog_copy_button.hide();
  1725. $dialog_edit_button.hide();
  1726. $dialog_textarea.show();
  1727. $dialog_radio_div.show();
  1728. $dialog_exit_button.show();
  1729. });
  1730. $dialog_exit_button.click(function () {
  1731. var $dialog_textarea = $('div.dialog-body textarea[name=dialog-textarea]', dialog);
  1732. var $dialog_item = $('div.dialog-body div', dialog);
  1733. $dialog_textarea.hide();
  1734. $dialog_radio_div.hide();
  1735. $dialog_item.show();
  1736. $dialog_exit_button.hide();
  1737. $dialog_copy_button.show();
  1738. $dialog_edit_button.show();
  1739. });
  1740. $dialog_div.append($dialog_tip);
  1741. $('body').append($dialog_div);
  1742. $dialog_div.dialogDrag();
  1743. $dialog_control.click(dialogControl);
  1744. return $dialog_div;
  1745. }
  1746. function createShadow() {
  1747. var $shadow = $('<div class="dialog-shadow" style="position: fixed; left: 0px; top: 0px; z-index: 50; background: rgb(0, 0, 0) none repeat scroll 0% 0%; opacity: 0.5; width: 100%; height: 100%; display: none;"></div>');
  1748. $('body').append($shadow);
  1749. return $shadow;
  1750. }
  1751. this.open = function (params) {
  1752. showParams = params;
  1753. linkList = [];
  1754. if (params.type == 'link') {
  1755. linkList = params.list.urls;
  1756. $('div.dialog-header h3 span.dialog-title', dialog).text(params.title + ":" + params.list.filename);
  1757. $.each(params.list.urls, function (index, element) {
  1758. var $div = $('<div><div style="width:30px;float:left">' + element.rank + ':</div><div style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis"><a href="' + element.url + '">' + element.url + '</a></div></div>');
  1759. $('div.dialog-body', dialog).append($div);
  1760. });
  1761. } else if (params.type == 'batch') {
  1762. linkList = params.list;
  1763. $('div.dialog-header h3 span.dialog-title', dialog).text(params.title);
  1764. if (params.showall) {
  1765. $.each(params.list, function (index, element) {
  1766. var $item_div = $('<div class="item-container" style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap"></div>');
  1767. var $item_name = $('<div style="width:100px;float:left;overflow:hidden;text-overflow:ellipsis" title="' + element.filename + '">' + element.filename + '</div>');
  1768. var $item_sep = $('<div style="width:12px;float:left"><span>:</span></div>');
  1769. var $item_link_div = $('<div class="item-link" style="float:left;width:618px;"></div>');
  1770. var $item_first = $('<div class="item-first" style="overflow:hidden;text-overflow:ellipsis"><a href="' + element.downloadlink + '">' + element.downloadlink + '</a></div>');
  1771. $item_link_div.append($item_first);
  1772. $.each(params.alllist[index].links, function (n, item) {
  1773. if (element.downloadlink == item.url)
  1774. return;
  1775. var $item = $('<div class="item-ex" style="display:none;overflow:hidden;text-overflow:ellipsis"><a href="' + item.url + '">' + item.url + '</a></div>');
  1776. $item_link_div.append($item);
  1777. });
  1778. var $item_ex = $('<div style="width:15px;float:left;cursor:pointer;text-align:center;font-size:16px"><span>+</span></div>');
  1779. $item_div.append($item_name).append($item_sep).append($item_link_div).append($item_ex);
  1780. $item_ex.click(function () {
  1781. var $parent = $(this).parent();
  1782. $parent.toggleClass('showall');
  1783. if ($parent.hasClass('showall')) {
  1784. $(this).text('-');
  1785. $('div.item-link div.item-ex', $parent).show();
  1786. } else {
  1787. $(this).text('+');
  1788. $('div.item-link div.item-ex', $parent).hide();
  1789. }
  1790. });
  1791. $('div.dialog-body', dialog).append($item_div);
  1792. });
  1793. } else {
  1794. $.each(params.list, function (index, element) {
  1795. var $div = $('<div style="overflow:hidden;text-overflow:ellipsis;white-space:nowrap"><div style="width:100px;float:left;overflow:hidden;text-overflow:ellipsis" title="' + element.filename + '">' + element.filename + '</div><span>:</span><a href="' + element.downloadlink + '">' + element.downloadlink + '</a></div>');
  1796. $('div.dialog-body', dialog).append($div);
  1797. });
  1798. }
  1799. }
  1800. if (params.tip) {
  1801. $('div.dialog-tip p', dialog).text(params.tip);
  1802. }
  1803. if (params.showcopy) {
  1804. $('div.dialog-button', dialog).show();
  1805. $('div.dialog-button button#dialog-copy-button', dialog).show();
  1806. }
  1807. if (params.showedit) {
  1808. $('div.dialog-button', dialog).show();
  1809. $('div.dialog-button button#dialog-edit-button', dialog).show();
  1810. var $dialog_textarea = $('<textarea name="dialog-textarea" style="display:none;resize:none;width:758px;height:300px;white-space:pre;word-wrap:normal;overflow-x:scroll"></textarea>');
  1811. var content = '';
  1812. if (showParams.type == 'batch') {
  1813. $.each(linkList, function (index, element) {
  1814. if (element.downloadlink == 'error')
  1815. return;
  1816. if (index == linkList.length - 1)
  1817. content = content + element.downloadlink;
  1818. else
  1819. content = content + element.downloadlink + '\n';
  1820. });
  1821. } else if (showParams.type == 'link') {
  1822. $.each(linkList, function (index, element) {
  1823. if (element.url == 'error')
  1824. return;
  1825. if (index == linkList.length - 1)
  1826. content = content + element.url;
  1827. else
  1828. content = content + element.url + '\n';
  1829. });
  1830. }
  1831. $dialog_textarea.val(content);
  1832. $('div.dialog-body', dialog).append($dialog_textarea);
  1833. }
  1834. shadow.show();
  1835. dialog.show();
  1836. };
  1837. this.close = function () {
  1838. dialogControl();
  1839. };
  1840. function dialogControl() {
  1841. $('div.dialog-body', dialog).children().remove();
  1842. $('div.dialog-header h3 span.dialog-title', dialog).text('');
  1843. $('div.dialog-tip p', dialog).text('');
  1844. $('div.dialog-button', dialog).hide();
  1845. $('div.dialog-radio input[type=radio][name=showmode][value=multi]', dialog).prop('checked', true);
  1846. $('div.dialog-radio', dialog).hide();
  1847. $('div.dialog-button button#dialog-copy-button', dialog).hide();
  1848. $('div.dialog-button button#dialog-edit-button', dialog).hide();
  1849. $('div.dialog-button button#dialog-exit-button', dialog).hide();
  1850. dialog.hide();
  1851. shadow.hide();
  1852. }
  1853. dialog = createDialog();
  1854. shadow = createShadow();
  1855. }
  1856. function VCodeDialog(refreshVCode, confirmClick) {
  1857. var dialog, shadow;
  1858. function createDialog() {
  1859. var screenWidth = document.body.clientWidth;
  1860. var dialogLeft = screenWidth > 520 ? (screenWidth - 520) / 2 : 0;
  1861. var $dialog_div = $('<div class="dialog" id="dialog-vcode" style="width:520px;top:0px;bottom:auto;left:' + dialogLeft + 'px;right:auto;display:none;visibility:visible;z-index:52"></div>');
  1862. var $dialog_header = $('<div class="dialog-header"><h3><span class="dialog-header-title"><em class="select-text">提示</em></span></h3></div>');
  1863. var $dialog_control = $('<div class="dialog-control"><span class="dialog-icon dialog-close icon icon-close"><span class="sicon">x</span></span></div>');
  1864. var $dialog_body = $('<div class="dialog-body"></div>');
  1865. var $dialog_body_div = $('<div style="text-align:center;padding:22px"></div>');
  1866. var $dialog_body_download_verify = $('<div class="download-verify" style="margin-top:10px;padding:0 28px;text-align:left;font-size:12px;"></div>');
  1867. var $dialog_verify_body = $('<div class="verify-body">请输入验证码:</div>');
  1868. var $dialog_input = $('<input id="dialog-input" type="text" style="padding:3px;width:85px;height:23px;border:1px solid #c6c6c6;background-color:white;vertical-align:middle;" class="input-code" maxlength="4">');
  1869. var $dialog_img = $('<img id="dialog-img" class="img-code" style="margin-left:10px;vertical-align:middle;" alt="点击换一张" src="" width="100" height="30">');
  1870. var $dialog_refresh = $('<a href="javascript:void(0)" style="text-decoration:underline;" class="underline">换一张</a>');
  1871. var $dialog_err = $('<div id="dialog-err" style="padding-left:84px;height:18px;color:#d80000" class="verify-error"></div>');
  1872. var $dialog_footer = $('<div class="dialog-footer g-clearfix"></div>');
  1873. var $dialog_confirm_button = $('<a class="g-button g-button-blue" data-button-id="" data-button-index href="javascript:void(0)" style="padding-left:36px"><span class="g-button-right" style="padding-right:36px;"><span class="text" style="width:auto;">确定</span></span></a>');
  1874. var $dialog_cancel_button = $('<a class="g-button" data-button-id="" data-button-index href="javascript:void(0);" style="padding-left: 36px;"><span class="g-button-right" style="padding-right: 36px;"><span class="text" style="width: auto;">取消</span></span></a>');
  1875. $dialog_header.append($dialog_control);
  1876. $dialog_verify_body.append($dialog_input).append($dialog_img).append($dialog_refresh);
  1877. $dialog_body_download_verify.append($dialog_verify_body).append($dialog_err);
  1878. $dialog_body_div.append($dialog_body_download_verify);
  1879. $dialog_body.append($dialog_body_div);
  1880. $dialog_footer.append($dialog_confirm_button).append($dialog_cancel_button);
  1881. $dialog_div.append($dialog_header).append($dialog_body).append($dialog_footer);
  1882. $('body').append($dialog_div);
  1883. $dialog_div.dialogDrag();
  1884. $dialog_control.click(dialogControl);
  1885. $dialog_img.click(refreshVCode);
  1886. $dialog_refresh.click(refreshVCode);
  1887. $dialog_input.keypress(function (event) {
  1888. if (event.which == 13)
  1889. confirmClick();
  1890. });
  1891. $dialog_confirm_button.click(confirmClick);
  1892. $dialog_cancel_button.click(dialogControl);
  1893. $dialog_input.click(function () {
  1894. $('#dialog-err').text('');
  1895. });
  1896. return $dialog_div;
  1897. }
  1898. this.open = function (vcode) {
  1899. if (vcode)
  1900. $('#dialog-img').attr('src', vcode.img);
  1901. dialog.show();
  1902. shadow.show();
  1903. };
  1904. this.close = function () {
  1905. dialogControl();
  1906. };
  1907. dialog = createDialog();
  1908. shadow = $('div.dialog-shadow');
  1909. function dialogControl() {
  1910. $('#dialog-img', dialog).attr('src', '');
  1911. $('#dialog-err').text('');
  1912. dialog.hide();
  1913. shadow.hide();
  1914. }
  1915. }
  1916. $.fn.dialogDrag = function () {
  1917. var mouseInitX, mouseInitY, dialogInitX, dialogInitY;
  1918. var screenWidth = document.body.clientWidth;
  1919. var $parent = this;
  1920. $('div.dialog-header', this).mousedown(function (event) {
  1921. mouseInitX = parseInt(event.pageX);
  1922. mouseInitY = parseInt(event.pageY);
  1923. dialogInitX = parseInt($parent.css('left').replace('px', ''));
  1924. dialogInitY = parseInt($parent.css('top').replace('px', ''));
  1925. $(this).mousemove(function (event) {
  1926. var tempX = dialogInitX + parseInt(event.pageX) - mouseInitX;
  1927. var tempY = dialogInitY + parseInt(event.pageY) - mouseInitY;
  1928. var width = parseInt($parent.css('width').replace('px', ''));
  1929. tempX = tempX < 0 ? 0 : tempX > screenWidth - width ? screenWidth - width : tempX;
  1930. tempY = tempY < 0 ? 0 : tempY;
  1931. $parent.css('left', tempX + 'px').css('top', tempY + 'px');
  1932. });
  1933. });
  1934. $('div.dialog-header', this).mouseup(function (event) {
  1935. $(this).unbind('mousemove');
  1936. });
  1937. }
  1938. })();

保存后在管理界面即可看到已安装脚本

重启浏览器,用百度随便搜索东西,可以在搜索栏右边看到一个“自定义”选项,点击后可以自由选择百度搜索结果的风格,本人选择的如下:

 

 

结果如下:

 

 

更多脚本可以在https://greasyfork.org/zh-CN获得

由于这些东西不是很难,读者有不明白的地方可以自行百度 tampermonkey配置学习!

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/393787
推荐阅读
相关标签
  

闽ICP备14008679号