Skip to content

Commit 5a3607d

Browse files
author
FoxInFlame
authored
Merge pull request FoxInFlame#3 from huupoke12/master
Fixed the errors caused obfuscated string not working and browser crashing
2 parents 74e953b + fc88e42 commit 5a3607d

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

MinecraftColorCodes.3.7.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
var obfuscators = [];
23
var styleMap = {
34
'§4': 'font-weight:normal;text-decoration:none;color:#be0000',
@@ -23,10 +24,11 @@ var styleMap = {
2324
};
2425
function obfuscate(string, elem) {
2526
var magicSpan,
26-
currNode;
27+
currNode,
28+
len = elem.childNodes.length;
2729
if(string.indexOf('<br>') > -1) {
2830
elem.innerHTML = string;
29-
for(var j = 0, len = elem.childNodes.length; j < len; j++) {
31+
for(var j = 0; j < len; j++) {
3032
currNode = elem.childNodes[j];
3133
if(currNode.nodeType === 3) {
3234
magicSpan = document.createElement('span');
@@ -58,11 +60,11 @@ function obfuscate(string, elem) {
5860
}
5961
}
6062
function applyCode(string, codes) {
63+
var len = codes.length;
6164
var elem = document.createElement('span'),
6265
obfuscated = false;
63-
for(var i = 0, len = codes.length; i < len; i++) {
66+
for(var i = 0; i < len; i++) {
6467
elem.style.cssText += styleMap[codes[i]] + ';';
65-
if(codes[i] === '§l')
6668
if(codes[i] === '§k') {
6769
obfuscate(string, elem);
6870
obfuscated = true;
@@ -76,19 +78,20 @@ function parseStyle(string) {
7678
indexes = [],
7779
apply = [],
7880
tmpStr,
79-
deltaIndex,
81+
indexDelta,
8082
noCode,
8183
final = document.createDocumentFragment(),
82-
i;
83-
string = string.replace(/\n|\\n/g, '<br>');
84-
for(i = 0, len = codes.length; i < len; i++) {
84+
len = codes.length,
85+
string = string.replace(/\n|\\n/g, '<br>');
86+
87+
for(var i = 0; i < len; i++) {
8588
indexes.push( string.indexOf(codes[i]) );
8689
string = string.replace(codes[i], '\x00\x00');
8790
}
8891
if(indexes[0] !== 0) {
8992
final.appendChild( applyCode( string.substring(0, indexes[0]), [] ) );
9093
}
91-
for(i = 0; i < len; i++) {
94+
for(var i = 0; i < len; i++) {
9295
indexDelta = indexes[i + 1] - indexes[i];
9396
if(indexDelta === 2) {
9497
while(indexDelta === 2) {
@@ -124,4 +127,4 @@ String.prototype.replaceColorCodes = function() {
124127
/////////////////////////////////////////////////
125128
function cutString(str, cutStart, cutEnd){
126129
return str.substr(0,cutStart) + str.substr(cutEnd+1);
127-
}
130+
}

MinecraftColorCodes.min.3.7.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)