macKeyIconToName

replace mac key icon to name

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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