macKeyIconToName

replace mac key icon to name

  1. // ==UserScript==
  2. // @name macKeyIconToName
  3. // @namespace leizingyiu
  4. // @match *://*.*/*
  5. // @grant none
  6. // @version 0.1
  7. // @author leizingyiu
  8. // @description replace mac key icon to name
  9. // @license GNU AGPLv3
  10. // ==/UserScript==
  11.  
  12.  
  13. const dict = {
  14. "⇧": "shift",
  15. "⌘": "cmd",
  16. "⌃": "ctrl",
  17. "⌥": "opt"
  18. };
  19.  
  20. function replaceText(node) {
  21. if (node.nodeType === Node.TEXT_NODE) {
  22. Object.entries(dict).forEach(([k, v]) => {
  23. let reg = new RegExp(k, 'g');
  24. node.nodeValue = node.nodeValue.replace(reg, v);
  25. });
  26. } else {
  27. node.childNodes.forEach(childNode => replaceText(childNode));
  28. }
  29. }
  30.  
  31. window.onload=()=>{
  32. setTimeout(()=>{replaceText(document.body);},1000);
  33. }
  34.  
  35.  
  36. // const dict = {
  37. // "⇧": "shift",
  38. // "⌘": "cmd",
  39. // "⌃": "ctrl",
  40. // "⌥": "opt"
  41. // };
  42.  
  43. // function replaceText(node) {
  44. // if (node.nodeType === Node.TEXT_NODE) {
  45. // Object.entries(dict).forEach(([k, v]) => {
  46. // let reg = new RegExp(k, 'g');
  47. // node.nodeValue = node.nodeValue.replace(reg, v);
  48. // });
  49. // }
  50. // }
  51.  
  52. // window.onload=()=>{
  53. // setTimeout(()=>{replaceText(document.body);},2000);
  54. // }
  55.  
  56. // const observer = new MutationObserver(mutationsList => {
  57. // mutationsList.forEach(mutation => {
  58. // mutation.addedNodes.forEach(addedNode => {
  59. // replaceText(addedNode);
  60. // });
  61. // mutation.target.childNodes.forEach(childNode => {
  62. // replaceText(childNode);
  63. // });
  64. // });
  65. // });
  66.  
  67. // observer.observe(document.body, { childList: true, subtree: true });
  68.  
  69.