`;
dom = '
' + dom + '
';
Swal.fire({
title: '助手配置',
html: dom,
icon: 'info',
showCloseButton: true,
showConfirmButton: false,
footer: pan.footer,
}).then(() => {
message.success('设置成功!');
history.go(0);
});
doc.on('click', '.listener-color', async (e) => {
base.setValue('setting_theme_color', e.target.dataset.color);
message.success('设置成功!');
history.go(0);
});
doc.on('input', '.listener-domain', async (e) => {
base.setValue('setting_rpc_domain', e.target.value);
});
doc.on('input', '.listener-port', async (e) => {
base.setValue('setting_rpc_port', e.target.value);
});
doc.on('input', '.listener-path', async (e) => {
base.setValue('setting_rpc_path', e.target.value);
});
doc.on('input', '.listener-token', async (e) => {
base.setValue('setting_rpc_token', e.target.value);
});
doc.on('input', '.listener-dir', async (e) => {
base.setValue('setting_rpc_dir', e.target.value);
});
doc.on('change', '.listener-terminal', async (e) => {
base.setValue('setting_terminal_type', e.target.value);
});
},
registerMenuCommand() {
GM_registerMenuCommand('⚙️ 设置', () => {
this.showSetting();
});
},
createTip() {
$('body').append('
');
doc.on('mouseenter mouseleave', '.listener-tip', (e) => {
if (e.type === 'mouseenter') {
let filename = e.currentTarget.innerText;
let size = e.currentTarget.dataset.size;
let tip = `${filename}
${size}`;
$(e.currentTarget).css({opacity: '0.5'});
$('.pl-tooltip').html(tip).css({
'left': e.pageX + 10 + 'px',
'top': e.pageY - e.currentTarget.offsetTop > 14 ? e.pageY + 'px' : e.pageY + 20 + 'px'
}).show();
} else {
$(e.currentTarget).css({opacity: '1'});
$('.pl-tooltip').hide(0);
}
});
},
createLoading() {
return $('
');
},
createDownloadIframe() {
let $div = $('
');
let $iframe = $('
');
$div.append($iframe);
$('body').append($div);
},
getMirrorList(link, mirror, thread = 2) {
let host = new URL(link).host;
let mirrors = [];
for (let i = 0; i < mirror.length; i++) {
for (let j = 0; j < thread; j++) {
let item = link.replace(host, mirror[i]) + '&'.repeat(j);
mirrors.push(item);
}
}
return mirrors.join('\n');
},
listenElement(element, callback) {
const checkInterval = 500; // 检查元素的间隔时间(毫秒)
let wasElementFound = false; // 用于跟踪元素是否之前已经找到
function checkElement() {
if (document.querySelector(element)) {
wasElementFound = true;
callback();
} else if (wasElementFound) {
wasElementFound = false; // 元素消失后重置标志
}
setTimeout(checkElement, checkInterval);
}
checkElement();
},
addPanLinkerStyle() {
color = base.getValue('setting_theme_color');
let css = `
body::-webkit-scrollbar { display: none }
::-webkit-scrollbar { width: 6px; height: 10px }
::-webkit-scrollbar-track { border-radius: 0; background: none }
::-webkit-scrollbar-thumb { background-color: rgba(85,85,85,.4) }
::-webkit-scrollbar-thumb,::-webkit-scrollbar-thumb:hover { border-radius: 5px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.2) }
::-webkit-scrollbar-thumb:hover { background-color: rgba(85,85,85,.3) }
.swal2-popup { font-size: 16px !important; }
.pl-popup { font-size: 12px !important; }
.pl-popup a { color: ${color} !important; }
.pl-header { padding: 0!important;align-items: flex-start!important; border-bottom: 1px solid #eee!important; margin: 0 0 10px!important; padding: 0 0 5px!important; }
.pl-title { font-size: 16px!important; line-height: 1!important;white-space: nowrap!important; text-overflow: ellipsis!important;}
.pl-content { padding: 0 !important; font-size: 12px!important; }
.pl-main { max-height: 400px;overflow-y:scroll; }
.pl-footer {font-size: 12px!important;justify-content: flex-start!important; margin: 10px 0 0!important; padding: 5px 0 0!important; color: #f56c6c!important; }
.pl-item { display: flex; align-items: center; line-height: 22px; }
.pl-item-name { flex: 0 0 150px; text-align: left;margin-right: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor:default; }
.pl-item-link { flex: 1; overflow: hidden; text-align: left; white-space: nowrap; text-overflow: ellipsis;cursor:pointer }
.pl-item-btn { background: ${color}; padding: 4px 5px; border-radius: 3px; line-height: 1; cursor: pointer; color: #fff; }
.pl-item-tip { display: flex; justify-content: space-between;flex: 1; }
.pl-back { width: 70px; background: #ddd; border-radius: 3px; cursor:pointer; margin:1px 0; }
.pl-ext { display: inline-block; width: 44px; background: #999; color: #fff; height: 16px; line-height: 16px; font-size: 12px; border-radius: 3px;}
.pl-retry {padding: 3px 10px; background: #cc3235; color: #fff; border-radius: 3px; cursor: pointer;}
.pl-browserdownload { padding: 3px 10px; background: ${color}; color: #fff; border-radius: 3px; cursor: pointer;}
.pl-item-progress { display:flex;flex: 1;align-items:center}
.pl-progress { display: inline-block;vertical-align: middle;width: 100%; box-sizing: border-box;line-height: 1;position: relative;height:15px; flex: 1}
.pl-progress-outer { height: 15px;border-radius: 100px;background-color: #ebeef5;overflow: hidden;position: relative;vertical-align: middle;}
.pl-progress-inner{ position: absolute;left: 0;top: 0;background-color: #409eff;text-align: right;border-radius: 100px;line-height: 1;white-space: nowrap;transition: width .6s ease;}
.pl-progress-inner-text { display: inline-block;vertical-align: middle;color: #d1d1d1;font-size: 12px;margin: 0 5px;height: 15px}
.pl-progress-tip{ flex:1;text-align:right}
.pl-progress-how{ flex: 0 0 90px; background: #ddd; border-radius: 3px; margin-left: 10px; cursor: pointer; text-align: center;}
.pl-progress-stop{ flex: 0 0 50px; padding: 0 10px; background: #cc3235; color: #fff; border-radius: 3px; cursor: pointer;margin-left:10px;height:20px}
.pl-progress-inner-text:after { display: inline-block;content: "";height: 100%;vertical-align: middle;}
.pl-btn-primary { background: ${color}; border: 0; border-radius: 4px; color: #ffffff; cursor: pointer; font-size: 12px; outline: none; display:flex; align-items: center; justify-content: center; margin: 2px 0; padding: 6px 0;transition: 0.3s opacity; }
.pl-btn-primary:hover { opacity: 0.9;transition: 0.3s opacity; }
.pl-btn-success { background: #55af28; animation: easeOpacity 1.2s 2; animation-fill-mode:forwards }
.pl-btn-info { background: #606266; }
.pl-btn-warning { background: #da9328; }
.pl-btn-warning { background: #da9328; }
.pl-btn-danger { background: #cc3235; }
.ali-button {display: inline-flex;align-items: center;justify-content: center;border: 0 solid transparent;border-radius: 5px;box-shadow: 0 0 0 0 transparent;width: fit-content;white-space: nowrap;flex-shrink: 0;font-size: 14px;line-height: 1.5;outline: 0;touch-action: manipulation;transition: background .3s ease,color .3s ease,border .3s ease,box-shadow .3s ease;color: #fff;background: rgb(99 125 255);margin-left: 20px;padding: 1px 12px;position: relative; cursor:pointer; height: 32px;}
.ali-button:hover {background: rgb(122, 144, 255)}
.tianyi-button {margin-right: 20px; padding: 4px 12px; border-radius: 4px; color: #fff; font-size: 12px; border: 1px solid #0073e3; background: #2b89ea; cursor: pointer; position: relative;}
.tianyi-button:hover {border-color: #1874d3; background: #3699ff;}
.yidong-button {float: left; position: relative; margin: 20px 24px 20px 0; width: 98px; height: 36px; background: #3181f9; border-radius: 2px; font-size: 14px; color: #fff; line-height: 39px; text-align: center; cursor: pointer;}
.yidong-share-button {display: inline-block; position: relative; font-size: 14px; line-height: 36px; height: 36px; text-align: center; color: #fff; border: 1px solid #5a9afa; border-radius: 2px; padding: 0 24px; margin-left: 24px; background: #3181f9; cursor: pointer;}
.yidong-button:hover {background: #2d76e5;}
.xunlei-button {display: inline-flex;align-items: center;justify-content: center;border: 0 solid transparent;border-radius: 5px;box-shadow: 0 0 0 0 transparent;width: fit-content;white-space: nowrap;flex-shrink: 0;font-size: 14px;line-height: 1.5;outline: 0;touch-action: manipulation;transition: background .3s ease,color .3s ease,border .3s ease,box-shadow .3s ease;color: #fff;background: #3f85ff;margin-left: 12px;padding: 0px 12px;position: relative; cursor:pointer; height: 36px;}
.xunlei-button:hover {background: #619bff}
.quark-button {display: inline-flex; align-items: center; justify-content: center; border: 1px solid #ddd; border-radius: 8px; white-space: nowrap; flex-shrink: 0; font-size: 14px; line-height: 1.5; outline: 0; color: #333; background: #fff; margin-right: 10px; padding: 0px 14px; position: relative; cursor: pointer; height: 36px;}
.quark-button:hover { background:#f6f6f6 }
.pl-dropdown-menu {position: absolute;right: 0;top: 30px;padding: 5px 0;color: rgb(37, 38, 43);background: #fff;z-index: 999;width: 102px;border: 1px solid #ddd;border-radius: 10px; box-shadow: 0 0 1px 1px rgb(28 28 32 / 5%), 0 8px 24px rgb(28 28 32 / 12%);}
.pl-dropdown-menu-item { height: 30px;display: flex;align-items: center;justify-content: center;cursor:pointer }
.pl-dropdown-menu-item:hover { background-color: rgba(132,133,141,0.08);}
.pl-button .pl-dropdown-menu { display: none; }
.pl-button:hover .pl-dropdown-menu { display: block!important; }
.pl-button-init { opacity: 0.5; animation: easeInitOpacity 1.2s 3; animation-fill-mode:forwards }
@keyframes easeInitOpacity { from { opacity: 0.5; } 50% { opacity: 1 } to { opacity: 0.5; } }
@keyframes easeOpacity { from { opacity: 1; } 50% { opacity: 0.35 } to { opacity: 1; } }
.element-clicked { opacity: 0.5; }
.pl-extra { margin-top: 10px;display:flex}
.pl-extra button { flex: 1}
.pointer { cursor:pointer }
.pl-setting-label { display: flex;align-items: center;justify-content: space-between;padding-top: 10px; }
.pl-label { flex: 0 0 100px;text-align:left; }
.pl-input { flex: 1; padding: 8px 10px; border: 1px solid #c2c2c2; border-radius: 5px; font-size: 14px }
.pl-color { flex: 1;display: flex;flex-wrap: wrap; margin-right: -10px;}
.pl-color-box { width: 35px;height: 35px;margin:10px 10px 0 0;; box-sizing: border-box;border:1px solid #fff;cursor:pointer }
.pl-color-box.checked { border:3px dashed #111!important }
.pl-close:focus { outline: 0; box-shadow: none; }
.tag-danger {color:#cc3235;margin: 0 5px;}
.pl-tooltip { position: absolute; color: #ffffff; max-width: 600px; font-size: 12px; padding: 5px 10px; background: #333; border-radius: 5px; z-index: 110000; display:none; word-break: break-all;}
@keyframes load { 0% { transform: rotate(0deg) } 100% { transform: rotate(360deg) } }
.pl-loading-box > div > div { position: absolute;border-radius: 50%;}
.pl-loading-box > div > div:nth-child(1) { top: 9px;left: 9px;width: 82px;height: 82px;background: #ffffff;}
.pl-loading-box > div > div:nth-child(2) { top: 14px;left: 38px;width: 25px;height: 25px;background: #666666;animation: load 1s linear infinite;transform-origin: 12px 36px;}
.pl-loading { width: 16px;height: 16px;display: inline-block;overflow: hidden;background: none;}
.pl-loading-box { width: 100%;height: 100%;position: relative;transform: translateZ(0) scale(0.16);backface-visibility: hidden;transform-origin: 0 0;}
.pl-loading-box div { box-sizing: content-box; }
.swal2-container { z-index:100000!important; }
body.swal2-height-auto { height: inherit!important; }
.btn-operate .btn-main { display:flex; align-items:center; }
`;
this.addStyle('panlinker-style', 'style', css);
}
};
let baidu = {
_getExtra() {
let seKey = decodeURIComponent(base.getCookie('BDCLND'));
return '{' + '"sekey":"' + seKey + '"' + "}";
},
_getSurl() {
let reg = /(?<=s\/|surl=)([a-zA-Z0-9_-]+)/g;
if (reg.test(location.href)) {
return location.href.match(reg)[0];
}
return '';
},
_getFidList() {
let fidlist = [];
selectList.forEach(v => {
if (+v.isdir === 1) return;
fidlist.push(v.fs_id);
});
return '[' + fidlist + ']';
},
_resetData() {
progress = {};
$.each(request, (key) => {
(request[key]).abort();
});
$.each(ins, (key) => {
clearInterval(ins[key]);
});
idm = {};
ins = {};
request = {};
},
setBDUSS() {
try {
GM_cookie && GM_cookie('list', {name: 'BDUSS'}, (cookies, error) => {
if (!error) {
let BDUSS = cookies?.[0]?.value;
if (BDUSS) {
base.setStorage("baiduyunPlugin_BDUSS", {BDUSS});
}
}
});
} catch (e) {
}
},
getBDUSS() {
let baiduyunPlugin_BDUSS = base.getStorage('baiduyunPlugin_BDUSS') ? base.getStorage('baiduyunPlugin_BDUSS') : '{"baiduyunPlugin_BDUSS":""}';
return baiduyunPlugin_BDUSS.BDUSS || '';
},
convertLinkToAria(link, filename, ua) {
let BDUSS = this.getBDUSS();
if (!!BDUSS) {
filename = base.fixFilename(filename);
return encodeURIComponent(`aria2c "${link}" --out "${filename}" --header "User-Agent: ${ua}" --header "Cookie: BDUSS=${BDUSS}"`);
}
return {
link: pan.assistant,
text: pan.init[5]
};
},
convertLinkToBC(link, filename, ua) {
let BDUSS = this.getBDUSS();
if (!!BDUSS) {
let cookie = `BDUSS=${BDUSS}`;
let bc = `AA/${encodeURIComponent(filename)}/?url=${encodeURIComponent(link)}&cookie=${encodeURIComponent(cookie)}&user_agent=${encodeURIComponent(ua)}ZZ`;
return encodeURIComponent(`bc://http/${base.e(bc)}`);
}
return {
link: pan.assistant,
text: pan.init[5]
};
},
convertLinkToCurl(link, filename, ua) {
let BDUSS = this.getBDUSS();
if (!!BDUSS) {
let terminal = base.getValue('setting_terminal_type');
filename = base.fixFilename(filename);
return encodeURIComponent(`${terminal !== 'wp' ? 'curl' : 'curl.exe'} -L -C - "${link}" -o "${filename}" -A "${ua}" -b "BDUSS=${BDUSS}"`);
}
return {
link: pan.assistant,
text: pan.init[5]
};
},
addPageListener() {
function _factory(e) {
let target = $(e.target);
let item = target.parents('.pl-item');
let link = item.find('.pl-item-link');
let progress = item.find('.pl-item-progress');
let tip = item.find('.pl-item-tip');
return {
item, link, progress, tip, target,
};
}
function _reset(i) {
ins[i] && clearInterval(ins[i]);
request[i] && request[i].abort();
progress[i] = 0;
idm[i] = false;
}
doc.on('mouseenter mouseleave click', '.pl-button.g-dropdown-button', (e) => {
if (e.type === 'mouseleave') {
$(e.currentTarget).removeClass('button-open');
} else {
$(e.currentTarget).addClass('button-open');
$(e.currentTarget).find('.pl-dropdown-menu').show();
}
});
doc.on('mouseleave', '.pl-button.g-dropdown-button .pl-dropdown-menu', (e) => {
$(e.currentTarget).hide();
});
doc.on('click', '.pl-button-mode', (e) => {
mode = e.target.dataset.mode;
Swal.showLoading();
this.getPCSLink();
});
doc.on('click', '.listener-link-api', async (e) => {
e.preventDefault();
let o = _factory(e);
let $width = o.item.find('.pl-progress-inner');
let $text = o.item.find('.pl-progress-inner-text');
let filename = o.link[0].dataset.filename;
let index = o.link[0].dataset.index;
_reset(index);
base.get(o.link[0].dataset.link, {"User-Agent": pan.ua}, 'blob', {filename, index});
ins[index] = setInterval(() => {
let prog = +progress[index] || 0;
let isIDM = idm[index] || false;
if (isIDM) {
o.tip.hide();
o.progress.hide();
o.link.text('已成功唤起IDM,请查看IDM下载框!').animate({opacity: '0.5'}, "slow").show();
clearInterval(ins[index]);
idm[index] = false;
} else {
o.link.hide();
o.tip.hide();
o.progress.show();
$width.css('width', prog + '%');
$text.text(prog + '%');
if (prog === 100) {
clearInterval(ins[index]);
progress[index] = 0;
o.item.find('.pl-progress-stop').hide();
o.item.find('.pl-progress-tip').html('下载完成,正在弹出浏览器下载框!');
}
}
}, 500);
});
doc.on('click', '.listener-retry', async (e) => {
let o = _factory(e);
o.tip.hide();
o.link.show();
});
doc.on('click', '.listener-how', async (e) => {
let o = _factory(e);
let index = o.link[0].dataset.index;
if (request[index]) {
request[index].abort();
clearInterval(ins[index]);
o.progress.hide();
o.tip.show();
}
});
doc.on('click', '.listener-stop', async (e) => {
let o = _factory(e);
let index = o.link[0].dataset.index;
if (request[index]) {
request[index].abort();
clearInterval(ins[index]);
o.tip.hide();
o.progress.hide();
o.link.show(0);
}
});
doc.on('click', '.listener-back', async (e) => {
let o = _factory(e);
o.tip.hide();
o.link.show();
});
doc.on('click', '.listener-link-aria, .listener-copy-all', (e) => {
e.preventDefault();
if (!e.target.dataset.link) {
$(e.target).removeClass('listener-copy-all').addClass('pl-btn-danger').html(`${pan.init[5]}👉
点击此处安装👈`);
} else {
base.setClipboard(decodeURIComponent(e.target.dataset.link));
$(e.target).text('复制成功,快去粘贴吧!').animate({opacity: '0.5'}, "slow");
}
});
doc.on('click', '.listener-link-rpc', async (e) => {
let target = $(e.currentTarget);
target.find('.icon').remove();
target.find('.pl-loading').remove();
target.prepend(base.createLoading());
let res = await this.sendLinkToRPC(e.currentTarget.dataset.filename, e.currentTarget.dataset.link);
if (res === 'success') {
$('.listener-rpc-task').show();
target.removeClass('pl-btn-danger').html('发送成功,快去看看吧!').animate({opacity: '0.5'}, "slow");
} else if (res === 'assistant') {
target.addClass('pl-btn-danger').html(`${pan.init[5]}👉
点击此处安装👈`);
} else {
target.addClass('pl-btn-danger').text('发送失败,请检查您的RPC配置信息!').animate({opacity: '0.5'}, "slow");
}
});
doc.on('click', '.listener-send-rpc', (e) => {
$('.listener-link-rpc').click();
$(e.target).text('发送完成,发送结果见上方按钮!').animate({opacity: '0.5'}, "slow");
});
doc.on('click', '.listener-open-setting', () => {
base.showSetting();
});
doc.on('click', '.listener-rpc-task', () => {
let rpc = JSON.stringify({
domain: base.getValue('setting_rpc_domain'),
port: base.getValue('setting_rpc_port'),
}), url = `${pan.d}/?rpc=${base.e(rpc)}#${base.getValue('setting_rpc_token')}`;
GM_openInTab(url, {active: true});
});
document.documentElement.addEventListener('mouseup', (e) => {
if (e.target.nodeName === 'A' && ~e.target.className.indexOf('pl-a')) {
e.stopPropagation();
}
}, true);
},
addButton() {
if (!pt) return;
let $toolWrap;
let $button = $(`
`);
if (pt === 'home') $toolWrap = $(pan.btn.home);
if (pt === 'main') {
$toolWrap = $(pan.btn.main);
$button = $(`
`);
}
if (pt === 'share') $toolWrap = $(pan.btn.share);
$toolWrap.prepend($button);
this.setBDUSS();
this.addPageListener();
},
async getToken() {
const openTab = () => {
GM_openInTab(pan.pcs[3], {active: false, insert: true, setParent: true});
base.deleteValue('baidu_access_token');
};
const waitForToken = () => new Promise((resolve) => {
let attempts = 0;
const interval = setInterval(() => {
const token = base.getValue('baidu_access_token');
if (token) {
clearInterval(interval);
resolve(token);
}
attempts++;
if (attempts > 60) {
clearInterval(interval);
resolve('');
}
}, 1000);
});
if (manageHandler === 'Tampermonkey' && base.getMajorVersion(manageVersion) >= 5) {
openTab();
return waitForToken();
}
let res = await base.getFinalUrl(pan.pcs[3]);
if (!res.includes('authorize') && !res.includes('access_token=')) {
openTab();
return waitForToken();
}
if (res.includes('authorize')) {
let html = await base.get(pan.pcs[3], {}, 'text');
let bdstoken = html.match(/name="bdstoken"\s+value="([^"]+)"/)?.[1];
let client_id = html.match(/name="client_id"\s+value="([^"]+)"/)?.[1];
let data = {
grant_permissions_arr: 'netdisk',
bdstoken: bdstoken,
client_id: client_id,
response_type: "token",
display: "page",
grant_permissions: "basic,netdisk"
};
await base.post(pan.pcs[3], base.stringify(data), {
'Content-Type': 'application/x-www-form-urlencoded',
});
let res2 = await base.getFinalUrl(pan.pcs[3]);
let accessToken = res2.match(/access_token=([^&]+)/)?.[1];
accessToken && base.setValue('baidu_access_token', accessToken);
return accessToken;
}
let accessToken = res.match(/access_token=([^&]+)/)?.[1];
accessToken && base.setValue('baidu_access_token', accessToken);
return accessToken;
},
async getPCSLink(maxRequestTime = 1) {
selectList = this.getSelectedList();
let fidList = this._getFidList(), url, res;
if (pt === 'home' || pt === 'main') {
if (selectList.length === 0) {
return message.error('提示:请先勾选要下载的文件!');
}
if (fidList.length === 2) {
return message.error('提示:请打开文件夹后勾选文件!');
}
fidList = encodeURIComponent(fidList);
let accessToken = base.getValue('baidu_access_token') || await this.getToken();
url = `${pan.pcs[0]}&fsids=${fidList}&access_token=${accessToken}`;
res = await base.get(url, {"User-Agent": pan.ua});
}
if (pt === 'share') {
this.getShareData();
if (!params.bdstoken) {
return message.error('提示:请先登录网盘!');
}
if (selectList.length === 0) {
return message.error('提示:请先勾选要下载的文件!');
}
if (fidList.length === 2) {
return message.error('提示:请打开文件夹后勾选文件!');
}
let dialog = await Swal.fire({
toast: true,
icon: 'info',
title: `提示:请将文件
[保存到网盘]👉前往
[我的网盘]中下载!`,
showConfirmButton: true,
confirmButtonText: '点击保存',
position: 'top',
});
if (dialog.isConfirmed) {
$('.tools-share-save-hb')[0].click();
}
return;
}
if (res.errno === 0) {
let html = this.generateDom(res.list);
this.showMainDialog(pan[mode][0], html, pan[mode][1]);
} else if (res.errno === 112) {
return message.error('提示:页面过期,请刷新重试!');
} else if (res.errno === 9019) {
maxRequestTime--;
await this.getToken();
if (maxRequestTime > 0) {
await this.getPCSLink(maxRequestTime);
} else {
message.error('提示:获取下载链接失败!请刷新网页后重试!');
}
} else {
base.deleteValue('baidu_access_token');
message.error('提示:获取下载链接失败!请刷新网页后重试!');
}
},
generateDom(list) {
let content = '
';
let alinkAllText = '';
base.sortByName(list);
list.forEach((v, i) => {
if (v.isdir === 1) return;
let filename = v.server_filename || v.filename;
let ext = base.getExtension(filename);
let size = base.sizeFormat(v.size);
let dlink = v.dlink + '&access_token=' + base.getValue('baidu_access_token');
if (mode === 'api') {
content += `
${filename}
${dlink}
若没有弹出IDM下载框,找到IDM 选项 -> 文件类型 -> 第一个框 中添加后缀 ${ext},详见此处 返回
取消下载
未发现IDM,使用自带浏览器下载
如何唤起IDM?
`;
}
if (mode === 'aria') {
let alink = this.convertLinkToAria(dlink, filename, pan.ua);
if (typeof (alink) === 'object') {
content += `
`;
} else {
alinkAllText += alink + '\r\n';
content += `
`;
}
}
if (mode === 'rpc') {
content += `
`;
}
if (mode === 'curl') {
let alink = this.convertLinkToCurl(dlink, filename, pan.ua);
if (typeof (alink) === 'object') {
content += `
`;
} else {
alinkAllText += alink + '\r\n';
content += `
`;
}
}
if (mode === 'bc') {
let alink = this.convertLinkToBC(dlink, filename, pan.ua);
if (typeof (alink) === 'object') {
content += `
`;
} else {
content += `
`;
}
}
});
content += '
';
if (mode === 'aria')
content += ``;
if (mode === 'rpc') {
let rpc = base.getValue('setting_rpc_domain') + ':' + base.getValue('setting_rpc_port') + base.getValue('setting_rpc_path');
content += ``;
}
if (mode === 'curl')
content += ``;
return content;
},
async sendLinkToRPC(filename, link) {
let rpc = {
domain: base.getValue('setting_rpc_domain'),
port: base.getValue('setting_rpc_port'),
path: base.getValue('setting_rpc_path'),
token: base.getValue('setting_rpc_token'),
dir: base.getValue('setting_rpc_dir'),
};
let BDUSS = this.getBDUSS();
if (!BDUSS) return 'assistant';
let url = `${rpc.domain}:${rpc.port}${rpc.path}`;
let rpcData = {
id: new Date().getTime(),
jsonrpc: '2.0',
method: 'aria2.addUri',
params: [`token:${rpc.token}`, [link], {
dir: rpc.dir,
out: filename,
header: [`User-Agent: ${pan.ua}`, `Cookie: BDUSS=${BDUSS}`]
}]
};
try {
let res = await base.post(url, rpcData, {"User-Agent": pan.ua}, '');
if (res.result) return 'success';
return 'fail';
} catch (e) {
return 'fail';
}
},
getSelectedList() {
try {
return require('system-core:context/context.js').instanceForSystem.list.getSelected();
} catch (e) {
return document.querySelector('.wp-s-core-pan').__vue__.selectedList;
}
},
getLogid() {
let ut = require("system-core:context/context.js").instanceForSystem.tools.baseService;
return ut.base64Encode(base.getCookie("BAIDUID"));
},
getShareData() {
let res = locals.dump();
params.shareType = 'secret';
params.sign = '';
params.timestamp = '';
params.bdstoken = res.bdstoken.value;
params.channel = 'chunlei';
params.clienttype = 0;
params.web = 1;
params.app_id = 250528;
params.encrypt = 0;
params.product = 'share';
params.logid = this.getLogid();
params.primaryid = res.shareid.value;
params.uk = res.share_uk.value;
params.shareType === 'secret' && (params.extra = this._getExtra());
params.surl = this._getSurl();
},
detectPage() {
let path = location.pathname;
if (/^\/disk\/home/.test(path)) return 'home';
if (/^\/disk\/main/.test(path)) return 'main';
if (/^\/(s|share)\//.test(path)) return 'share';
return '';
return '';
},
showMainDialog(title, html, footer) {
Swal.fire({
title,
html,
footer,
allowOutsideClick: false,
showCloseButton: true,
showConfirmButton: false,
position: 'top',
width,
padding: '15px 20px 5px',
customClass,
}).then(() => {
this._resetData();
});
},
async initPanLinker() {
base.initDefaultConfig();
base.addPanLinkerStyle();
pt = this.detectPage();
let res = await base.post
(`https://api.youxiaohou.com/config/v2?ver=${version}&a=${author}`, {}, {}, 'text');
pan = JSON.parse(base.d(res));
Object.freeze && Object.freeze(pan);
this.addButton();
base.createTip();
base.registerMenuCommand();
},
async initAuthorize() {
let ins = setInterval(() => {
if (/openapi.baidu.com\/oauth\/2.0\/authorize/.test(location.href)) {
let confirmButton = document.querySelector('#auth-allow');
if (confirmButton) {
confirmButton.click();
return;
}
}
if (/openapi.baidu.com\/oauth\/2.0\/login_success/.test(location.href)) {
if (location.href.includes('access_token')) {
let token = location.href.match(/access_token=(.*?)&/)[1];
base.setValue('baidu_access_token', token);
window.close()
}
}
}, 200)
}
};
let main = {
init() {
if (/(pan|yun).baidu.com/.test(location.host)) {
baidu.initPanLinker();
}
if (/openapi.baidu.com\/oauth/.test(location.href)) {
baidu.initAuthorize()
}
}
};
main.init();
})();