StackOverflow code标签替换

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

目前為 2024-03-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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
}