Flip text in page


/ Published in: JavaScript
Save to your folder(s)

April 1, 2009, youtube.com


Copy this code and paste it in your HTML
  1. function watchFlip() {
  2. var elements = document.body.getElementsByTagName("*");
  3. for (var x = 0; x < elements.length; ++x) {
  4. if ((elements[x].innerText || elements[x].textContent) && elements[x].innerHTML.indexOf('<') == -1 &&
  5. (elements[x].nodeName == "DIV" || elements[x].nodeName == "SPAN" || elements[x].nodeName == "A" || elements[x].nodeName == "H1" || elements[x].nodeName == "H2"
  6. || elements[x].nodeName == "LABEL" || elements[x].nodeName == "B" || elements[x].nodeName == "OPTION" || elements[x].nodeName == "TH")) {
  7. var result2 = flipStr((elements[x].innerText || elements[x].textContent).toLowerCase());
  8. if (elements[x].innerText) {
  9. elements[x].innerText = result2;
  10. } else {
  11. elements[x].textContent = result2;
  12. }
  13. }
  14. }
  15.  
  16. onLoadFunctionList.push(function() {
  17. if (document.comment_formmain_comment) {
  18. document.comment_formmain_comment.preview_comment_button.value = flipStr(document.comment_formmain_comment.preview_comment_button.value.toLowerCase());
  19. document.comment_formmain_comment.add_comment_button.value = flipStr(document.comment_formmain_comment.add_comment_button.value.toLowerCase());
  20. }
  21. });
  22. }
  23.  
  24. function flipStr(str) {
  25. var result = "";
  26. for (var x = str.length - 1; x >= 0; --x){
  27. var c = str.charAt(x);
  28. var r = watchFlipCharset[c];
  29. result += r != undefined ? r : c;
  30. }
  31.  
  32. return result;
  33. }
  34.  
  35.  
  36. var watchFlipCharset = {
  37. a : '\u0250',
  38. b : 'q',
  39. c : '\u0254',
  40. d : 'p',
  41. e : '\u01DD',
  42. f : '\u025F',
  43. g : '\u0183',
  44. h : '\u0265',
  45. i : '\u0131',
  46. j : '\u027E',
  47. k : '\u029E',
  48. l : 'l',
  49. m : '\u026F',
  50. n : 'u',
  51. o : 'o',
  52. p : 'd',
  53. q : 'b',
  54. r : '\u0279',
  55. s : 's',
  56. t : '\u0287',
  57. u : 'n',
  58. v : '\u028C',
  59. w : '\u028D',
  60. y : '\u028E',
  61. z : 'z',
  62. 1 : '\u21C2',
  63. 2 : '\u1105',
  64. 3 : '\u1110',
  65. 4 : '\u3123',
  66. 5 : '\u078E', /* or u03DB */
  67. 6 : '9',
  68. 7 : '\u3125',
  69. 8 : '8',
  70. 9 : '6',
  71. 0 : '0',
  72. '.' : '\u02D9',
  73. ',' : "\'",
  74. "\'" : ',',
  75. "\"" : ',,',
  76. "´" : ',',
  77. "`" : ',',
  78. ';' : '\u061B',
  79. '!' : '\u00A1',
  80. '\u00A1' : '!',
  81. '?' : '\u00BF',
  82. '\u00BF' : '?',
  83. '[' : ']',
  84. ']' : '[',
  85. '(' : ')',
  86. ')' : '(',
  87. '{' : '}',
  88. '}' : '{',
  89. '<' : '>',
  90. '>' : '<',
  91. '_' : '\u203E',
  92. '\r' : '\n'
  93. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.