Skip to content

Instantly share code, notes, and snippets.

@haruue
Last active December 5, 2025 14:09
Show Gist options
  • Select an option

  • Save haruue/87e8f74121faa83bc6f4cc435390d21b to your computer and use it in GitHub Desktop.

Select an option

Save haruue/87e8f74121faa83bc6f4cc435390d21b to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Fuck arm64/amd64
// @namespace https://haruue.net/
// @version 1.0
// @description 将网页中容易混淆的架构名替换为不易混淆的名称:amd64 → x86-64,arm64 → aarch64
// @author haruue
// @match *://*/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
const ARCH_REGEX = /\b(?<arch>amd64|arm64)(?=\b|(?=v[0-9])|[^a-zA-Z0-9])/g;
function archReplace(text) {
return text.replace(ARCH_REGEX, (match) => {
if (match === 'amd64') return 'x86-64';
if (match === 'arm64') return 'aarch64';
return match;
});
}
function shouldReplace(text) {
return /(^|[^a-zA-Z])(?:amd64|arm64)(?=$|[^a-zA-Z0-9]|v[0-9])/.test(text);
}
function isInUnreplaceableBlock(node) {
let el = node.parentElement;
while (el) {
const tag = el.tagName.toLowerCase();
if ((tag === 'code' || tag === 'pre' || el.classList.contains('blob-code')) && !el.closest('a')) {
return true;
}
el = el.parentElement;
}
return false;
}
function processTextNode(node) {
if (isInUnreplaceableBlock(node)) return;
const original = node.textContent;
if (shouldReplace(original)) {
const replaced = archReplace(original);
if (replaced !== original) {
node.textContent = replaced;
}
}
}
function walk(node) {
if (node.nodeType === Node.TEXT_NODE) {
processTextNode(node);
} else if (node.nodeType === Node.ELEMENT_NODE) {
for (const child of node.childNodes) {
walk(child);
}
}
}
function runInitial() {
walk(document.body);
}
const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
walk(node);
}
}
}
});
function start() {
runInitial();
observer.observe(document.body, {
childList: true,
subtree: true,
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', start);
} else {
start();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment