百度云解析 blog.tsyinpin.com 优化版

百度云盘解析 blog.tsyinpin.com 优化版

  1. // ==UserScript==
  2. // @name 百度云解析 blog.tsyinpin.com 优化版
  3. // @namespace http://blog.tsyinpin.com
  4. // @version 0.1.6
  5. // @description 百度云盘解析 blog.tsyinpin.com 优化版
  6. // @author gxvv
  7. // @supportURL http://blog.tsyinpin.com
  8. // @date 01/01/2017
  9. // @modified 05/04/2017
  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. // @match *://eyun.baidu.com/s/*
  17. // @run-at document-end
  18. // @grant unsafeWindow
  19. // @grant GM_addStyle
  20. // @grant GM_info
  21. // @require https://cdn.bootcss.com/clipboard.js/1.5.16/clipboard.min.js
  22. // ==/UserScript==
  23.  
  24. (function(require, define, Promise) {
  25. 'use strict';
  26.  
  27. function showError(msg) {
  28. GM_addStyle('#errorDialog{position: fixed;top: 76.5px; bottom: auto; left: 423px; right: auto;background: #fff;border: 1px solid #ced1d9;border-radius: 4px;box-shadow: 0 0 3px #ced1d9;color: black;word-break: break-all;display: block;width: 520px;padding: 10px 20px;z-index: 9999;}#errorDialog h3{border-bottom: 1px solid #ced1d9;font-size: 1.5em;font-weight: bold;}');
  29. var $;
  30. try {
  31. $ = require('base:widget/libs/jquerypacket.js');
  32. } catch (e) {
  33. var div = document.createElement('div');
  34. $ = function(str) {
  35. div.innerHTML = str;
  36. div.onclick = function() {
  37. this.remove();
  38. };
  39. return $;
  40. };
  41. $.on = function() {
  42. return {
  43. appendTo: function() {
  44. document.body.appendChild(div);
  45. }
  46. };
  47. };
  48. }
  49. var $dialog = $('<div id="errorDialog">' +
  50. '<h3>EX-baiduyunpan:程序异常</h3>' +
  51. '<div class="dialog-body"><p>请尝试更新脚本或复制以下信息提交issue</p>' +
  52. '<p>Exception: ' + msg + '</p>' +
  53. '<p>Script Ver: ' + GM_info.script.version + '</p>' +
  54. '<p>TemperMonkey Ver: ' + GM_info.version + '</p>' +
  55. '<p>UA: ' + navigator.userAgent + '</p>' +
  56. '</div><hr><a class="close" href="javascript:;">关闭</a></div>');
  57. $dialog.on('click', '.close', function(event) {
  58. $dialog.remove();
  59. }).appendTo(document.body);
  60. }
  61. define('ex-yunpan:pageInfo', function(require) {
  62. var url = location.href;
  63. var currentPage = 'pan';
  64. var matchs = {
  65. '.*://pan.baidu.com/disk/home.*': 'pan',
  66. '.*://yun.baidu.com/disk/home.*': 'pan',
  67. '.*://pan.baidu.com/s/.*': 'share',
  68. '.*://yun.baidu.com/s/.*': 'share',
  69. '.*://pan.baidu.com/share/link?.*': 'share',
  70. '.*://yun.baidu.com/share/link?.*': 'share',
  71. '.*://eyun.baidu.com/s/.*': 'enterprise'
  72. };
  73. var PAGE_CONFIG = {
  74. pan: {
  75. prefix: 'file-widget-1:',
  76. containers: ['.g-button:has(.icon-download):visible'],
  77. style: function() {
  78. GM_addStyle('.DxdbeCb .QDDOQB .g-dropdown-button.ex-yunpan-dropdown-button .g-button{border-radius: 0;}');
  79. }
  80. },
  81. share: {
  82. prefix: 'file-widget-1:',
  83. containers: [
  84. '.KKtwaH .button-box>.g-button:has(.icon-download)',
  85. '.module-share-top-bar .button-box>.g-button:has(.icon-download)'
  86. ],
  87. style: function() {
  88. var styleList = [
  89. '.KPDwCE .QxJxtg{z-index: 2;}',
  90. '.module-share-header .slide-show-right{width: auto;}',
  91. '.ex-yunpan-dropdown-button.g-dropdown-button.button-open .menu{z-index:41;}',
  92. '.module-share-header .slide-show-header h2{width:230px;}',
  93. '.KPDwCE .xGLMIab .g-dropdown-button.ex-yunpan-dropdown-button{margin: 0 5px;}'
  94. ];
  95. GM_addStyle(styleList.join(''));
  96. }
  97. },
  98. enterprise: {
  99. prefix: 'business-function:',
  100. containers: ['.button-box-container>.g-button:has(:contains("下载"))'],
  101. style: function() {
  102. var styleList = [
  103. '.ex-yunpan-dropdown-button .icon-download{background-image: url(/box-static/business-function/infos/icons_z.png?t=1476004014313);}',
  104. '.ex-yunpan-dropdown-button .g-button:hover .icon-download{background-position: 0px -34px;}'
  105. ];
  106. GM_addStyle(styleList.join(''));
  107. }
  108. }
  109. };
  110. for (var match in matchs) {
  111. if (new RegExp(match).test(url) === true) {
  112. currentPage = matchs[match];
  113. }
  114. }
  115. return PAGE_CONFIG[currentPage];
  116. });
  117. define('ex-yunpan:downloadBtnInit', function(require) {
  118. var ctx = require('system-core:context/context.js').instanceForSystem;
  119. var $ = require('base:widget/libs/jquerypacket.js');
  120. var pageInfo = require('ex-yunpan:pageInfo');
  121. var prefix = pageInfo.prefix;
  122. var dServ = null;
  123. require.async(prefix + 'download/service/dlinkService.js', function(dlinkService) {
  124. dServ = dlinkService;
  125. });
  126. var exDlBtnConfig = {
  127. type: 'dropdown',
  128. title: '解析下载',
  129. resize: true,
  130. menu: [{
  131. title: '普通下载',
  132. 'click': function() {
  133. var start = require(prefix + 'download/start.js');
  134. start.start(ctx);
  135. }
  136. }, {
  137. title: '复制链接',
  138. 'click': function() {
  139. var selectedList = ctx.list.getSelected();
  140. if (selectedList.length === 0) return ctx.ui.tip({
  141. mode: 'caution',
  142. msg: '您还没有选择下载的文件'
  143. });
  144. ctx.ui.tip({
  145. mode: 'loading',
  146. msg: '开始请求链接...'
  147. });
  148. var foldersList = selectedList.filter(function(e) {
  149. return e.isdir === 1;
  150. });
  151. var filesList = selectedList.filter(function(e) {
  152. return e.isdir === 0;
  153. });
  154. var currentProduct = ctx.pageInfo.currentProduct;
  155. if (!~['pan', 'share', 'enterprise'].indexOf(currentProduct)) {
  156. return ctx.ui.tip({
  157. mode: 'caution',
  158. msg: '复制链接当前页面不可用',
  159. hasClose: true,
  160. autoClose: false
  161. });
  162. }
  163. if (filesList.length > 0 && currentProduct !== 'enterprise') {
  164. foldersList.unshift(filesList);
  165. } else {
  166. [].push.apply(foldersList, filesList);
  167. }
  168. var requestMethod;
  169. if (currentProduct === 'pan') {
  170. requestMethod = function(e, cb) {
  171. dServ.getDlinkPan(dServ.getFsidListData(e), e.isdir === 1 ? 'batch' : 'nolimit', cb, undefined, undefined, 'POST');
  172. };
  173. } else {
  174. var yunData = require((currentProduct === 'share' ? 'disk-share:widget/system' : 'page-common:widget') + '/data/yunData.js').get();
  175. requestMethod = function(e, cb) {
  176. dServ.getDlinkShare({
  177. share_id: yunData.shareid,
  178. share_uk: yunData.uk,
  179. sign: yunData.sign,
  180. timestamp: yunData.timestamp,
  181. list: currentProduct === 'share' ? e : [e],
  182. type: e.isdir === 1 ? 'batch' : 'nolimit'
  183. }, cb);
  184. };
  185. }
  186. var promises = foldersList.map(function(e) {
  187. return new Promise(function(resolve, reject) {
  188. var timer = setTimeout(function() {
  189. resolve($.extend({}, e));
  190. }, 15000);
  191. requestMethod(e, function(result) {
  192. resolve($.extend({}, e.isdir === 1 ? e : {}, result));
  193. });
  194. });
  195. });
  196. Promise.all(promises).then(function(result) {
  197. ctx.ui.hideTip();
  198. var dlinks = [];
  199. var needToRetry = result.filter(function(e) {
  200. return e.errno !== 0;
  201. });
  202. if (needToRetry.length > 0) {
  203. try {
  204. dServ.dialog.hide();
  205. } catch (ex) {}
  206. ctx.ui.tip({
  207. mode: 'caution',
  208. msg: needToRetry.length + '个文件请求链接失败'
  209. });
  210. }
  211. result.filter(function(e) {
  212. return e.errno === 0;
  213. }).forEach(function(e) {
  214. if (e.isdir === 1) {
  215. var dlink = e.dlink + "&zipname=" + encodeURIComponent('【文件夹】' + e.server_filename + '.zip');
  216. dlinks.push(e.dlink && dlink);
  217. } else {
  218. [].push.apply(dlinks, (e.dlink || e.list || []).map(function(e) {
  219. return e.dlink;
  220. }));
  221. }
  222. });
  223. if (dlinks.length === 0) return ctx.ui.tip({
  224. mode: 'caution',
  225. msg: '复制失败:未获取到链接'
  226. });
  227. var clipboard = new Clipboard('.btn');
  228. clipboard.on('success', function(e) {
  229. ctx.ui.tip({
  230. mode: 'success',
  231. msg: '复制成功' + dlinks.length + '个文件'
  232. });
  233. e.clearSelection();
  234. dialog.hide();
  235. clipboard.destroy();
  236. });
  237. clipboard.on('error', function(e) {
  238. ctx.ui.tip({
  239. mode: 'caution',
  240. msg: '复制失败'
  241. });
  242. });
  243. var text = '<textarea id="bar" rows="' + (dlinks.length + 1) + '" style="width:100%;white-space: nowrap;">' + dlinks.join('\n') + '</textarea>';
  244. var dialog = ctx.ui.confirm({
  245. title: '复制链接',
  246. body: text,
  247. sureText: '复制',
  248. onClose: function() {
  249. clipboard && clipboard.destory && clipboard.destroy();
  250. }
  251. });
  252. dialog.buttonIns[0].dom.attr({
  253. 'data-clipboard-action': 'copy',
  254. 'data-clipboard-target': '#bar'
  255. }).addClass('btn').off();
  256. }).catch(function(e) {
  257. showError(e);
  258. });
  259. }
  260. }],
  261. icon: 'icon-download'
  262. };
  263. var selector = pageInfo.containers.join();
  264. $(selector).each(function(i, e) {
  265. var exDlBtn = ctx.ui.button(exDlBtnConfig);
  266. $(e).after(exDlBtn.dom.addClass('ex-yunpan-dropdown-button'));
  267. exDlBtn.resizeButtonWidth();
  268. });
  269. pageInfo.style();
  270. });
  271. define('ex-yunpan:pluginInit.js', function(require, module, exports) {
  272. var ctx = require('system-core:context/context.js').instanceForSystem;
  273. var $ = require('base:widget/libs/jquerypacket.js');
  274. var pageInfo = require('ex-yunpan:pageInfo');
  275. var prefix = pageInfo.prefix;
  276. var dmPromise = new Promise(function(resolve, reject) {
  277. $(unsafeWindow).on('load', function() {
  278. reject('downloadManager.js');
  279. });
  280. require.async(prefix + 'download/service/downloadManager.js', function(dm) {
  281. dm.MODE_PRE_INSTALL = dm.MODE_PRE_DOWNLOAD;
  282. resolve();
  283. });
  284. });
  285. var gjcPromise = new Promise(function(resolve, reject) {
  286. $(unsafeWindow).on('load', function() {
  287. reject('guanjiaConnector.js');
  288. });
  289. require.async(prefix + 'download/service/guanjiaConnector.js', function(gjC) {
  290. gjC.init = function() {
  291. setTimeout(function() {
  292. ctx.ui.tip({
  293. mode: 'caution',
  294. msg: '检测到正在调用云管家,若脚本失效,请检查更新或提交issue',
  295. hasClose: true,
  296. autoClose: false
  297. });
  298. }, 5000);
  299. };
  300. resolve();
  301. });
  302. });
  303. var ddsPromise = new Promise(function(resolve, reject) {
  304. $(unsafeWindow).on('load', function() {
  305. reject('downloadDirectService.js');
  306. });
  307. require.async(prefix + 'download/service/downloadDirectService.js', function(dDS) {
  308. var $preDlFrame = null;
  309. var _ = dDS.straightforwardDownload;
  310. if (typeof _ !== 'function') return;
  311. dDS.straightforwardDownload = function() {
  312. ctx.ui.tip({
  313. mode: 'loading',
  314. msg: '正在开始下载...'
  315. });
  316. if ($preDlFrame === null) {
  317. setTimeout(function() {
  318. var $frame = $('#pcsdownloadiframe');
  319. if ($frame.length === 0) return;
  320. $frame.ready(function(event) {
  321. ctx.ui.hideTip();
  322. });
  323. $preDlFrame = $frame;
  324. }, 1000);
  325. }
  326. _.apply(dDS, arguments);
  327. };
  328. resolve();
  329. });
  330. });
  331. Promise.all([dmPromise, gjcPromise, ddsPromise]).then(function() {
  332. try {
  333. require('ex-yunpan:downloadBtnInit');
  334. ctx.ui.tip({
  335. mode: 'success',
  336. msg: '百度云盘解析: 插件加载成功'
  337. });
  338. } catch (e) {
  339. ctx.ui.tip({
  340. mode: 'caution',
  341. msg: '百度云盘解析: 插件加载成功,按钮初始化失败',
  342. autoClose: false,
  343. hasClose: true
  344. });
  345. }
  346. }).catch(function(msg) {
  347. showError(msg + '加载失败');
  348. });
  349. });
  350. try {
  351. require('ex-yunpan:pluginInit.js');
  352. } catch (ex) {
  353. showError(ex);
  354. }
  355. })(unsafeWindow.require, unsafeWindow.define, unsafeWindow.Promise);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址