macKeyIconToName

replace mac key icon to name

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