Skip to content

Commit 3eda266

Browse files
author
FoxInFlame
committed
Create MinecraftColorCodes.3.7.js
1 parent 48292f4 commit 3eda266

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

MinecraftColorCodes.3.7.js

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

0 commit comments

Comments
 (0)