Greasy Fork is available in English.

全给我变成小南娘!

变!

< Opiniones de 全给我变成小南娘!

Puntuación: Bueno; el script funciona tal y como promete

§
Publicado: 29/9/2024
Editado: 29/9/2024

我发现由于每秒替换会导致鼠标拖拽选中的内容被取消选中,故用gpt4重写了一个代码,完美解决了这个问题,将代码粘贴在这里,个人喜好我删掉了替换"人"的内容.注意有些敏感词会被屏蔽
// ==UserScript==
// @name 全给我变成小南娘!
// @namespace https://penyo.ru/
// @version 1.0.7
// @description 变!
// @author Penyo
// @match *://*/*
// @exclude *://greasyfork.org/*
// @grant none
// @license WTFPL
// @downloadURL https://update.greasyfork.org/scripts/504225/%E5%85%A8%E7%BB%99%E6%88%91%E5%8F%98%E6%88%90%E5%B0%8F%E5%8D%97%E5%A8%98%EF%BC%81.user.js
// @updateURL https://update.greasyfork.org/scripts/504225/%E5%85%A8%E7%BB%99%E6%88%91%E5%8F%98%E6%88%90%E5%B0%8F%E5%8D%97%E5%A8%98%EF%BC%81.meta.js
// ==/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) => `喵${orophilia()}${$2}`
)
.replace(
/([的了辣])([!"#$%&'()*+,-./:;/,=>?@[\]^_`{|}~\u3000-\u303F\uFF00-\uFFEF]|\s+(?!<|\w)|$)/g,
(_, $1, $2) => `${$1}喵${orophilia()}${$2}`
);

const orophilia = () => (Math.random() < 0.33 ? "です" : "");

requestIdleCallback(() => {
const selection = window.getSelection();
const selectedText = selection.toString();

// 如果有选中的文本,则不进行替换
if (selectedText) return;

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);
}
});
}
});
});
}

/**
* @param {Element} root
*/
async function afterDomLoaded(root) {
if (!root) return;
const fn = () => {
replace(root);
root.querySelectorAll("*").forEach(async (node) => {
if (node.shadowRoot) {
await afterDomLoaded(node.shadowRoot);
}
});
};
while (document.readyState == "loading") {
await new Promise((r) => setTimeout(r, 1000));
}
fn();
}

afterDomLoaded(document);
setInterval(() => afterDomLoaded(document), 2500);
})();

Publicar respuesta

Inicia sesión para responder.