Advertisement
Guest User

be a weeb 1.0

a guest
Feb 10th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Moonrune Decipherer
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Turns those pesky number codes into something else you can't understand.
  6. // @author       dat boi
  7. // @grant        none
  8. // ==/UserScript==
  9. /* jshint -W097 */
  10. 'use strict';
  11.  
  12. walk(document.body);
  13.  
  14. function walk(node)
  15. {
  16.     // I stole this function from a guy who stole this function from here:
  17.     // http://is.gd/mwZp7E
  18.    
  19.     var child, next;
  20.  
  21.     switch (node.nodeType)  
  22.     {
  23.         case 1:  // Element
  24.         case 9:  // Document
  25.         case 11: // Document fragment
  26.             child = node.firstChild;
  27.             while (child)
  28.             {
  29.                 next = child.nextSibling;
  30.                 walk(child);
  31.                 child = next;
  32.             }
  33.             break;
  34.  
  35.         case 3: // Text node
  36.             handleText(node);
  37.             break;
  38.     }
  39. }
  40.  
  41. function handleText(textNode)
  42. {
  43.     var str = textNode.nodeValue;
  44.     //I only wrote this part
  45.     var pattern = /&#(\d+);/gim;
  46.     var matches;
  47.     while ((matches = pattern.exec(str)) != null) {//yes, 4 identical consecutive while loops is the only way I could get this to work
  48.         str = str.replace(matches[0], String.fromCharCode(matches[1]));
  49.     }
  50.     while ((matches = pattern.exec(str)) != null) {
  51.         str = str.replace(matches[0], String.fromCharCode(matches[1]));
  52.     }
  53.     while ((matches = pattern.exec(str)) != null) {
  54.         str = str.replace(matches[0], String.fromCharCode(matches[1]));
  55.     }
  56.     while ((matches = pattern.exec(str)) != null) {
  57.         str = str.replace(matches[0], String.fromCharCode(matches[1]));
  58.     }
  59.    
  60.     textNode.nodeValue = str;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement