mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-19 09:45:28 +01:00
Improving MOTD
This commit is contained in:
parent
ebf00a1900
commit
2e5299e521
@ -22,19 +22,17 @@ var styleMap = {
|
|||||||
'§o': 'font-style:italic',
|
'§o': 'font-style:italic',
|
||||||
};
|
};
|
||||||
function obfuscate(string, elem) {
|
function obfuscate(string, elem) {
|
||||||
var magicSpan,
|
var magicSpan;
|
||||||
currNode;
|
|
||||||
if (string.indexOf('<br>') > -1) {
|
if (string.indexOf('<br>') > -1) {
|
||||||
elem.innerHTML = string;
|
elem.innerHTML = string;
|
||||||
for(var j = 0, len = elem.childNodes.length; j < len; j++) {
|
elem.childNodes.array.forEach(currNode => {
|
||||||
currNode = elem.childNodes[j];
|
|
||||||
if (currNode.nodeType === 3) {
|
if (currNode.nodeType === 3) {
|
||||||
magicSpan = document.createElement('span');
|
magicSpan = document.createElement('span');
|
||||||
magicSpan.innerHTML = currNode.nodeValue;
|
magicSpan.innerHTML = currNode.nodeValue;
|
||||||
elem.replaceChild(magicSpan, currNode);
|
elem.replaceChild(magicSpan, currNode);
|
||||||
init(magicSpan);
|
init(magicSpan);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
} else {
|
} else {
|
||||||
init(elem, string);
|
init(elem, string);
|
||||||
}
|
}
|
||||||
@ -60,52 +58,31 @@ function obfuscate(string, elem) {
|
|||||||
function applyCode(string, codes) {
|
function applyCode(string, codes) {
|
||||||
var elem = document.createElement('span'),
|
var elem = document.createElement('span'),
|
||||||
obfuscated = false;
|
obfuscated = false;
|
||||||
string = string.replace(/\x00*/g, '');
|
codes.forEach(code => {
|
||||||
for(var i = 0, len = codes.length; i < len; i++) {
|
elem.style.cssText += styleMap[code] + ';';
|
||||||
elem.style.cssText += styleMap[codes[i]] + ';';
|
if (code === '§k') {
|
||||||
if(codes[i] === '§k') {
|
|
||||||
obfuscate(string, elem);
|
obfuscate(string, elem);
|
||||||
obfuscated = true;
|
obfuscated = true;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
if (!obfuscated) elem.innerHTML = string;
|
if (!obfuscated) elem.innerHTML = string;
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
function parseStyle(string) {
|
function parseStyle(string) {
|
||||||
var codes = string.match(/§.{1}/g) || [],
|
var final = document.createDocumentFragment();
|
||||||
indexes = [],
|
console.log("STRING : " + string)
|
||||||
apply = [],
|
|
||||||
tmpStr,
|
|
||||||
deltaIndex,
|
|
||||||
noCode,
|
|
||||||
final = document.createDocumentFragment(),
|
|
||||||
i;
|
|
||||||
string = string.replace(/\n|\\n/g, '<br>');
|
string = string.replace(/\n|\\n/g, '<br>');
|
||||||
for(i = 0, len = codes.length; i < len; i++) {
|
string = string.split('§r');
|
||||||
indexes.push( string.indexOf(codes[i]) );
|
string.forEach(item => {
|
||||||
string = string.replace(codes[i], '\x00\x00');
|
var apply = [];
|
||||||
}
|
if (item.length > 0) {
|
||||||
if(indexes[0] !== 0) {
|
apply = item.match(/§.{1}/g) || [];
|
||||||
final.appendChild( applyCode( string.substring(0, indexes[0]), [] ) );
|
apply.forEach(code => {
|
||||||
}
|
item = item.replace(code, '')
|
||||||
for(i = 0; i < len; i++) {
|
});
|
||||||
indexDelta = indexes[i + 1] - indexes[i];
|
final.appendChild(applyCode(item, apply));
|
||||||
if(indexDelta === 2) {
|
|
||||||
while(indexDelta === 2) {
|
|
||||||
apply.push ( codes[i] );
|
|
||||||
i++;
|
|
||||||
indexDelta = indexes[i + 1] - indexes[i];
|
|
||||||
}
|
|
||||||
apply.push ( codes[i] );
|
|
||||||
} else {
|
|
||||||
apply.push( codes[i] );
|
|
||||||
}
|
|
||||||
if( apply.lastIndexOf('§r') > -1) {
|
|
||||||
apply = apply.slice( apply.lastIndexOf('§r') + 1 );
|
|
||||||
}
|
|
||||||
tmpStr = string.substring( indexes[i], indexes[i + 1] );
|
|
||||||
final.appendChild( applyCode(tmpStr, apply) );
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
return final;
|
return final;
|
||||||
}
|
}
|
||||||
function clearObfuscators() {
|
function clearObfuscators() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user