1-
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- } ;
25-
26- function obfuscate ( string , elem ) {
27- if ( string . includes ( "<br>" ) ) {
28- elem . innerHTML = string ;
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 ) ;
1+ const MinecraftColorCodes = {
2+ obfuscators : [ ] ,
3+ 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+ } ,
25+ obfuscate : function ( string , elem ) {
26+ if ( string . includes ( "<br>" ) ) {
27+ elem . innerHTML = string ;
28+ for ( let currNode of elem . childNodes ) if ( currNode . nodeType === 3 ) {
29+ let magicSpan = document . createElement ( "span" ) ;
30+ magicSpan . innerHTML = currNode . nodeValue ;
31+ elem . replaceChild ( magicSpan , currNode ) ;
32+ init ( magicSpan ) ;
33+ }
3434 }
35- }
36- else init ( elem , string ) ;
37- function init ( el , str ) {
38- let i = 0 ,
39- obsStr = str || el . innerHTML ;
40- obfuscators . push ( window . setInterval ( function ( ) {
41- if ( i >= obsStr . length ) i = 0 ;
42- obsStr = replaceRand ( obsStr , i ) ;
43- el . innerHTML = obsStr ;
44- ++ i ;
45- } , 0 ) ) ;
46- }
47- function replaceRand ( string , i ) {
48- let randChar = String . fromCharCode ( Math . floor ( Math . random ( ) * 27 ) + 64 ) ;
49- return string . substr ( 0 , i ) + randChar + string . substr ( i + 1 , string . length ) ;
50- }
51- }
52-
53- function applyCode ( string , codes ) {
54- let elem = document . createElement ( "span" ) ,
55- obfuscated = false ;
56- for ( let code of codes ) {
57- elem . style . cssText += styleMap [ code ] + ";" ;
58- if ( code === "§k" ) {
59- obfuscate ( string , elem ) ;
60- obfuscated = true ;
35+ else init ( elem , string ) ;
36+ function init ( el , str ) {
37+ let i = 0 ,
38+ obsStr = str || el . innerHTML ;
39+ MinecraftColorCodes . obfuscators . push ( window . setInterval ( function ( ) {
40+ if ( i >= obsStr . length ) i = 0 ;
41+ obsStr = replaceRand ( obsStr , i ) ;
42+ el . innerHTML = obsStr ;
43+ ++ i ;
44+ } , 0 ) ) ;
45+ }
46+ function replaceRand ( string , i ) {
47+ let randChar = String . fromCharCode ( Math . floor ( Math . random ( ) * 27 ) + 64 ) ;
48+ return string . substr ( 0 , i ) + randChar + string . substr ( i + 1 , string . length ) ;
49+ }
50+ } ,
51+ applyCode : function ( string , codes ) {
52+ let elem = document . createElement ( "span" ) ,
53+ obfuscated = false ;
54+ for ( let code of codes ) {
55+ elem . style . cssText += MinecraftColorCodes . styleMap [ code ] + ";" ;
56+ if ( code === "§k" ) {
57+ MinecraftColorCodes . obfuscate ( string , elem ) ;
58+ obfuscated = true ;
59+ }
60+ }
61+ if ( ! obfuscated ) elem . innerHTML = string ;
62+ return elem ;
63+ } ,
64+ parseStyle : function ( string ) {
65+ let codes = string . match ( / § .{ 1 } / g) || [ ] ,
66+ indices = [ ] ,
67+ apply = [ ] ,
68+ tmpStr ,
69+ indexDelta ,
70+ noCode ,
71+ final = document . createDocumentFragment ( ) ;
72+ string = string . replace ( / \n | \\ n / g, "<br>" ) ;
73+
74+ for ( let code of codes ) {
75+ indices . push ( string . indexOf ( code ) ) ;
76+ string = string . replace ( code , "\x00\x00" ) ;
6177 }
62- }
63- if ( ! obfuscated ) elem . innerHTML = string ;
64- return elem ;
65- }
66-
67- function parseStyle ( string ) {
68- let codes = string . match ( / § .{ 1 } / g) || [ ] ,
69- indices = [ ] ,
70- apply = [ ] ,
71- tmpStr ,
72- indexDelta ,
73- noCode ,
74- final = document . createDocumentFragment ( ) ;
75- string = string . replace ( / \n | \\ n / g, "<br>" ) ;
76-
77- for ( let code of codes ) {
78- indices . push ( string . indexOf ( code ) ) ;
79- string = string . replace ( code , "\x00\x00" ) ;
80- }
8178
82- if ( indices [ 0 ] !== 0 ) final . appendChild ( applyCode ( string . substring ( 0 , indices [ 0 ] ) , [ ] ) ) ;
79+ if ( indices [ 0 ] !== 0 ) final . appendChild ( MinecraftColorCodes . applyCode ( string . substring ( 0 , indices [ 0 ] ) , [ ] ) ) ;
8380
84- for ( let i in codes ) {
85- indexDelta = indices [ i + 1 ] - indices [ i ] ;
86- if ( indexDelta === 2 ) {
87- while ( indexDelta === 2 ) {
81+ for ( let i in codes ) {
82+ indexDelta = indices [ i + 1 ] - indices [ i ] ;
83+ if ( indexDelta === 2 ) {
84+ while ( indexDelta === 2 ) {
85+ apply . push ( codes [ i ] ) ;
86+ ++ i ;
87+ indexDelta = indices [ i + 1 ] - indices [ i ] ;
88+ }
8889 apply . push ( codes [ i ] ) ;
89- ++ i ;
90- indexDelta = indices [ i + 1 ] - indices [ i ] ;
9190 }
92- apply . push ( codes [ i ] ) ;
91+ else apply . push ( codes [ i ] ) ;
92+ if ( apply . lastIndexOf ( "§r" ) > - 1 ) apply = apply . slice ( apply . lastIndexOf ( "§r" ) + 1 ) ;
93+ tmpStr = string . substring ( indices [ i ] , indices [ i + 1 ] ) ;
94+ final . appendChild ( MinecraftColorCodes . applyCode ( tmpStr , apply ) ) ;
9395 }
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 ] ) ;
97- final . appendChild ( applyCode ( tmpStr , apply ) ) ;
96+ return final ;
97+ } ,
98+ clearObfuscators : function ( ) {
99+ for ( let obfuscator of MinecraftColorCodes . obfuscators ) clearInterval ( obfuscator ) ;
100+ MinecraftColorCodes . obfuscators = [ ] ;
98101 }
99- return final ;
100- }
101-
102- function clearObfuscators ( ) {
103- for ( let obfuscator of obfuscators ) clearInterval ( obfuscator ) ;
104- obfuscators = [ ] ;
105102}
106103
107104String . prototype . replaceColorCodes = function ( ) {
108- clearObfuscators ( ) ;
109- let outputString = parseStyle ( String ( this ) ) ;
110- return outputString ;
111- } ;
105+ MinecraftColorCodes . clearObfuscators ( ) ;
106+ return MinecraftColorCodes . parseStyle ( String ( this ) ) ;
107+ } ;
0 commit comments