// ==UserScript==
// @name (改)网盘直链下载助手
// @namespace https://github.com/syhyz1990/baiduyun
// @version 1.0.9
// @author Hmjz100、油小猴
// @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48cGF0aCBkPSJNMTAzLjYgMTA3LjRjMy41LTIuMiA4LjktNi4xIDEzLjgtMTIuNXM3LjMtMTIuNSA4LjUtMTYuNWMuNS0xLjcgMi4yLTcuNSAyLjItMTQuNyAwLTEwLjEtMy4zLTI1LjEtMTUuNC0zNi44LTE0LjUtMTQtMzIuMS0xNC4zLTM1LjctMTQuMy04IDAtMTUuNyAxLjktMjIuNiA1LjJDNDQgMjMgMzUuNyAzMS40IDMwLjggNDEuN2MtMS4zIDIuOC00IDQuNy03LjEgNS00IC4zLTcuNSA0LjQtOC45IDkuNi0uNSAxLjktMS42IDMuNS0zLjEgNC43QzQuNCA2Ni44IDAgNzUuNyAwIDg1YzAgNi44IDIuMyAxMy4xIDYuMSAxOC4yIDUuNSA3LjQgMTQuMiAxMi4yIDI0IDEyLjJoNDcuMWM0LjQgMCAxMS0uNSAxOC4zLTMuNSAzLjItMS40IDUuOS0zIDguMS00LjV6IiBmaWxsPSIjQTA5OUYwIi8+PHBhdGggZD0iTTExOS44IDY0LjNjLjEtMTcuMS0xMC40LTI4LTEyLjUtMzAuMUM5NSAyMi4xIDc5LjkgMjEuOCA3Ni45IDIxLjhjLTE3LjYgMC0zMy4zIDEwLjUtMzkuOSAyNi43LS42IDEuMy0xLjggMi4zLTMuNCAyLjNoLS40Yy01LjggMC0xMC42IDQuOC0xMC42IDEwLjd2LjVjMCAxLjQtLjggMi42LTEuOSAzLjNDMTMuNCA2OSA4LjggNzYuOCA4LjggODVjMCAxMi4yIDkuOSAyMi4zIDIyLjIgMjIuM2g0NS4yYzMuNi0uMSAxNy42LS45IDI5LjYtMTIgMi45LTIuOCAxMy45LTEzLjcgMTQtMzF6IiBmaWxsPSIjNTc0QUI4Ii8+PHBhdGggZD0iTTExMC44IDU3LjRsLjIgMy4zYzAgMS4zLTEuMSAyLjQtMi4zIDIuNC0xLjMgMC0yLjMtMS4xLTIuMy0yLjRsLS4xLTIuOHYtLjNjMC0xLjIuOS0yLjIgMi4xLTIuM2guM2MuNyAwIDEuMy4zIDEuNy43LS4yLjEuMy41LjQgMS40em0tMy4zLTEwLjNjMCAxLjItMSAyLjMtMi4yIDIuM2gtLjFjLS44IDAtMS42LS41LTItMS4yLTQuNi04LjMtMTMuMy0xMy41LTIyLjgtMTMuNS0xLjIgMC0yLjMtMS0yLjMtMi4ydi0uMWMwLTEuMiAxLTIuMyAyLjItMi4zaC4xYTMwLjM3IDMwLjM3IDAgMCAxIDE1LjggNC40YzQuNiAyLjggOC40IDYuOCAxMS4xIDExLjUuMS4zLjIuNy4yIDEuMXpNODguMyA3My44TDczLjUgOTMuMmMtMS41IDEuOS0zLjUgMy4xLTUuNyAzLjVoLS4yYy0uNC4xLS44LjEtMS4yLjEtLjYgMC0xLjEtLjEtMS42LS4yLTIuMi0uNC00LjItMS43LTUuNi0zLjVMNDQuMyA3My45Yy0yLTIuNi0yLjUtNS40LTEuNC03LjcuMS0uMS4xLS4yLjItLjIgMS4yLTIgMy41LTMuMiA2LjQtMy4yaDYuNnYtNS43YzAtNi44IDQuNy0xMiAxMC45LTEyIDQuOCAwIDguNSAyLjYgMTAuMyA3LjIuNSAxLjMtLjIgMi43LTEuNSAzLjJzLTIuOC0uMS0zLjMtMS40Yy0xLjEtMi43LTIuOS00LTUuNS00LTMuNSAwLTYgMy02IDd2OC4xYzAgLjUtLjIgMS0uNiAxLjQtLjYuNy0xLjcgMS4xLTIuNiAxLjFoLTguNGMtMS4zIDAtMiAuNC0yLjEuNy0uMi40IDAgMS4zLjkgMi40TDYzLjEgOTBjLjkgMS4yIDIuMSAxLjggMy4zIDEuOHMyLjMtLjYgMy4xLTEuN2wxNC44LTE5LjNjLjktMS4xIDEuMS0yIC45LTIuNC0uMi0uMy0uOS0uNy0yLjEtLjdoLTcuNmMtLjkgMC0xLjctLjUtMi4xLTEuMi0uMy0uNC0uNC0uOC0uNC0xLjMgMC0xLjQgMS4xLTIuNSAyLjUtMi41aDcuNmMzLjEgMCA1LjUgMS4zIDYuNiAzLjVsLjMuN2MuNyAyLjEuMSA0LjYtMS43IDYuOXoiIGZpbGw9IiNmZmYiLz48L3N2Zz4=
// @description 一个基于 JavaScript 的网盘文件下载地址获取工具,支持 百度网盘/阿里云盘/天翼云盘/迅雷云盘/夸克网盘/移动网盘 六大网盘 | 基于【网盘直链下载助手】修改自6.2.7版本 | 开源 - 自用 - 去广 | 改界面 - 添功能 - 修Bug | 不仅能够精简网盘界面 还支持修改网盘界面主题颜色!
// @license AGPL-3.0-or-later
// @homepage https://github.com/hmjz100/Online-disk-direct-link-download-assistant/
// @supportURL https://github.com/hmjz100/Online-disk-direct-link-download-assistant/issues
// @compatible Chrome
// @compatible Edge
// @compatible Firefox
// @compatible Safari
// @compatible Opera
// @require https://unpkg.com/jquery@3.6.0/dist/jquery.min.js
// @require https://unpkg.com/sweetalert2@11/dist/sweetalert2.min.js
// @require https://unpkg.com/js-md5@0.7.3/build/md5.min.js
// @resource Swal https://unpkg.com/sweetalert2@11/dist/sweetalert2.min.css
// @resource SwalDark https://unpkg.com/@sweetalert2/theme-dark@5.0.15/dark.min.css
// @match *://pan.baidu.com/disk/home*
// @match *://yun.baidu.com/disk/home*
// @match *://pan.baidu.com/disk/timeline*
// @match *://yun.baidu.com/disk/timeline*
// @match *://pan.baidu.com/disk/main*
// @match *://yun.baidu.com/disk/main*
// @match *://pan.baidu.com/youth/pan/main*
// @match *://yun.baidu.com/youth/pan/main*
// @match *://pan.baidu.com/disk/base*
// @match *://yun.baidu.com/disk/base*
// @match *://pan.baidu.com/s/*
// @match *://pan.baidu.com/aipan/*
// @match *://yun.baidu.com/s/*
// @match *://yun.baidu.com/aipan/*
// @match *://pan.baidu.com/share/*
// @match *://yun.baidu.com/share/*
// @match *://openapi.baidu.com/*
// @match *://www.aliyundrive.com/s/*
// @match *://www.aliyundrive.com/drive*
// @match *://www.alipan.com/s/*
// @match *://www.alipan.com/drive*
// @match *://cloud.189.cn/web/*
// @match *://pan.xunlei.com/*
// @match *://pan.quark.cn/*
// @match *://yun.139.com/*
// @match *://caiyun.139.com/*
// @match *://*.youxiaohou.com/*
// @connect baidu.com
// @connect baidupcs.com
// @connect aliyundrive.com
// @connect aliyundrive.net
// @connect alipan.com
// @connect alicloudccp.com
// @connect 189.cn
// @connect xunlei.com
// @connect quark.cn
// @connect youxiaohou.com
// @connect gcore.jsdelivr.net
// @connect localhost
// @connect *
// @run-at document-idle
// @grant unsafeWindow
// @grant window.close
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_deleteValue
// @grant GM_openInTab
// @grant GM_info
// @grant GM_registerMenuCommand
// @grant GM_cookie
// @grant GM_getResourceText
// ==/UserScript==
(function Panlinker() {
'use strict';
/*
防止代码因其他原因被执行多次
这段代码出自 Via轻插件,作者谷花泰
*/
const key = encodeURIComponent('(改)网盘直链下载助手:主代码');
if (window[key]) return;
window[key] = true;
unsafeWindow.GM = GM_info
/*
网盘直链下载助手
以下代码均改自 网盘直链下载助手,作者油小猴
*/
/* 全局参数 */
let pt = '', selectList = [], params = {}, mode = '', width = '', pan = {}, color = '',
doc = $(document), progress = {}, request = {}, ins = {}, idm = {}, colored = false,
scriptInfo = GM_info.script,
realauthor = scriptInfo.author,
realname = scriptInfo.name,
realversion = scriptInfo.version,
manageHandler = GM_info.scriptHandler,
manageVersion = GM_info.version;
/* 设置选项 */
// Shell类型(用于curl下载)
let terminalType = {
wc: "Microsoft Windows 命令提示符",
wp: "Microsoft Windows PowerShell",
lt: "Linux 终端",
ls: "Linux Shell",
mt: "Apple MacOS 终端",
};
// 使用油小猴服务器
let monkeyServer = {
v1: "使用 [用油小猴服务器 V1 接口]",
v2: "使用 [用油小猴服务器 V2 接口]",
no: "不使用 [用 jsdelivr 连接本项目 Github 仓库]"
};
// 更换 百度网盘新界面/阿里云盘/迅雷云盘/移动云盘 主题颜色
let assistantTheme = {
yes: "更换主题颜色",
no: "不更换主题颜色"
};
/* Sweet Alert 2 */
// 自定义元素 Class 名(于 showMainDialog() 中)
let customClass = {
popup: 'pl-popup',
header: 'pl-header',
title: 'pl-title',
closeButton: 'pl-close',
content: 'pl-content',
input: 'pl-input',
footer: 'pl-footer'
};
// Toast 提示配置
let toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
timer: 3500,
timerProgressBar: true,
showCloseButton: true,
didOpen: function (toast) {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
// Toast 简易调用
let message = {
success: function (text) {
toast.fire({ title: text, icon: 'success' });
},
error: function (text) {
toast.fire({ title: text, icon: 'error' });
},
warning: function (text) {
toast.fire({ title: text, icon: 'warning' });
},
info: function (text) {
toast.fire({ title: text, icon: 'info' });
},
question: function (text) {
toast.fire({ title: text, icon: 'question' });
}
};
/* 基础函数 */
let base = {
// 创建 GreaseMonkey 菜单
registerMenuCommand() {
GM_registerMenuCommand('⚙️ 设置', function () {
base.showSetting();
});
GM_registerMenuCommand('📃 更新', function () {
base.showUpdateLog();
});
GM_registerMenuCommand('🛠️ 调试', function () {
base.showDebug();
});
},
// 取消注册
unRegisterInit(value) {
console.log("【(改)网盘直链下载助手】\n正在注入设置项目...");
message.warning("正在注入设置项目...");
base.setValue('setting_init_code', value);
base.setValue('license', value);
history.go(0)
},
/*-- 对象类型判断
示例:
isType([]) // 输出"array"
isType(123) // 输出"number"
isType(null) // 输出"null"
isType(new Date()) // 输出"date"
*/
isType(obj) {
return Object.prototype.toString.call(obj).replace(/^\[object (.+)\]$/, '$1').toLowerCase();
},
// 获取本地保存的数值(仅用于 Greasemonkey)
getValue(name) {
return GM_getValue(name);
},
// 增改本地保存的数值(仅用于 Greasemonkey)
setValue(name, value) {
GM_setValue(name, value);
},
// 删除本地保存的数值(仅用于 Greasemonkey)
deleteValue(name) {
GM_deleteValue(name);
},
// 获取本地保存的数值
getStorage(key) {
try {
return JSON.parse(localStorage.getItem(key));
} catch (e) {
return localStorage.getItem(key);
}
},
// 修改本地保存的数值
setStorage(key, value) {
if (this.isType(value) === 'object' || this.isType(value) === 'array') {
return localStorage.setItem(key, JSON.stringify(value));
}
return localStorage.setItem(key, value);
},
// 设置剪贴板
setClipboard(text) {
GM_setClipboard(text, 'text');
},
// 加密成base64(先转换成URL编码)
encode(str) {
return btoa(unescape(encodeURIComponent(str)));
},
// 从base64解密
decode(str) {
return decodeURIComponent(escape(atob(str)));
},
// 数字补零
repairTimer(i) {
if (i >= 0 && i <= 9) {
return "0" + i;
} else {
return i;
}
},
// 接受文件名并返回大写扩展名
getExtension(name) {
const reg = /(?!\.)\w+$/;
if (reg.test(name)) {
let match = name.match(reg);
return match[0].toUpperCase();
}
return '';
},
// 文件大小转换(以字节为单位)
sizeFormat(value) {
if (value === +value) {
let unit = ["字节(B)", "千字节(KB)", "兆字节(MB)", "吉字节(GB)", "太字节(TB)", "拍字节(PB)", "艾字节(EB)", "泽字节(ZB)", "尧字节(YB)"];
if (value === 0) {
return "0字节(B)";
} else {
let index = Math.floor(Math.log(value) / Math.log(1024));
let size = value / Math.pow(1024, index);
size = size.toFixed(1);
return size + unit[index];
}
}
return '';
},
// 根据数组中的每个文件名进行排序,使用 localeCompare 方法来比较中文字符串的顺序。
sortByName(arr) {
const handle = function () {
return (a, b) => {
const p1 = a.filename ? a.filename : a.server_filename;
const p2 = b.filename ? b.filename : b.server_filename;
return p1.localeCompare(p2, "zh-CN");
};
};
arr.sort(handle());
},
// 替换特殊字符为下划线
fixFilename(name) {
let replace = /[!?&|`"'*\/:<>\\]/g
return name.replace(replace, '_');
},
// 传递 Document Cookie
getCookie(name) {
let cname = name + "=";
let ca = document.cookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i].trim();
if (c.indexOf(cname) == 0) return c.substring(cname.length, c.length);
}
return "";
},
// 接受Blob对象和文件名,然后创建临时链接指向blob对象,之后创建a标签指向临时链接和设置文件名,最后模拟点击a标签实现下载和释放临时链接
blobDownload(blob, filename) {
if (blob instanceof Blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
},
/* 请求 */
// 使用 Post 发送请求
post(url, data, headers, type, maxRetries = 3, currentRetry = 0) {
if (this.isType(data) === 'object') {
data = JSON.stringify(data);
}
return new Promise((resolve, reject) => {
const sendRequest = function () {
GM_xmlhttpRequest({
method: "POST", url, headers, data,
responseType: type || 'json',
onload: function (res) {
// 尝试格式化请求结果以方便调试
if (res.response) {
try {
res.decodedResponse = JSON.parse(res.response);
} catch (e) { }
}
if (res.responseText) {
try {
res.decodedResponseText = JSON.parse(res.responseText);
} catch (e) { }
}
console.log('【(改)网盘直链下载助手】Post\n请求地址:' + url + '\n请求头部:' + JSON.stringify(headers) + '\n请求数据:' + JSON.stringify(data) + '\n请求结果:', res);
type === 'blob' ? resolve(res) : resolve(res.response || res.responseText);
},
onerror: function (err) {
if (currentRetry < maxRetries) {
currentRetry++;
console.error(`【(改)网盘直链下载助手】Post\n请求出现错误,可能是网络问题\n5秒后将重试 (错误次数:${currentRetry}/${maxRetries})...`, err);
setTimeout(function () {
console.log(`【(改)网盘直链下载助手】Post\n重新尝试请求...`);
sendRequest(); // 重新发送请求
}, 5000)
} else {
reject('【(改)网盘直链下载助手】Post\n请求出现错误,可能是网络问题\n无法继续请求,达到最大错误次数。', err); // 达到最大重试次数,拒绝 Promise
}
},
});
};
sendRequest(); // 初始请求
});
},
// 使用 Get 发送请求
get(url, headers, type, extra, maxRetries = 3, currentRetry = 0) {
return new Promise((resolve, reject) => {
const sendRequest = function () {
let requestObj = GM_xmlhttpRequest({
method: "GET", url, headers,
responseType: type || 'json',
onload: function (res) {
if (res.status === 204) {
console.log('【(改)网盘直链下载助手】Get\n请求地址:' + url + '\n请求头部:' + JSON.stringify(headers) + '\n请求结果:', res + '\n请求已被IDM捕获。');
requestObj.abort();
idm[extra.index] = true;
}
if (type === 'blob') {
console.log('【(改)网盘直链下载助手】Get Blob\n请求地址:' + url + '\n请求头部:' + JSON.stringify(headers) + '\n请求结果:', res);
res.status === 200 && base.blobDownload(res.response, extra.filename);
resolve(res);
} else {
// 尝试格式化请求结果以方便调试
if (res.response) {
try {
res.decodedResponse = JSON.parse(res.response);
} catch (e) { }
}
if (res.responseText) {
try {
res.decodedResponseText = JSON.parse(res.responseText);
} catch (e) { }
}
console.log('【(改)网盘直链下载助手】Get\n请求地址:' + url + '\n请求头部:' + JSON.stringify(headers) + '\n请求结果:', res);
resolve(res.response || res.responseText);
}
},
onprogress: function (res) {
if (extra && extra.filename && extra.index) {
res.total > 0 ? progress[extra.index] = (res.loaded * 100 / res.total).toFixed(2) : progress[extra.index] = 0.00;
}
},
onloadstart() {
console.log('【(改)网盘直链下载助手】Get\n请求地址:' + url + '\n请求头部:' + JSON.stringify(headers));
extra && extra.filename && extra.index && (request[extra.index] = requestObj);
},
onerror: function (err) {
if (currentRetry < maxRetries) {
currentRetry++;
console.error(`【(改)网盘直链下载助手】Get\n请求出现错误,可能是网络问题\n5秒后将重试 (错误次数:${currentRetry}/${maxRetries})...`, err);
setTimeout(function () {
console.log(`【(改)网盘直链下载助手】Get\n重新尝试请求...`);
sendRequest(); // 重新发送请求
}, 5000)
} else {
reject('【(改)网盘直链下载助手】Get\n请求出现错误,可能是网络问题\n无法继续请求,达到最大错误次数。', err); // 达到最大重试次数,拒绝 Promise
}
},
});
};
sendRequest(); // 初始请求
});
},
// 使用 Get 发送请求获取跳转后的链接
getFinalUrl(url, headers, maxRetries = 3, currentRetry = 0) {
return new Promise((resolve, reject) => {
const sendRequest = function () {
let requestObj = GM_xmlhttpRequest({
method: "GET", url, headers,
onload: function (res) {
console.log('【(改)网盘直链下载助手】Get FinalUrl\n请求地址:' + url + '\n请求头部:' + JSON.stringify(headers) + '\n返回结果:', res);
resolve(res.finalUrl)
},
onerror: function (err) {
if (currentRetry < maxRetries) {
currentRetry++;
console.error(`【(改)网盘直链下载助手】Get FinalUrl\n请求出现错误,可能是网络问题\n5秒后将重试 (错误次数:${currentRetry}/${maxRetries})...`);
setTimeout(function () {
console.log(`【(改)网盘直链下载助手】Get FinalUrl\n重新尝试请求...`);
sendRequest(); // 重新发送请求
}, 5000)
} else {
reject('【(改)网盘直链下载助手】Get FinalUrl\n请求出现错误,可能是网络问题\n无法继续请求,达到最大错误次数。', err); // 达到最大重试次数,拒绝 Promise
}
},
});
};
sendRequest(); // 初始请求
});
},
// RPC测试
async rpcTest(domain, port, path, token) {
return new Promise((resolve, reject) => {
let rpc = { domain, port, path, token };
let url = `${rpc.domain}:${rpc.port}${rpc.path}`;
let rpcData = {
id: new Date().getTime(),
jsonrpc: '2.0',
method: 'system.listMethods',
params: [`token:${rpc.token}`],
};
GM_xmlhttpRequest({
method: "POST", url, headers: {}, data: JSON.stringify(rpcData),
responseType: 'json',
onload: function (res) {
console.log('【(改)网盘直链下载助手】Post RPCTest\n请求地址:' + url + '\n请求结果:', res);
if (res.response) {
resolve("success");
} else {
resolve("fail");
}
},
onerror: function (err) {
console.error('【(改)网盘直链下载助手】Post RPCTest\n请求失败', err);
resolve("fail");
},
});
});
},
// 将对象转换为 URL 加密
stringify(obj) {
let str = '';
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var value = obj[key];
if (Array.isArray(value)) {
for (var i = 0; i < value.length; i++) {
str += encodeURIComponent(key) + '=' + encodeURIComponent(value[i]) + '&';
}
} else {
str += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
}
}
}
return str.slice(0, -1); // 去掉末尾的 "&"
},
// 动态添加样式
addStyle(id, tag, css, element, position) {
tag = tag || 'style';
element = element || 'body';
let styleDom = document.getElementById(id);
if (styleDom) styleDom.remove();
let style = document.createElement(tag);
style.rel = 'stylesheet';
style.id = id;
tag === 'style' ? style.innerHTML = css : style.href = css;
if (position === "before") {
$(element).prepend($(style));
} else {
$(element).append($(style));
}
},
hexToRgba(hex) {
// 去掉 # 号
hex = hex.replace(/^#/, '');
// 如果是四位十六进制颜色值,转换为八位
if (hex.length === 4) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + hex[3] + hex[3];
}
// 解析 RGB 分量
var r = parseInt(hex.substring(0, 2), 16);
var g = parseInt(hex.substring(2, 4), 16);
var b = parseInt(hex.substring(4, 6), 16);
var a = '';
// 如果是八位十六进制颜色值,解析 alpha 通道
if (hex.length === 8) {
var a = 1;
a = parseInt(hex.substring(6, 8), 16) / 255; // 将 alpha 值转换为 0 到 1 之间的小数
a = ',' + a
}
// 返回 rgba 格式字符串
return r + ', ' + g + ', ' + b + a;
},
replaceColors(cssText, baseURI, type, colorMap) {
if (!cssText) return '';
var colorList = ['#09AAFF', '#cc3235', '#518c17', '#ed944b', '#f969a5', '#bca280', '#574AB8', '#b673ab', '#1d2327', '#18a497', '#637dff', '#0d53ff', '#3181f9', '#f8d800', '#0396ff', '#32ccbc', '#f6416c', '#2271b1', '#59524c', '#ff679a', '#f44236', '#fec107', '#8bc24a', '#2594ed', '#9c28b1']
colorList.forEach(function (oldColor) {
cssText = cssText.replace(new RegExp(base.hexToRgba(oldColor), 'ig'), base.hexToRgba(color));
cssText = cssText.replace(new RegExp(oldColor, 'ig'), color);
});
if (type === 'other') {
// 遍历颜色映射数组,将旧颜色替换为新颜色,并添加过渡效果
colorMap.forEach(function (colorPair) {
var oldColor = colorPair[0];
var newColor = colorPair[1];
// 判断新颜色是否为 color
cssText = cssText.replace(new RegExp(oldColor, 'ig'), newColor);
});
return cssText;
}
if (colorMap) {
// 遍历颜色映射数组,将旧颜色替换为新颜色,并添加过渡效果
colorMap.forEach(function (colorPair) {
var oldColor = colorPair[0];
var newColor = colorPair[1];
// 判断新颜色是否为 color
if (oldColor.includes("#")) {
cssText = cssText.replace(new RegExp(oldColor + '(.*?)}', 'ig'), newColor + '$1; ' + 'transition: all 0.1s ease;}');
} else {
cssText = cssText.replace(new RegExp(oldColor, 'ig'), newColor);
}
});
};
if (baseURI) {
// 替换相对路径资源为绝对路径
cssText = cssText.replace(/url\((?!['"]?(?:data|https?):)['"]?([^'"\)]*)['"]?\)/ig, function (match, p1) {
// 如果URL是相对路径,则将其转换为绝对路径
var absoluteURL = new URL(p1, baseURI).href;
return 'url(' + absoluteURL + ')';
});
};
return cssText;
},
setColors(colorMap, type) {
let cssText
document.querySelectorAll('link[rel="stylesheet"]').forEach(function (tag) {
if (!tag.parentElement) return;
// 对于link标签,异步获取其CSS内容
fetch(tag.href)
.then(response => response.text())
.then(responseText => {
let id = 'Panlinker-ColorUI-' + tag.href
// 替换颜色并添加样式
cssText = base.replaceColors(responseText, tag.href, type, colorMap);
if (responseText === base.replaceColors(responseText, '', type, colorMap)) return;
let newStyle = document.createElement('style');
newStyle.id = id;
newStyle.textContent = responseText;
if (location.pathname.includes("youth/pan")) {
base.addStyle(id, 'style', cssText, 'body', "before");
tag.remove()
} else {
base.addStyle(id, 'style', cssText, tag.parentElement.tagName || 'body');
}
console.log(`【(改)网盘直链下载助手】UI\n修改 元素 转