macKeyIconToName

replace mac key icon to name

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        macKeyIconToName
// @namespace   leizingyiu
// @match       *://*.*/*
// @grant       none
// @version     0.1
// @author      leizingyiu
// @description replace mac key icon to name
// @license     GNU AGPLv3 
// ==/UserScript==


const dict = {
    "⇧": "shift",
    "⌘": "cmd",
    "⌃": "ctrl",
    "⌥": "opt"
};

function replaceText(node) {
    if (node.nodeType === Node.TEXT_NODE) {
        Object.entries(dict).forEach(([k, v]) => {
            let reg = new RegExp(k, 'g');
            node.nodeValue = node.nodeValue.replace(reg, v);
        });
    } else {
        node.childNodes.forEach(childNode => replaceText(childNode));
    }
}

window.onload=()=>{
  setTimeout(()=>{replaceText(document.body);},1000);
}


// const dict = {
//     "⇧": "shift",
//     "⌘": "cmd",
//     "⌃": "ctrl",
//     "⌥": "opt"
// };

// function replaceText(node) {
//     if (node.nodeType === Node.TEXT_NODE) {
//         Object.entries(dict).forEach(([k, v]) => {
//             let reg = new RegExp(k, 'g');
//             node.nodeValue = node.nodeValue.replace(reg, v);
//         });
//     }
// }

// window.onload=()=>{
//   setTimeout(()=>{replaceText(document.body);},2000);
// }

// const observer = new MutationObserver(mutationsList => {
//     mutationsList.forEach(mutation => {
//         mutation.addedNodes.forEach(addedNode => {
//             replaceText(addedNode);
//         });
//         mutation.target.childNodes.forEach(childNode => {
//             replaceText(childNode);
//         });
//     });
// });

// observer.observe(document.body, { childList: true, subtree: true });