Shift-JIS Letter Fixer

Replaces Shift-JIS encoded Latin letters with Unicode equivalents, making pages a bit more searchable

当前为 2016-01-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Shift-JIS Letter Fixer
  3. // @namespace DoomTay
  4. // @description Replaces Shift-JIS encoded Latin letters with Unicode equivalents, making pages a bit more searchable
  5. // @version 1.0.0
  6. // @grant none
  7.  
  8. // ==/UserScript==
  9.  
  10. var replacementTable = [
  11. ["A","A"],
  12. ["B","B"],
  13. ["C","C"],
  14. ["D","D"],
  15. ["E","E"],
  16. ["F","F"],
  17. ["G","G"],
  18. ["H","H"],
  19. ["I","I"],
  20. ["J","J"],
  21. ["K","K"],
  22. ["L","L"],
  23. ["M","M"],
  24. ["N","N"],
  25. ["O","O"],
  26. ["P","P"],
  27. ["Q","Q"],
  28. ["R","R"],
  29. ["S","S"],
  30. ["T","T"],
  31. ["U","U"],
  32. ["V","V"],
  33. ["W","W"],
  34. ["X","X"],
  35. ["Y","Y"],
  36. ["Z","Z"],
  37. ["a","a"],
  38. ["b","b"],
  39. ["c","c"],
  40. ["d","d"],
  41. ["e","e"],
  42. ["f","f"],
  43. ["g","g"],
  44. ["h","h"],
  45. ["i","i"],
  46. ["j","j"],
  47. ["k","k"],
  48. ["l","l"],
  49. ["m","m"],
  50. ["n","n"],
  51. ["o","o"],
  52. ["p","p"],
  53. ["q","q"],
  54. ["r","r"],
  55. ["s","s"],
  56. ["t","t"],
  57. ["u","u"],
  58. ["v","v"],
  59. ["w","w"],
  60. ["x","x"],
  61. ["y","y"],
  62. ["z","z"],
  63. ["0","0"],
  64. ["1","1"],
  65. ["2","2"],
  66. ["3","3"],
  67. ["4","4"],
  68. ["5","5"],
  69. ["6","6"],
  70. ["7","7"],
  71. ["8","8"],
  72. ["9","9"]
  73. ];
  74. function replaceText(node, scan, replacement) {
  75. var nodes = node.childNodes;
  76. for (var n=0; n<nodes.length; n++) {
  77. if(nodes[n].nodeType == Node.TEXT_NODE && nodes[n].textContent.trim().indexOf(scan) > -1)
  78. {
  79. while(nodes[n].textContent.indexOf(scan) > -1) nodes[n].textContent = nodes[n].textContent.replace(scan,replacement);
  80. }
  81. //Nothing in this node. Look at the children of this node.
  82. else
  83. {
  84. replaceText(nodes[n],scan,replacement);
  85. }
  86. }
  87. }
  88.  
  89. for(var i = 0; i < replacementTable.length; i++)
  90. {
  91. replaceText(document.body,replacementTable[i][0], replacementTable[i][1]);
  92. }