// ==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 = ` 油猴 中文网 `; const css = ` .comiis_logo img{display:none!important} .comiis_logo a {${prefixBackgroundImage(regexEncode(doublesToSingles(svg)),"xml")}width:${width}px} `; //document.head.insertAdjacentHTML("beforeend", ``); 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,}<`); 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;"; }