Fullwidth Letter Fixer

Replaces fullwidth letters with ASCII equivalents, making pages a bit more searchable

  1. // ==UserScript==
  2. // @name Fullwidth Letter Fixer
  3. // @namespace DoomTay
  4. // @description Replaces fullwidth letters with ASCII equivalents, making pages a bit more searchable
  5. // @version 1.0.4
  6. // @include *
  7. // @exclude *.svg
  8. // @grant none
  9.  
  10. // ==/UserScript==
  11.  
  12. function replaceText(node) {
  13. if(node == null) return;
  14. var nodes = node.childNodes;
  15. for (var n=0; n<nodes.length; n++) {
  16. if(nodes[n].nodeType == Node.TEXT_NODE)
  17. {
  18. nodes[n].textContent = nodes[n].textContent.replace(/[\uFF01-\uFF5E]/g, function(char) {
  19. return String.fromCharCode(char.charCodeAt(0) - 0xFF01 + 0x21);
  20. });
  21. }
  22. //Nothing left to do here. Look at the children of this node
  23. replaceText(nodes[n]);
  24. }
  25. }
  26.  
  27. replaceText(document.body);