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' ,
24+ } ;
25+ function obfuscate ( string , elem ) {
26+ var magicSpan ,
27+ currNode ,
28+ len = elem . childNodes . length ;
29+ if ( string . indexOf ( '<br>' ) > - 1 ) {
30+ 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+ }
39+ }
40+ } else {
41+ init ( elem , string ) ;
42+ }
43+ 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 ;
49+ obsStr = replaceRand ( obsStr , i ) ;
50+ el . innerHTML = obsStr ;
51+ i ++ ;
52+ } , 0 ) ) ;
53+ }
54+ function randInt ( min , max ) {
55+ return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
56+ }
57+ function replaceRand ( string , i ) {
58+ var randChar = String . fromCharCode ( randInt ( 64 , 90 ) ) ; /*Numbers: 48-57 Al:64-90*/
59+ return string . substr ( 0 , i ) + randChar + string . substr ( i + 1 , string . length ) ;
60+ }
61+ }
62+ function applyCode ( string , codes ) {
63+ var len = codes . length ;
64+ var elem = document . createElement ( 'span' ) ,
65+ obfuscated = false ;
66+ for ( var i = 0 ; i < len ; i ++ ) {
67+ elem . style . cssText += styleMap [ codes [ i ] ] + ';' ;
68+ if ( codes [ i ] === '§k' ) {
69+ obfuscate ( string , elem ) ;
70+ obfuscated = true ;
71+ }
72+ }
73+ if ( ! obfuscated ) elem . innerHTML = string ;
74+ return elem ;
75+ }
76+ function parseStyle ( string ) {
77+ var codes = string . match ( / § .{ 1 } / g) || [ ] ,
78+ indexes = [ ] ,
79+ apply = [ ] ,
80+ tmpStr ,
81+ indexDelta ,
82+ noCode ,
83+ final = document . createDocumentFragment ( ) ,
84+ len = codes . length ,
85+ string = string . replace ( / \n | \\ n / g, '<br>' ) ;
86+
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 ] ) , [ ] ) ) ;
93+ }
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 ] ;
101+ }
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 ) ;
108+ }
109+ tmpStr = string . substring ( indexes [ i ] , indexes [ i + 1 ] ) ;
110+ final . appendChild ( applyCode ( tmpStr , apply ) ) ;
111+ }
112+ return final ;
113+ }
114+ function clearObfuscators ( ) {
115+ var i = obfuscators . length ;
116+ for ( ; i -- ; ) {
117+ clearInterval ( obfuscators [ i ] ) ;
118+ }
119+ obfuscators = [ ] ;
120+ }
121+ String . prototype . replaceColorCodes = function ( ) {
122+ clearObfuscators ( ) ;
123+ var outputString = parseStyle ( String ( this ) ) ;
124+ return outputString ;
125+ } ;
126+
127+ /////////////////////////////////////////////////
128+ function cutString ( str , cutStart , cutEnd ) {
129+ return str . substr ( 0 , cutStart ) + str . substr ( cutEnd + 1 ) ;
130+ }
0 commit comments