// ==UserScript== // @name 萌娘百科增强 // @namespace github.com/hmjz100 // @author hmjz100 // @version 0.6 // @description 自用脚本,萌娘百科更换主题为紫色,黑幕转淡紫幕,链接与选中文本变紫色 // @license MIT // @match http*://*.moegirl.org/* // @match http*://*.moegirl.org/* // @match http*://*.moegirl.org.cn/* // @match http*://*.moegirl.org.cn/* // @grant GM_addStyle // @icon data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFaIVgxWhFdgAAAAAAAAAAAAAAAAAgAACFKEU4BWhFXcAAAAAAAAAAAAAAAAAAAAAFKMUMheiFzcAmQAFAAAAABWhFbUVoRXuAAAAAAAAAAAAAAAAAAAAABWhFd4VoRXLAAAAAAAAAAAUoRQmFaEV8Bi5GP8YuBj/FaIV/xSgFDMVoRWdFaEV7AAAAAAAAAAAAAAAAAAAAAAWoRaYFqEW+QCqAAMA/wABFaIV3RalFv8UnxRaFqAWUxWhFekVoRXvFaEVnhWhFf4VoBWEFqEWghWhFYcWoRZ1FKIUiRWiFf8UpxQaFKAUMxezF/8WoBZTAAAAAAAAAAAUoxQyF60X/xWhFdcVoxX/F64X/xeuF/8Xshf/FaUV/xWhFZIVoxX/FKIUNBWgFWEWqxb/EqASKyCfIAgAAAAAIJ8gCBWhFfgVoRX+FaEV+g+lDxEAAAAAAAAAAAAAAAATnxM1F60X/xSiFE0UoRRkFqYW/xWhFf8WqBb/FaEV6RWfFRgVoRXcFaEV/hWhFf0VoRViFKMUThWhFVcToRM2GZwZHxanFv8UoxRkFaEVYhaoFv8VoBWcFaAVkxShFH8QnxAQFaAV6BWhFdsVoRX7FqsW/xarFv8XtRf/FaEV3xWfFRgVoRX9FaEVbRajFkUXshf/EpoSKwAAAAAAAAAAGpkaChWlFf8VoBWyFqcW/xagFlMNoQ0TF6IXFgCqAAMUoxQZF60X/xWgFWEasxoKFqoW/hanFtAXlxcWEI8QEBWgFYMXsRf/FqIWXRarFv8UohRYAAAAAAAAAAAPpQ8RFaEVtRevF/8WoBYjAAAAABe5F1cazBr/GcAZ/xeyF/8Xsxf/FaEVkACqAAMWpxb/F7AX/xWhFeYVoRXrF7AX/xi8GP8UoRR/AAAAAAAAAAAAAAAAF8EXIRm5GXEXsxeDF7MX8ROzExsAAAAAFaAVVhWgFZMVoRX/FaAV5RagFnYTnxMoAAAAAAAAAAAAAAAAAKoAAwAAAAAAAAAAG9IbOR3hHf8XvBdMAEAABAAAAAAAAAAAFqkWxxanFtoAAAAAAAAAAACAAAIAAAABH/gfsyD7IP8f7h//Huke+x3hHfYe5h7/HNgc/hvQG/0ayxr9GsUa+hnEGf8Ytxj/F7IX9BeuF/0WqRb/FqUW+SD/IGcg/CCmIPkgoSD1IKEh/CH/H/Af5B/lH54d3h2hHdkdoBvRG6EbzhuoHNoc/xnDGdAYuhigGLMYoRauFpoAAAAAAAAAAAAAAAAAAAAAIf4hyyD/IG4AAAAAAAAAAAAAAAAAAAAAAAAAABzcHOAd3x1HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== // @require https://unpkg.com/jquery@3.6.3/dist/jquery.min.js // ==/UserScript== (function moegirl() { let colored = false var base = { // 动态添加样式 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 ''; 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 = 'Moegirl-Replace-Color-' + 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修改 元素 转