油猴中文网LOGO替换
// ==UserScript==
// @name 油猴中文网LOGO替换
// @namespace XJB写着玩的不要当真
// @version 1.1
// @description 【一名低级的程序员只能完成最基本的代码功能,而优秀的程序员在考虑完成功能的同时,代码自身也是一副美女图】 ——节选自《李恒道语录》
// @author DreamNya
// @match https://bbs.tampermonkey.net.cn/*
// @grant none
// @license MIT
// @run-at document-start
// ==/UserScript==
const font_size = 28;
const font_weight = 600;
const margin_left = 15;
const margin_right = 5;
const margin_top = 6;
const width = font_size * 5 + margin_left * 2 + margin_right * 2;
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="${width}" height="${font_size + (margin_top - 1) * 2 + margin_top * 2}">
<text x="${font_size + margin_left}" y="${font_size + margin_top}" font-size="${font_size}" text-anchor="middle" fill="white" font-weight="${font_weight}">油猴</text>
<rect x="${font_size * 2 + margin_left + margin_right}" y="${margin_top}" width="${font_size * 3 + margin_right}" height="${font_size + (margin_top - 1) * 2}" fill="rgb(241, 158, 56)" rx="5"/>
<text x="${font_size * 5 - margin_right - margin_left}" y="${font_size + margin_top}" font-size="${font_size}" text-anchor="middle" fill="black" font-weight="${font_weight}">中文网</text>
</svg>
`;
const css = `
.comiis_logo img{display:none!important}
.comiis_logo a {${prefixBackgroundImage(regexEncode(doublesToSingles(svg)),"xml")}width:${width}px}
`;
//document.head.insertAdjacentHTML("beforeend", `<style>${css}</style>`);
document.children[0].appendChild(document.createElement('style')).textContent = css;
// Code above fork from https://github.com/IORoot/SVGencode
function doublesToSingles(svg) {
return svg.replace(/"/g, "'");
}
function regexEncode(svg) {
svg = svg.replace(/>\s{1,}</g, `><`);
svg = svg.replace(/\s{2,}/g, ` `);
return svg.replace(/[\r\n%#()<>?[\\\]^`{|}]/g, encodeURIComponent);
}
function prefixDataType(svg, type) {
return "data:image/svg+" + type + "," + svg;
}
function prefixURLDoubleQuotes(svg) {
return 'url("' + svg + '")';
}
function prefixBackgroundImage(svg, type) {
svg = prefixDataType(svg, type);
svg = prefixURLDoubleQuotes(svg);
return "background: " + svg + " !important;";
}