// ==UserScript== // @name 雷利子 // @namespace https://github.com/oneNorth7/Cloud189_popper // @version 0.2.7 // @author 一个北七 // @description 简单突破天翼云盘网页版文件下载的大小, 多文件, 文件夹限制; 单选、多选、全选文件直接下载; 逐个文件直接下载并根据情况复制目录名称 // @icon https://gitee.com/oneNorth7/pics/raw/master/picgo/pentagram-devil.png // @created 2021/3/13 下午6:23:05 // @include http*://cloud.189.cn/* // @compatible chrome 69+ // @compatible firefox 78+ // @compatible edge Latest // @noframes // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js // @require https://cdn.jsdelivr.net/npm/sweetalert2@10.15.5/dist/sweetalert2.all.min.js // @run-at document-end // @grant unsafeWindow // @grant GM_registerMenuCommand // @grant GM_setValue // @grant GM_getValue // @grant GM_setClipboard // @downloadURL none // ==/UserScript== void function() { 'use strict'; const sizeLimit = 50 * 1<<10 * 1<<10; const buttonText = '\u76f4\u63a5\u4e0b\u8f7d'; const buttonStyle = {'background-color': '#36BE63', 'color': 'white'}; let t = { clog() { console.group('[\u96f7\u5229\u5b50]'); for (let m of arguments) { if (void 0 !== m) console.log(m); } console.groupEnd(); }, set(name, value) { GM_setValue(name, value); }, get(name, def) { return GM_getValue(name, def); }, registerMenu(title, func) { return GM_registerMenuCommand(title, func); }, copy(text, type='text/plain') { GM_setClipboard(text, type); }, increase() { success_times = +this.get("success_times") + 1; this.set("success_times", success_times); }, subscribe() { let isFollowed = this.get('isFollowed', false), least_times = this.get('least_times', 20); success_times = +this.get("success_times"); if (success_times > least_times && !isFollowed) { Swal.fire({ title: '\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e0d\u8ff7\u8def\uff01', html: $( `
\u7b2c\u4e00\u65f6\u95f4\u83b7\u53d6\u66f4\u65b0\u63a8\u9001\uff01\uff01\uff01
\u662f\u5426\u5168\u90e8\u9010\u4e00\u4e0b\u8f7d\uff1f
', icon: 'warning', showCancelButton: true, allowOutsideClick: false, confirmButtonColor: '#d33', confirmButtonText: '\u786e\u5b9a\u5168\u90e8\u4e0b\u8f7d', cancelButtonColor: '#3085d6', cancelButtonText: '\u53d6\u6d88\u4e0b\u8f7d', }).then((result) => { if (result.isConfirmed) { directDownload(); t.info('\u5c01\u5370\u89e3\u9664\uff01', '\u5168\u90e8\u6587\u4ef6\u5f00\u59cb\u9010\u4e00\u4e0b\u8f7d', 'success'); } }); } }, showInfo() { let view = this.getView(), fileIdList = this.getFileIdList(view), fileList = this.getFileList(), panType = this.getPanType(), msg = ''; switch(panType) { case 0: case 2: if ($('a.J_Download').hasClass('disable')) { t.info('\u7cfb\u7edf\u751f\u6210\u6587\u4ef6\u5939', '\u65e0\u6cd5\u76f4\u63a5\u4e0b\u8f7d\uff0c\u8bf7\u8fdb\u5165\u6587\u4ef6\u5939\u4e0b\u8f7d\uff01'); return ; } if (fileIdList) { if (fileIdList.includes(',') ) { msg += '\u6210\u529f\u7a81\u7834\u6587\u4ef6\u6570\u91cf\u9650\u5236\uff01'; } else { msg += this.breakSingleSize(fileList.selected()[0]); } } if (this.isFolderSelected()) msg = msg ? msg.replace('\u9650\u5236', '\u548c\u6587\u4ef6\u5939\u9650\u5236') : '\u6210\u529f\u7a81\u7834\u6587\u4ef6\u5939\u9650\u5236\uff01'; break; case 1: msg += '\u6210\u529f\u7a81\u7834\u6587\u4ef6\u5927\u5c0f\u9650\u5236\uff01'; break; } t.increase(); if (msg) t.info('\u5c01\u5370\u89e3\u9664\uff01', msg, 'success'); }, hideTip() { $('div.tips-save-box').hide(); }, changeStyleOne() { if (unsafeWindow.fileSize >= sizeLimit) { this.enableButton(); $('a.download-link').css(buttonStyle).text(buttonText); this.showInfo(); } this.hideTip(); }, changeStyleTwo() { $('div.file-item').on('click', () => { $('#J_Download').css(buttonStyle).text(buttonText); this.hideTip(); }); $('.file-list-hd .col-checkbox').on('click', () => { setTimeout(() => { $('#J_Download').css(buttonStyle).text(buttonText); this.hideTip(); }, 2000); }); this.addListener(); }, changeStyleZero() { $('.file-item-container>.file-item').on('click', () => { $('.file-list-container div.btn-group .dropdown').css('width','320px'); $('a.J_Download').css(buttonStyle).text(buttonText); }); $('.file-list-hd .col-checkbox').on('click', () => { setTimeout(() => { $('.file-list-container div.btn-group .dropdown').css('width','320px'); $('a.J_Download').css(buttonStyle).text(buttonText); }, 2000); }); this.addListener(); }, addListener() { $('a.J_Download, #J_Download').on('click', () => { this.enableButton(); this.securityOn(); this.copyFolderName(); this.showInfo(); }); $('div.file-item-container a.download-link').on('click', (obj) => { $(obj.target).parents('div.file-item').click(); $('a.J_Download, #J_Download')[0].click(); }); $('a.open-link, ul.breadcrumb a').on('click', () => { setTimeout(() => { this.changeButton(); }, 1000); this.addButton(); }); $('a.allfile').on('click', () => { setTimeout(() => { this.addButton(); }, 1000); }); this.addButton(); }, addButton() { let downloadLink = $('div.file-item-container:visible>.file-item'); let newButton = this.newButton, name = this.getFolderName(); if (downloadLink.length > 1 && name.length <= 1) { let operate = $('a.btn-save-as'); if (operate.length && !$('#J_download1by1').length) { this.newButton = $('\u9010\u4e2a\u4e0b\u8f7d'); operate.before(this.newButton); } let bar = $('div.toolbar>.btn-group'); if (bar.length && !$('#J_download1by1').length) { this.newButton = $('\u9010\u4e2a\u4e0b\u8f7d'); bar.append(this.newButton); } $('#J_download1by1').on('click', () => { this.download1by1(); }); } else if (newButton) newButton.remove(); this.hideTip(); }, changeButton() { let panType = this.getPanType(); switch(panType) { case 0: if ($('#J_SwitchMode').text() == '\u5217\u8868') $('#J_SwitchMode')[0].click(); this.changeStyleZero(); break; case 1: this.changeStyleOne(); break; case 2: if ($('span.J_DropdownToggleContent').text() == '\u56fe\u6807') $('#J_ListMode')[0].click(); this.changeStyleTwo() break; } }, isLogin() { return unsafeWindow.application && unsafeWindow.application.headerView.isLogin; }, init() { if (!$('#code_txt').length) { $('#J_Notify').css('z-index', 1010); setTimeout(() => { let count = 0, result; let tid = setInterval(() => { count++; result = unsafeWindow.fileId || unsafeWindow.appRouter || unsafeWindow.mainView; if ($('div.login-pannel').length > 0 || $('div.error-content').length > 0) { clearInterval(tid); } else if (this.isLogin() && result) { this.changeButton(); clearInterval(tid); t.clog('\u52a0\u8f7d\u6210\u529f\uff01'); if (flag) t.info('\u96f7\u5229\u5b50','\u5c01\u5370\u89e3\u9664\uff01', 'success'); } else if (this.isLogin() === false) { clearInterval(tid); Swal.fire('\u8bf7\u5148\u767b\u5f55\uff01', '\u5fc5\u987b\u767b\u5f55\u624d\u80fd\u7a81\u7834\u4e0b\u8f7d\u9650\u5236', 'info') .then(result => { if (result.isConfirmed) { let account = $('#J_UserAccount'); if (account.text() == '\u767b\u5f55') account.click(); } }); $('body').removeClass('swal2-height-auto'); } if (count == 5) { clearInterval(tid); Swal.fire('\u96f7\u5229\u5b50', '\u52a0\u8f7d\u8d85\u65f6\uff0c\u8bf7\u5237\u65b0\u9875\u9762\u91cd\u8bd5\uff01', 'error') .then(result => { if (result.isConfirmed) { location.reload(); } }); $('body').removeClass('swal2-height-auto'); } }, 1000); }, 1000); } else { t.info('\u63a8\u8350\u4f7f\u7528<\u94fe\u63a5\u52a9\u624b>', '\u81ea\u52a8\u586b\u5199\u7f51\u76d8\u5bc6\u7801'); $('a.btn-primary').click(() => { setTimeout(() => { if ($('div.file-item-container').children().length) { if (this.isLogin()) location.reload(); else { Swal.fire('\u8bf7\u5148\u767b\u5f55\uff01', '\u5fc5\u987b\u767b\u5f55\u624d\u80fd\u7a81\u7834\u4e0b\u8f7d\u9650\u5236', 'info') .then(result => { if (result.isConfirmed) { let account = $('#J_UserAccount'); // if (account.text() == '登录') account.click(); if (account.text() == '\u767b\u5f55') account.click(); } }); $('body').removeClass('swal2-height-auto'); } } }, 500); }); $('#code_txt').one('focus', () => { if ($('div.link-helper').length) $('div.link-helper').show(); else $('div.access-code-item').append('\u8bd5\u8bd5\u80fd\u81ea\u52a8\u586b\u5199\u7f51\u76d8\u5bc6\u7801\u7684\ud83d\udc49\u94fe\u63a5\u52a9\u624b