// ==UserScript==
// @name 雷利子
// @namespace https://github.com/oneNorth7/Cloud189_popper
// @version 0.2.9
// @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
// @grant GM_xmlhttpRequest
// @grant GM_download
// ==/UserScript==
void function() {
'use strict';
const sizeLimit = 1024 * 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", 0) + 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: $(
`<div><img style="width: 300px;margin: 5px auto;" src="https://gitee.com/oneNorth7/pics/raw/master/picgo/oneNorth7.png"><p style="font-size: 16px;color: red;">\u7b2c\u4e00\u65f6\u95f4\u83b7\u53d6\u66f4\u65b0\u63a8\u9001\uff01\uff01\uff01</p></div>`
)[0],
showCancelButton: true,
allowOutsideClick: false,
confirmButtonColor: '#d33',
confirmButtonText: '\u5df2\u5173\u6ce8\uff0c\u4e0d\u518d\u63d0\u9192\uff01',
cancelButtonColor: '#3085d6',
cancelButtonText: '\u7a0d\u540e\u5173\u6ce8',
}).then((result) => {
if (result.isConfirmed) {
Swal.fire({
position: 'center',
icon: 'success',
title: '\u611f\u8c22\u5173\u6ce8\uff01\uff01\uff01',
text: '\u4e00\u4e2a\u5317\u4e03\u4f1a\u7ee7\u7eed\u4e0d\u9057\u4f59\u529b\u5730\u521b\u4f5c\u66f4\u591a\u5b9e\u7528\u5de5\u5177',
showConfirmButton: false,
timer: 2000
});
this.set('isFollowed', true);
} else this.set('least_times', least_times + 15);
});
} else flag = true;
},
info(text, icon='success', title = '\u96f7\u5229\u5b50', position='top', timer=2000) {
if (icon == 'error') timer = timer == 2000 ? 3000 : timer;
return Swal.fire({
position,
icon,
toast: true,
title,
text,
showConfirmButton: false,
timer
});
},
};
let success_times = t.get("success_times"), flag = false;
if (!success_times || isNaN(success_times)) t.set("success_times", 0);
t.subscribe();
const o = location.origin,
h = location.host,
hr = location.href,
ha = location.hash,
s = location.search;
const api = ['/api/open/user/getUserInfoForPortal.action',
'/api/open/share/getShareInfoByCode.action',
'/api/open/file/getFileDownloadUrl.action',
'/api/portal/listFiles.action'];
let main = {
hideTip() {
$('div.tips-save-box').hide();
},
isLogin() {
return $('div.person-info').children().length != 2;
},
getFileInfo() {
let code = s.replace('?code=', '');
if (code) {
this._get(api[1], {shareCode: code},
res => {
if (res.isFolder) {
this.multiShare(res.shareId);
$('section.c-file-list').delegate('li, label.ant-checkbox-wrapper', 'mousedown', o => {
setTimeout(() => {
let button = $('div.button-normal:contains("\u4e0b\u8f7d")');
button.remove();
}, 500);
});
} else if(res.fileSize > sizeLimit){
this.singleShare(res.fileId, res.shareId);
} else
$('a.btn-download').removeAttr('target').text(buttonText).css(buttonStyle);
},
err => {
t.clog('error:', err);
});
} else {
this.mainPage();
$('li.title-message,\
div.nav-logo,\
li.menu-item:contains(" \u4e91\u76d8 ")').on('click',
o => {
setTimeout(() => this.mainPage(), 1000);
});
$('section.c-file-list').delegate('li, label.ant-checkbox-wrapper', 'mousedown', o => {
setTimeout(() => {
let button = $('div.button-normal:contains("\u4e0b\u8f7d")');
button.remove();
let menu = $('div[class^="menu_menu-block-item_"]:contains("\u4e0b\u8f7d")');
if (!$(`div[class^="menu_menu-block-item_"]:contains("${buttonText}")`).length) {
let another = menu.clone().text(buttonText).click(this.directDownload);
menu.replaceWith(another);
}
}, 500);
});
}
},
directDownload(time = 1000, delay = 1000) {
let items = $('li.c-file-item.selected:not([data-isfolder])');
if (items.length) {
items.each((i, e) => {
setTimeout(() => {
$(e).find('span.file-item-ope-item-download').click();
}, time += delay);
});
}
else t.info('\u9009\u4e2d\u4e3a\u6587\u4ef6\u5939\uff0c\u8bf7\u8fdb\u5165\u76ee\u5f55\u4e0b\u8f7d\uff01', 'info');
},
_get(url, data, success, error = () => {}) {
data.noCache = Math.random();
return $.ajax(url,
{data,
success,
error,
headers: {Accept: 'application/json;charset=UTF-8'}
});
},
singleShare(fileId, shareId) {
this._get(api[2], {fileId, shareId, dt: 1},
res => {
let link = $('a.btn-download').clone()
.prop('href', res.fileDownloadUrl)
.removeAttr('target')
.text(buttonText)
.css(buttonStyle);
$('a.btn-download').replaceWith(link);
t.increase();
t.info('\u6210\u529f\u7a81\u7834\u6587\u4ef6\u5927\u5c0f\u4e0b\u8f7d\u9650\u5236\uff01');
},
err => {
t.clog('error', err);
t.info('\u83b7\u53d6\u4e0b\u8f7d\u76f4\u94fe\u5931\u8d25\uff01', 'error');
});
},
replaceDownload(o, shareId) {
let fileId = $(o.target).parents('li').attr('data-fileid');
let e = o.currentTarget, result = e.title.match(/&expired=(\d+)&/),
time = new Date(Number(result && result[1]));
if (time < new Date) {
this._get(api[2], {fileId, shareId, dt: 1},
res => {
let url = res.fileDownloadUrl
$(e).data('href', url)
let iframe = $(`<iframe src="${url}" style="display: none;"></iframe>`);
$(document.head).append(iframe);
if (Number($(e).parents('div.file-item-name').next().text().replace('G', '')) > 1) {
t.increase();
t.info('\u6210\u529f\u7a81\u7834\u6587\u4ef6\u5927\u5c0f\u4e0b\u8f7d\u9650\u5236\uff01');
}
},
err => {
$(e).parents('.file-item-ope').prev().css('color', '#f0424f');
t.clog('error', err);
t.info('\u83b7\u53d6\u4e0b\u8f7d\u76f4\u94fe\u5931\u8d25\uff01', 'error');
});
} else {
let url = $(e).data('href'),
iframe = $(`<iframe src="${url}" style="display: none;"></iframe>`);
$(document.head).append(iframe);
}
},
multiShare(shareId) {
$('ul.file-list-ul>li').each((i, e) => {
if ($(e).attr('data-isfolder')) {
$(e).find('span.file-item-name-fileName-span').one('click',
o => {
setTimeout(() => {
this.multiShare(shareId);
$('div.FileListHead_file-list-nav_1Yc_- span[class^="FileListHead_file-list-nav-"]')
.on('click', o => {
setTimeout(() => this.multiShare(shareId), 1000);
});
}, 1000);
});
} else {
let span = $(e).find('span.file-item-ope-item-download'),
another = span.clone().prop('title', buttonText).on('click', o => this.replaceDownload(o, shareId));
span.replaceWith(another);
}
});
},
mainPage() {
let folderId = location.pathname.match('/web/main/file/folder/(-?\\d+)$');
if(folderId) {
let fileId = folderId[1];
this._get(api[3], {fileId},
res => {
let {data} = res;
if (data) {
for (let d of data) {
let li = $(`li[data-fileId="${d.fileId}"]`);
if (d.isFolder) {
let span = li.find('div.file-item-ope-item>span.file-item-ope-item-download');
if (span.length) {
let link = $('<a></a>').append(span.clone().prop('title', '\u8bf7\u8fdb\u5165\u76ee\u5f55\u4e0b\u8f7d\uff01')).click(o => t.info('\u8bf7\u8fdb\u5165\u76ee\u5f55\u4e0b\u8f7d\uff01', 'info'));
span.replaceWith(link);
}
li.find('span.file-item-name-fileName-span').one('click', o => {
setTimeout(() => {
this.mainPage();
$('div.FileListHead_file-list-nav_1Yc_- span[class^="FileListHead_file-list-nav-"]')
.on('click', o => {
setTimeout(() => this.mainPage(), 1000);
});
}, 1000);
});
} else {
let span = li.find('span.file-item-ope-item-download').prop('title', buttonText);
if (d.fileSize > sizeLimit) {
let another = span.clone().click(o => {
let iframe = $(`<iframe src="${d.downloadUrl}" style="display: none;"></iframe>`);
$(document.head).append(iframe);
t.increase();
t.info('\u6210\u529f\u7a81\u7834\u6587\u4ef6\u5927\u5c0f\u4e0b\u8f7d\u9650\u5236\uff01');
});
span.replaceWith(another);
}
}
}
}
},
err => {
t.clog('error', err);
});
}
},
init() {
if (!$('#code_txt:visible').length) {
setTimeout(async () => {
if (!this.isLogin()) {
Swal.fire('\u8bf7\u5148\u767b\u5f55\uff01', '\u5fc5\u987b\u767b\u5f55\u624d\u80fd\u7a81\u7834\u4e0b\u8f7d\u9650\u5236', 'info');
$('body').removeClass('swal2-height-auto');
} else if ($('div.error-content:visible').length) {
} else {
this.hideTip();
this.getFileInfo();
if (flag) t.info('\u5c01\u5370\u89e3\u9664\uff01');
}
}, 1000);
} else {
t.info('\u81ea\u52a8\u586b\u5199\u7f51\u76d8\u5bc6\u7801', 'info', '\u63a8\u8350\u4f7f\u7528<\u94fe\u63a5\u52a9\u624b>');
$('a.btn-primary').click(() => {
setTimeout(() => {
if ($('div.file-operate:visible').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');
$('body').removeClass('swal2-height-auto');
}
}
}, 500);
});
$('#code_txt').one('focus', () => {
let tip = $('div.tips-save-box').clone(true, true).css({top: '230px', left: '50px'})
tip.children('p').css({width: '110px', top: '35px', left: '8px'}).html('\u8bd5\u8bd5\u80fd\u81ea\u52a8\u586b\u5199\u7f51\u76d8\u5bc6\u7801\u7684\ud83d\udc49<a target="_blank" href="https://greasyfork.org/zh-CN/scripts/422773-%E9%93%BE%E6%8E%A5%E5%8A%A9%E6%89%8B" style="color:#2b89ea;position:relative;display:inline;top:0;left:0;text-decoration:underline;">\u94fe\u63a5\u52a9\u624b</a>');
tip.children('img').prop('alt', '\u94fe\u63a5\u52a9\u624b');
tip.children('a').click(o => $(o.target).parent().hide());
$('div.access-code-item').append(tip);
});
}
},
};
setTimeout(() => main.init(), 1500);
}();