// ==UserScript== // @name 全都变猫娘喵! // @namespace https://penyo.ru/ // @version 1.0.8 // @description 变! // @author Penyo&lyx // @match *://*/* // @exclude *://greasyfork.org/* // @grant none // @license WTFPL // @downloadURL none // ==/UserScript== /** * 是否影响输入框 * * 警告!除非你知道改动此项会引发什么结果,否则不应改动! */ const affectInput = false; (function () { "use strict"; const elementToMatch = [ "title", "h1", "h2", "h3", "h4", "h5", "h6", "p", "article", "section", "blockquote", "li", "a", "CC", ]; /** * @param {Element} root */ function replace(root) { const replacer = (str) => str .replace(/我们/g, "咱喵和其它猫猫们") .replace(/大家/g, "各位猫猫们") .replace(/本人|(??@[\]^_`{|}~\u3000-\u303F\uFF00-\uFFEF]|$)/g, (_, $1, $2) => `喵${$2}` ) .replace( /([的了辣])([!"#$%&'()*+,-./:;/,=>?@[\]^_`{|}~\u3000-\u303F\uFF00-\uFFEF]|\s+(?!<|\w)|$)/g, (_, $1, $2) => `${$1}喵${$2}` ) // 新增句末添加“蝶思喵~” .replace(/([^。!?])$/g, "$1蝶思喵~"); requestIdleCallback(() => { root .querySelectorAll( elementToMatch .concat(elementToMatch.map((name) => name + " *")) .concat(affectInput ? ["input"] : []) .join(",") ) .forEach((candidate) => { if (candidate.nodeName == "INPUT") { candidate.value = replacer(candidate.value); } else if ( candidate.textContent && candidate.textContent == candidate.innerHTML.trim() ) { candidate.textContent = replacer(candidate.textContent); } else if ( Array.from(candidate.childNodes).filter((c) => c.nodeName == "BR") ) { Array.from(candidate.childNodes).forEach((maybeText) => { if (maybeText.nodeType == Node.TEXT_NODE) { maybeText.textContent = replacer(maybeText.textContent); } }); } }); }); } })();