StackOverflow code标签替换

替换<code>为<strong>,使chrome的翻译拆分效果更好。否则code会截断一整个句子的翻译。

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         StackOverflow code标签替换
// @namespace    http://tampermonkey.net/
// @version      2024-03-101
// @description  替换<code>为<strong>,使chrome的翻译拆分效果更好。否则code会截断一整个句子的翻译。
// @author       You
// @match        https://stackoverflow.com/questions/*
// @match        https://*.stackexchange.com/questions/*
// @match        https://developer.mozilla.org/en-US/*
// @match        https://pypi.org/project/*
// @match        https://*.github.com/*
// @match        https://askubuntu.com/*
// @match        https://superuser.com/*
// @match        https://serverfault.com/*
// @match        https://scikit-learn.org/*
// @match        https://access.redhat.com/*
// @match        https://www.smashingmagazine.com/*
// @match        https://docs.npmjs.com/cli/v8/commands/*
// @match        https://highway-env.readthedocs.io/*
// @match        https://router.vuejs.org/*
// @match        https://farama-foundation.github.io/*
// @match        https://developer.chrome.com/*
// @match        https://git-scm.com/docs/*

// @icon         https://www.google.com/s2/favicons?sz=64&domain=stackoverflow.com
// @grant        none
// @license      LGPLv3
// ==/UserScript==


let consoleButton = document.createElement('button');
consoleButton.textContent = '替换code标签';


consoleButton.style.position = 'fixed';
consoleButton.style.top = '30px';
consoleButton.style.right = '30px';
consoleButton.style.zIndex = '9999';


consoleButton.addEventListener('click', function () {
	replaceCode()
});

document.body.appendChild(consoleButton);

function replaceCode() {
	let hh = document.querySelector("body").innerHTML
	// hh = hh.replace(/<code style="user-select: text;">(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
	// hh = hh.replace(/<code class="notranslate" style="user-select: text;">(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
	// hh = hh.replace(/<code class="docutils literal notranslate" style="user-select: text;">(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
	// hh = hh.replace(/<code .+?>(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")
	hh = hh.replace(/<code.*?>(.*?)<\/code>/g, "<strong style=\"user-select: text;\">$1</strong>")

	document.querySelector("body").innerHTML = hh
}