// ==UserScript==
// @name 喵传链接
// @namespace https://t.me/KyokuSai
// @version 0.1.3
// @description 生成、转存秒传链接喵
// @author HanaCream
// @match *://pan.baidu.com/disk/home*
// @match *://pan.baidu.com/disk/main*
// @match *://yun.baidu.com/disk/home*
// @match *://yun.baidu.com/disk/main*
// @match *://wangpan.baidu.com/disk/home*
// @match *://wangpan.baidu.com/disk/main*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @grant unsafeWindow
// @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js
// @connect baidu.com
// @connect baidupcs.com
// @connect *
// @downloadURL none
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
(function () {
'use strict';
if (GM_getValue('savepath') === undefined) GM_setValue('savepath', '');
if (GM_getValue('ua') === undefined) GM_setValue('ua', 'nekoupload');
if (GM_getValue('debug') === undefined) GM_setValue('debug', false);
if (GM_getValue('purify') === undefined) GM_setValue('purify', false);
if (GM_getValue('drag') === undefined) GM_setValue('drag', true);
if (GM_getValue('dlinkapi') === undefined) GM_setValue('dlinkapi', false);
let $_savepath = GM_getValue('savepath');
let $_ua = GM_getValue('ua');
let $_debug = GM_getValue('debug');
let $_purify = GM_getValue('purify');
let $_drag = GM_getValue('drag');
let $_dlinkapi = GM_getValue('dlinkapi');
var styleElement = document.createElement('style');
styleElement.innerHTML = `
.nekoupload-switch{position:relative;display:inline-block;width:64px;height:26px;transition:all .3s ease}.nekoupload-switch>div{position:absolute;top:0;right:0;bottom:0;left:0;cursor:pointer;border:1px solid #626262;border-radius:32px;background:0 0}.nekoupload-switch>div:before{position:absolute;bottom:2px;left:3px;width:20px;height:20px;content:"";transition:all .3s cubic-bezier(.55,-.36,.59,1.46);border-radius:50%;background-color:#9c9c9c}.checked.nekoupload-switch>div{border-color:#fa4276}.checked.nekoupload-switch>div:before{transform:translateX(36px);background-color:#fa4276}#nekoupload_dialog *{box-sizing:border-box}#nekoupload_dialog{position:fixed;top:0;left:0;right:0;bottom:0;width:100%;height:100%;display:none;z-index:10000}#nekoupload_dialog_filter{position:fixed;top:0;left:0;right:0;bottom:0;width:100%;height:100%;z-index:10001;display:block;transition:opacity .3s ease;background:rgba(0,0,0,.2);opacity:0}#nekoupload_dialog_container{display:flex;position:absolute;top:50%;left:50%;transform:translate(-50%,calc(-50% + 4rem));width:min(600px,98%);background:#fff;align-items:center;border-radius:8px;overflow:hidden;flex-direction:column;z-index:10002;transition:all .3s ease;box-shadow:-1px 0 4px rgba(0,0,0,.04),0 1px 7px rgba(0,0,0,.07),3px 1px 12px rgba(0,0,0,.09)}.nekoupload-dialog-opened #nekoupload_dialog_filter{opacity:1}.nekoupload-dialog-opened #nekoupload_dialog_container{transform:translate(-50%,-50%)}body.nekoupload-dialog-opened{overflow:hidden}#nekoupload_dialog_title{font-size:1.2rem;font-weight:700;line-height:1;padding:.8rem;width:100%;text-align:center;background:#ffcad9}#nekoupload_dialog_content{font-size:1rem;font-weight:600;line-height:1.4;padding:1rem;color:#333;max-height:60vh;overflow:auto;width:100%;word-wrap:break-word}#nekoupload_dialog_btn{padding:.4rem}#nekoupload_dialog_btn button{background:#ff8ad2;padding:.4rem 1.2rem;border-radius:16px;margin:0 1rem;box-shadow:-1px 0 4px rgba(0,0,0,.04),0 1px 7px rgba(0,0,0,.07),3px 1px 12px rgba(0,0,0,.09);transition:all .3s ease;border:0;font-size:1.2rem;line-height:1;font-weight:700;color:#fff}#nekoupload_dialog_btn button:hover{background:#ff69f2;border:0}#nekoupload_btn{position:fixed;bottom:1.6rem;right:2rem;height:-moz-max-content;height:max-content;z-index:9999;transition:all .3s ease;display:flex;flex-direction:column}#nekoupload_btn button{width:2.8rem;height:2.8rem;background:#fff;border-radius:8px;color:#ff4276;font-size:1.2rem;font-weight:700;box-shadow:-1px 0 4px rgba(0,0,0,.04),0 1px 7px rgba(0,0,0,.07),3px 1px 12px rgba(0,0,0,.09);transition:all .3s ease;border:0;margin:4px}#nekoupload_btn button:hover{color:#fff;background:rgba(255,66,118,.64);border:0}#nekoupload_btn_settings svg{width:100%;height:100%;padding:.5rem}#nekoupload_btn button:hover .nekoupload-setting{fill:#fff}#nekoupload_nekocode{width:100%;min-height:5rem;text-align:left;margin:1rem 0;padding:.4rem .6rem;border-radius:8px;box-shadow:-1px 0 4px rgba(0,0,0,.04),0 1px 7px rgba(0,0,0,.07),3px 1px 12px rgba(0,0,0,.09);border:0;outline:0}.nekoupload-input{width:100%;min-height:1rem;text-align:left;margin:0 0 1rem;padding:.4rem .6rem;border-radius:8px;box-shadow:-1px 0 4px rgba(0,0,0,.04),0 1px 7px rgba(0,0,0,.07),3px 1px 12px rgba(0,0,0,.09);border:0;outline:0}#nekoupload_nekocode::-moz-placeholder,.nekoupload-input::-moz-placeholder{color:#999;font-size:1rem;font-weight:400}#nekoupload_nekocode::placeholder,.nekoupload-input::placeholder{color:#999;font-size:1rem;font-weight:400}#nekoupload_nekocode_savepath{margin:0}#nekoupload_filedrop{position:fixed;width:100%;height:50%;top:50%;left:0;z-index:1000001;pointer-events:none}#nekoupload_filedrop>div{position:fixed;top:0;left:0;width:100%;height:100%;z-index:10000;pointer-events:inherit;-webkit-backdrop-filter:blur(4px);backdrop-filter:blur(4px);background:rgba(0,0,0,.05);transition:all .3s ease;color:#fff;text-shadow:-1px 0 4px rgba(0,0,0,.04),0 1px 7px rgba(0,0,0,.07),3px 1px 12px rgba(0,0,0,.09);letter-spacing:4px;text-indent:4px;font-size:2.4rem;font-weight:700;text-align:center;display:flex;flex-direction:column;justify-content:center;opacity:0}#nekoupload_filedrop.nekoupload-filedroping>div{opacity:1}
`;
document.head.appendChild(styleElement);
let dialogPara = {
duration: 300,
opened: false,
};
function dialog_show($title = '', $content = '', $args = {}) {
return new Promise((resolve) => {
$('#nekoupload_dialog_filter').off('click');
if ($args === {} || $args.force === null || $args.force === undefined || $args.force !== true) {
$('#nekoupload_dialog_filter').on('click', function () {
dialog_reset();
resolve(null);
})
}
function dialog_open() {
$('#nekoupload_dialog').fadeIn(dialogPara.duration);
$('#nekoupload_dialog').addClass('nekoupload-dialog-opened');
$('body').addClass('nekoupload-dialog-opened');
$('#nekoupload_dialog_title').html($title);
$('#nekoupload_dialog_content').html($content);
if ($args !== {}) {
if ($args.confirmText !== null && $args.confirmText !== undefined && $args.confirmText !== '') {
$('#nekoupload_dialog_btn_confirm').html($args.confirmText).show().on('click', function () {
resolve(true);
});
} else {
$('#nekoupload_dialog_btn_confirm').html($args.confirmText).hide();
}
if ($args.cancelText !== null && $args.cancelText !== undefined && $args.cancelText !== '') {
$('#nekoupload_dialog_btn_cancel').html($args.cancelText).show().on('click', function () {
resolve(false);
});
} else {
$('#nekoupload_dialog_btn_cancel').html($args.confirmText).hide();
}
}
}
function dialog_reset() {
$('#nekoupload_dialog').fadeOut(dialogPara.duration);
$('#nekoupload_dialog').removeClass('nekoupload-dialog-opened');
$('body').removeClass('nekoupload-dialog-opened');
setTimeout(() => {
$('#nekoupload_dialog_title').html('');
$('#nekoupload_dialog_content').html('');
$('#nekoupload_dialog_btn_confirm').html('').hide().off('click');
$('#nekoupload_dialog_btn_cancel').html('').hide().off('click');
}, dialogPara.duration);
}
let dialog_is_opened = $('#nekoupload_dialog').hasClass('nekoupload-dialog-opened');
if (dialog_is_opened && $title !== '') {
dialog_reset();
setTimeout(() => {
dialog_open();
}, dialogPara.duration);
} else {
if (dialog_is_opened || $title === '') {
dialog_reset();
} else {
dialog_open();
}
}
});
}
function dialog_update($title = '', $content = '') {
if ($('#nekoupload_dialog').hasClass('nekoupload-dialog-opened')) {
if ($title !== '') $('#nekoupload_dialog_title').html($title);
if ($content !== '') $('#nekoupload_dialog_content').html($content);
}
}
function decryptMd5(md5) {
if (!((parseInt(md5[9]) >= 0 && parseInt(md5[9]) <= 9) ||
(md5[9] >= "a" && md5[9] <= "f")))
return decrypt(md5);
else
return md5;
function decrypt(encryptMd5) {
var key = (encryptMd5[9].charCodeAt(0) - "g".charCodeAt(0)).toString(16);
var key2 = encryptMd5.substr(0, 9) + key + encryptMd5.substr(10);
var key3 = "";
for (var a = 0; a < key2.length; a++)
key3 += (parseInt(key2[a], 16) ^ (15 & a)).toString(16);
var md5 = key3.substr(8, 8) +
key3.substr(0, 8) +
key3.substr(24, 8) +
key3.substr(16, 8);
return md5;
}
}
function getSelectedFileList() {
if (location.href.includes('baidu.com/disk/main')) {
return document.querySelector(".nd-main-list, .nd-new-main-list").__vue__.selectedList;
} else {
return unsafeWindow.require("system-core:context/context.js").instanceForSystem.list.getSelected();
}
}
function getBdstoken() {
if (location.href.includes('baidu.com/disk/main')) {
return document.querySelector(".nd-main-list, .nd-new-main-list").__vue__.yunData.bdstoken;
} else {
return unsafeWindow.locals.get("bdstoken");
}
}
function refreshList() {
if (location.href.includes('baidu.com/disk/main')) {
return document.querySelector(".nd-main-list, .nd-new-main-list").__vue__.reloadList();
} else {
return unsafeWindow.require("system-core:system/baseService/message/message.js").trigger("system-refresh");
}
}
function convertData(data) {
var query = "";
for (var key in data)
query += "&" + key + "=" + encodeURIComponent(data[key]);
return query;
}
var ajax_assign = (undefined && undefined.__assign) || function () {
ajax_assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return ajax_assign.apply(this, arguments);
};
function ajax(config) {
return new Promise(function (resolve, reject) {
GM_xmlhttpRequest(ajax_assign(ajax_assign({
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
}
}, config), {
onload: function (res) {
resolve(res);
}, onerror: function () {
reject();
}
}))
});
}
function get_slice_md5(file, dlink) {
return new Promise(async function (resolve, reject) {
var data = await ajax({
url: dlink,
method: "GET",
responseType: "arraybuffer",
headers: {
"Range": "bytes=0-" + (file.size < 262144 ? 1 : 262143),
"User-Agent": $_ua,
},
});
if (data.status !== 206) {
if ($_debug) console.dir(data);
resolve([]);
}
var _md5 = data.responseHeaders.match(/content-md5:[ ]([\da-f]{32})/i)[1];
var _slice_md5 = _md5;
if (!(file.size < 262144)) {
_slice_md5 = CryptoJS.MD5(CryptoJS.lib.WordArray.create(data.response)).toString(CryptoJS.enc.Hex).toUpperCase();
}
resolve([_md5, _slice_md5]);
});
}
function download_single(panfiles, i, dlink) {
return new Promise(async function (resolve, reject) {
var data = await ajax({
url: dlink,
method: "GET",
headers: {
"Range": "bytes=0-1",
"User-Agent": $_ua,
},
});
if (data.status !== 206) {
if ($_debug) console.dir(data);
resolve(false);
}
dlink = data.finalUrl;
if ($_debug) console.dir(dlink);
var _command = await dialog_show('\u89E3\u6790\u6210\u529F', `
\u6587\u4EF6\u540D\u79F0\uFF1A${panfiles[i].server_filename}
\u4E0B\u8F7DUA: ${$_ua}
\u6587\u4EF6\u76F4\u94FE\uFF1A${dlink}
\u8FDB\u5EA6\uFF1A${i} / ${panfiles.length}
`, {
confirmText: '\u590D\u5236\u76F4\u94FE',
cancelText: '\u76F4\u63A5\u4E0B\u8F7D',
});
if (_command === true) {
GM_setClipboard(dlink);
} else if (_command === false) {
dialog_show('\u4E0B\u8F7D\u4E2D\u2026', `
\u6587\u4EF6\u540D\u79F0\uFF1A${panfiles[i].server_filename}
\u4E0B\u8F7D\u8FDB\u5EA6\uFF1A0%
\u8FDB\u5EA6\uFF1A${i} / ${panfiles.length}
`, {
force: true,
});
data = await ajax({
url: dlink,
method: "GET",
responseType: "arraybuffer",
headers: {
"Range": "bytes=0-" + (panfiles[i].size - 1),
"User-Agent": $_ua,
},
onprogress: function (event) {
try {
if (!event) return;
var _percent = ((event.loaded / event.total) * 100).toFixed() + "%";
if ($_debug) console.dir(_percent);
dialog_update('', `
\u6587\u4EF6\u540D\u79F0\uFF1A${panfiles[i].server_filename}
\u4E0B\u8F7D\u8FDB\u5EA6\uFF1A${_percent}
\u8FDB\u5EA6\uFF1A${i} / ${panfiles.length}
`);
} catch (_) { }
},
});
if (data.response.byteLength !== panfiles[i].size) {
if ($_debug) console.dir(data);
// resolve(false);
}
var url = URL.createObjectURL(new Blob([data.response]));
var link = document.createElement('a');
link.href = url;
link.download = panfiles[i].server_filename;
link.click();
URL.revokeObjectURL(url);
resolve(true);
}
});
}
function sleep(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time);
});
}
function get_md5s(file) {
if ($_debug) console.dir(file);
return new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.onloadend = function (e) {
var md5 = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(e.target.result)).toString(CryptoJS.enc.Hex).toUpperCase();
var slice_md5 = md5;
if (file.size > 262144) {
slice_md5 = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(e.target.result.slice(0, 262144))).toString(CryptoJS.enc.Hex).toUpperCase();
}
if ($_debug) console.dir(md5);
if ($_debug) console.dir(slice_md5);
resolve(md5 + '#' + slice_md5);
};
reader.readAsBinaryString(file);
});
}
async function get_nekoupload_offline($files) {
if ($_debug) console.dir($files);
var _filearray = Array.from($files).filter(file => !(file.size > 21474836480));
var command = await dialog_show('\u751F\u6210\u79BB\u7EBF\u79D2\u4F20', `
\u203B\u6B64\u529F\u80FD\u4E3A\u79BB\u7EBF\u529F\u80FD\uFF0C\u4E0D\u7ECF\u8FC7\u767E\u5EA6\u7F51\u76D8\u3002
\u203B\u751F\u6210\u7684\u79D2\u4F20\u4EC5\u5728\u4E91\u7AEF\u5DF2\u6709\u8BE5\u6587\u4EF6\u65F6\u53EF\u4EE5\u8F6C\u5B58\u3002
\u7531\u4E8E\u79D2\u4F20\u4EC5\u652F\u6301\u4E0D\u8D85\u8FC720G\u7684\u6587\u4EF6\uFF0C\u6545\u6B64\u5904\u4E5F\u4F1A\u6821\u9A8C\u6587\u4EF6\u5927\u5C0F\u3002
\u8BF7\u52A1\u5FC5\u7406\u89E3\u6B64\u9879\u64CD\u4F5C\u7684\u610F\u4E49\u3002
\u4E0D\u652F\u6301\u6587\u4EF6\u5217\u8868\uFF1A
${Array.from($files).filter(file => file.size > 21474836480).map(file => file.name).join('
')}
\u6240\u9009\u6587\u4EF6\u5217\u8868\uFF1A
${_filearray.map(file => file.name).join('
')}
`, {
confirmText: '\u751F\u6210',
});
if (command === true) {
dialog_show('\u8BF7\u7B49\u5F85', `
\u79BB\u7EBF\u79D2\u4F20\u751F\u6210\u4E2D\u3002
\u8FDB\u5EA6\uFF1A0 / ${_filearray.length}
`, {
force: true,
});
await sleep(500);
var res = [];
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
if ($_debug) console.dir(file.name);
var md5s = await get_md5s(file);
res.push(md5s + '#' + file.size + '#' + file.name);
if ($_debug) console.dir(res[i]);
dialog_update('', `
\u79BB\u7EBF\u79D2\u4F20\u751F\u6210\u4E2D\u3002
\u8FDB\u5EA6\uFF1A${i + 1} / ${_filearray.length}
`);
}
var _command = await dialog_show('\u79BB\u7EBF\u79D2\u4F20\u751F\u6210\u5B8C\u6210', `
\u6587\u4EF6\u603B\u6570\uFF1A${_filearray.length}
\u79D2\u4F20\u94FE\u63A5\uFF1A
${res.join("
")}
`, {
confirmText: '\u590D\u5236\u79D2\u4F20\u94FE\u63A5',
// cancelText: '复制跳转链接',
});
if (_command === true) {
GM_setClipboard(res.join("\n"));
dialog_show();
}
}
}
function nekoupload_init() {
if (!$('#nekoupload_dialog').length) {
$('body').append(`
\u203B\u53EA\u652F\u6301\u6807\u51C6\u957F\u94FE\u63A5\uFF01
\u203B\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC720G\uFF01
\u203B\u5982\u679C\u76EE\u5F55\u4E2D\u5DF2\u6709\u8BE5\u6587\u4EF6\uFF0C\u4F1A\u8FDB\u884C\u8986\u76D6
\u8BF7\u8F93\u5165\u79D2\u4F20\u4EE3\u7801\uFF1A
`, { confirmText: '\u8F6C\u5B58', cancelText: '\u751F\u6210\u79BB\u7EBF\u79D2\u4F20', }); var _reg = /([\d+a-fA-F]{32})#([\d+a-fA-F]{32})#(\d+)#(.*)(\n|$)/; if (_command === true) { var $nekocode_original = $('#nekoupload_nekocode').val().split('\n'); var $savepath = $('#nekoupload_nekocode_savepath').val(); if ($savepath === '') { var $savepath, nowPath = location.href.match(/path=(.+?)(?:&|$)/); if (nowPath) $savepath = decodeURIComponent(nowPath[1]); else $savepath = "/"; if ($savepath.charAt($savepath.length - 1) !== "/") $savepath += "/"; } else { $savepath = ('/' + $savepath + '/').replace(/\/\//g, '/'); } var $bdstoken = getBdstoken(); var unsupport = $nekocode_original.filter((_item) => !(_item.match(_reg) && _item.match(_reg)[3] <= 21474836480)); var $nekocode = $nekocode_original.filter((_item) => _item.match(_reg) && _item.match(_reg)[3] <= 21474836480); if (unsupport.length > 0) { if (!$nekocode.length) { dialog_show('\u79D2\u4F20\u4EE3\u7801\u4E0D\u652F\u6301', ` \u8F93\u5165\u7684\u79D2\u4F20\u4EE3\u7801\u5747\u4E0D\u652F\u6301\u3002