Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Moonrune Decipherer
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description Turns those pesky number codes into something else you can't understand.
- // @author dat boi
- // @grant none
- // ==/UserScript==
- /* jshint -W097 */
- 'use strict';
- walk(document.body);
- function walk(node)
- {
- // I stole this function from a guy who stole this function from here:
- // http://is.gd/mwZp7E
- var child, next;
- switch (node.nodeType)
- {
- case 1: // Element
- case 9: // Document
- case 11: // Document fragment
- child = node.firstChild;
- while (child)
- {
- next = child.nextSibling;
- walk(child);
- child = next;
- }
- break;
- case 3: // Text node
- handleText(node);
- break;
- }
- }
- function handleText(textNode)
- {
- var str = textNode.nodeValue;
- //I only wrote this part
- var pattern = /&#(\d+);/gim;
- var matches;
- while ((matches = pattern.exec(str)) != null) {//yes, 4 identical consecutive while loops is the only way I could get this to work
- str = str.replace(matches[0], String.fromCharCode(matches[1]));
- }
- while ((matches = pattern.exec(str)) != null) {
- str = str.replace(matches[0], String.fromCharCode(matches[1]));
- }
- while ((matches = pattern.exec(str)) != null) {
- str = str.replace(matches[0], String.fromCharCode(matches[1]));
- }
- while ((matches = pattern.exec(str)) != null) {
- str = str.replace(matches[0], String.fromCharCode(matches[1]));
- }
- textNode.nodeValue = str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement