|
1 | 1 |
|
2 | | -var obfuscators = []; |
3 | | -var styleMap = { |
4 | | - '§4': 'font-weight:normal;text-decoration:none;color:#be0000', |
5 | | - '§c': 'font-weight:normal;text-decoration:none;color:#fe3f3f', |
6 | | - '§6': 'font-weight:normal;text-decoration:none;color:#d9a334', |
7 | | - '§e': 'font-weight:normal;text-decoration:none;color:#fefe3f', |
8 | | - '§2': 'font-weight:normal;text-decoration:none;color:#00be00', |
9 | | - '§a': 'font-weight:normal;text-decoration:none;color:#3ffe3f', |
10 | | - '§b': 'font-weight:normal;text-decoration:none;color:#3ffefe', |
11 | | - '§3': 'font-weight:normal;text-decoration:none;color:#00bebe', |
12 | | - '§1': 'font-weight:normal;text-decoration:none;color:#0000be', |
13 | | - '§9': 'font-weight:normal;text-decoration:none;color:#3f3ffe', |
14 | | - '§d': 'font-weight:normal;text-decoration:none;color:#fe3ffe', |
15 | | - '§5': 'font-weight:normal;text-decoration:none;color:#be00be', |
16 | | - '§f': 'font-weight:normal;text-decoration:none;color:#ffffff', |
17 | | - '§7': 'font-weight:normal;text-decoration:none;color:#bebebe', |
18 | | - '§8': 'font-weight:normal;text-decoration:none;color:#3f3f3f', |
19 | | - '§0': 'font-weight:normal;text-decoration:none;color:#000000', |
20 | | - '§l': 'font-weight:bold', |
21 | | - '§n': 'text-decoration:underline;text-decoration-skip:spaces', |
22 | | - '§o': 'font-style:italic', |
23 | | - '§m': 'text-decoration:line-through;text-decoration-skip:spaces', |
| 2 | +let obfuscators = []; |
| 3 | +const styleMap = { |
| 4 | + "§4": "font-weight:normal;text-decoration:none;color:#be0000", |
| 5 | + "§c": "font-weight:normal;text-decoration:none;color:#fe3f3f", |
| 6 | + "§6": "font-weight:normal;text-decoration:none;color:#d9a334", |
| 7 | + "§e": "font-weight:normal;text-decoration:none;color:#fefe3f", |
| 8 | + "§2": "font-weight:normal;text-decoration:none;color:#00be00", |
| 9 | + "§a": "font-weight:normal;text-decoration:none;color:#3ffe3f", |
| 10 | + "§b": "font-weight:normal;text-decoration:none;color:#3ffefe", |
| 11 | + "§3": "font-weight:normal;text-decoration:none;color:#00bebe", |
| 12 | + "§1": "font-weight:normal;text-decoration:none;color:#0000be", |
| 13 | + "§9": "font-weight:normal;text-decoration:none;color:#3f3ffe", |
| 14 | + "§d": "font-weight:normal;text-decoration:none;color:#fe3ffe", |
| 15 | + "§5": "font-weight:normal;text-decoration:none;color:#be00be", |
| 16 | + "§f": "font-weight:normal;text-decoration:none;color:#ffffff", |
| 17 | + "§7": "font-weight:normal;text-decoration:none;color:#bebebe", |
| 18 | + "§8": "font-weight:normal;text-decoration:none;color:#3f3f3f", |
| 19 | + "§0": "font-weight:normal;text-decoration:none;color:#000000", |
| 20 | + "§l": "font-weight:bold", |
| 21 | + "§n": "text-decoration:underline;text-decoration-skip:spaces", |
| 22 | + "§o": "font-style:italic", |
| 23 | + "§m": "text-decoration:line-through;text-decoration-skip:spaces", |
24 | 24 | }; |
| 25 | + |
25 | 26 | function obfuscate(string, elem) { |
26 | | - var magicSpan, |
27 | | - currNode, |
28 | | - len = elem.childNodes.length; |
29 | | - if(string.indexOf('<br>') > -1) { |
| 27 | + if (string.includes("<br>")) { |
30 | 28 | elem.innerHTML = string; |
31 | | - for(var j = 0; j < len; j++) { |
32 | | - currNode = elem.childNodes[j]; |
33 | | - if(currNode.nodeType === 3) { |
34 | | - magicSpan = document.createElement('span'); |
35 | | - magicSpan.innerHTML = currNode.nodeValue; |
36 | | - elem.replaceChild(magicSpan, currNode); |
37 | | - init(magicSpan); |
38 | | - } |
| 29 | + for (let currNode of elem.childNodes) if (currNode.nodeType === 3) { |
| 30 | + let magicSpan = document.createElement("span"); |
| 31 | + magicSpan.innerHTML = currNode.nodeValue; |
| 32 | + elem.replaceChild(magicSpan, currNode); |
| 33 | + init(magicSpan); |
39 | 34 | } |
40 | | - } else { |
41 | | - init(elem, string); |
42 | 35 | } |
| 36 | + else init(elem, string); |
43 | 37 | function init(el, str) { |
44 | | - var i = 0, |
45 | | - obsStr = str || el.innerHTML, |
46 | | - len = obsStr.length; |
47 | | - obfuscators.push( window.setInterval(function () { |
48 | | - if(i >= len) i = 0; |
| 38 | + let i = 0, |
| 39 | + obsStr = str || el.innerHTML; |
| 40 | + obfuscators.push(window.setInterval(function () { |
| 41 | + if (i >= obsStr.length) i = 0; |
49 | 42 | obsStr = replaceRand(obsStr, i); |
50 | 43 | el.innerHTML = obsStr; |
51 | | - i++; |
52 | | - }, 0) ); |
53 | | - } |
54 | | - function randInt(min, max) { |
55 | | - return Math.floor( Math.random() * (max - min + 1) ) + min; |
| 44 | + ++i; |
| 45 | + }, 0)); |
56 | 46 | } |
57 | 47 | function replaceRand(string, i) { |
58 | | - var randChar = String.fromCharCode( randInt(64,90) ); /*Numbers: 48-57 Al:64-90*/ |
| 48 | + let randChar = String.fromCharCode(Math.floor(Math.random() * (27)) + 64); |
59 | 49 | return string.substr(0, i) + randChar + string.substr(i + 1, string.length); |
60 | 50 | } |
61 | 51 | } |
| 52 | + |
62 | 53 | function applyCode(string, codes) { |
63 | | - var len = codes.length; |
64 | | - var elem = document.createElement('span'), |
| 54 | + let elem = document.createElement("span"), |
65 | 55 | obfuscated = false; |
66 | | - for(var i = 0; i < len; i++) { |
67 | | - elem.style.cssText += styleMap[codes[i]] + ';'; |
68 | | - if(codes[i] === '§k') { |
| 56 | + for (let code of codes) { |
| 57 | + elem.style.cssText += styleMap[code] + ";"; |
| 58 | + if (code === "§k") { |
69 | 59 | obfuscate(string, elem); |
70 | 60 | obfuscated = true; |
71 | 61 | } |
72 | 62 | } |
73 | | - if(!obfuscated) elem.innerHTML = string; |
| 63 | + if (!obfuscated) elem.innerHTML = string; |
74 | 64 | return elem; |
75 | 65 | } |
| 66 | + |
76 | 67 | function parseStyle(string) { |
77 | | - var codes = string.match(/§.{1}/g) || [], |
78 | | - indexes = [], |
| 68 | + let codes = string.match(/§.{1}/g) || [], |
| 69 | + indices = [], |
79 | 70 | apply = [], |
80 | 71 | tmpStr, |
81 | 72 | indexDelta, |
82 | 73 | noCode, |
83 | | - final = document.createDocumentFragment(), |
84 | | - len = codes.length, |
85 | | - string = string.replace(/\n|\\n/g, '<br>'); |
| 74 | + final = document.createDocumentFragment(); |
| 75 | + string = string.replace(/\n|\\n/g, "<br>"); |
86 | 76 |
|
87 | | - for(var i = 0; i < len; i++) { |
88 | | - indexes.push( string.indexOf(codes[i]) ); |
89 | | - string = string.replace(codes[i], '\x00\x00'); |
90 | | - } |
91 | | - if(indexes[0] !== 0) { |
92 | | - final.appendChild( applyCode( string.substring(0, indexes[0]), [] ) ); |
| 77 | + for (let code of codes) { |
| 78 | + indices.push(string.indexOf(code)); |
| 79 | + string = string.replace(code, "\x00\x00"); |
93 | 80 | } |
94 | | - for(var i = 0; i < len; i++) { |
95 | | - indexDelta = indexes[i + 1] - indexes[i]; |
96 | | - if(indexDelta === 2) { |
97 | | - while(indexDelta === 2) { |
98 | | - apply.push ( codes[i] ); |
99 | | - i++; |
100 | | - indexDelta = indexes[i + 1] - indexes[i]; |
| 81 | + |
| 82 | + if (indices[0] !== 0) final.appendChild(applyCode(string.substring(0, indices[0]), [])); |
| 83 | + |
| 84 | + for (let i in codes) { |
| 85 | + indexDelta = indices[i + 1] - indices[i]; |
| 86 | + if (indexDelta === 2) { |
| 87 | + while (indexDelta === 2) { |
| 88 | + apply.push(codes[i]); |
| 89 | + ++i; |
| 90 | + indexDelta = indices[i + 1] - indices[i]; |
101 | 91 | } |
102 | | - apply.push ( codes[i] ); |
103 | | - } else { |
104 | | - apply.push( codes[i] ); |
105 | | - } |
106 | | - if( apply.lastIndexOf('§r') > -1) { |
107 | | - apply = apply.slice( apply.lastIndexOf('§r') + 1 ); |
| 92 | + apply.push(codes[i]); |
108 | 93 | } |
109 | | - tmpStr = string.substring( indexes[i], indexes[i + 1] ); |
| 94 | + else apply.push(codes[i]); |
| 95 | + if (apply.lastIndexOf("§r") > -1) apply = apply.slice( apply.lastIndexOf("§r") + 1 ); |
| 96 | + tmpStr = string.substring( indices[i], indices[i + 1] ); |
110 | 97 | final.appendChild( applyCode(tmpStr, apply) ); |
111 | 98 | } |
112 | 99 | return final; |
113 | 100 | } |
| 101 | + |
114 | 102 | function clearObfuscators() { |
115 | | - var i = obfuscators.length; |
116 | | - for(;i--;) { |
117 | | - clearInterval(obfuscators[i]); |
118 | | - } |
| 103 | + for (let obfuscator of obfuscators) clearInterval(obfuscator); |
119 | 104 | obfuscators = []; |
120 | 105 | } |
| 106 | + |
121 | 107 | String.prototype.replaceColorCodes = function() { |
122 | 108 | clearObfuscators(); |
123 | | - var outputString = parseStyle(String(this)); |
| 109 | + let outputString = parseStyle(String(this)); |
124 | 110 | return outputString; |
125 | 111 | }; |
126 | | - |
127 | | -///////////////////////////////////////////////// |
128 | | -function cutString(str, cutStart, cutEnd){ |
129 | | - return str.substr(0,cutStart) + str.substr(cutEnd+1); |
130 | | -} |
0 commit comments