function
TagReplacement(str, fc, fs)
{
str = replaceTags(str,
"_"
,
"<b>"
,
"</b>"
);
str = replaceTags(str,
"\""
,
"<i>"
,
"</i>"
);
str = replaceTags(str,
'§'
,
'<span style="color: '
+ fc +
'; font-size: '
+ fs +
'px;">'
,
'</span>'
);
str = replaceSingleTags(str,
"#"
,
""
);
str = replaceSingleTags(str,
'\\'
,
''
);
return
str;
}
function
replaceTags(row, code, firstTag, secondTag)
{
var
chars = row.split(
""
);
first =
new
Boolean(
true
);
for
(
var
i
in
chars)
{
if
(chars[i] == code)
{
if
(i > 0 && chars[i - 1] ==
'\\'
)
continue
;
else
{
if
(first)
chars[i] = firstTag;
else
chars[i] = secondTag;
first = !first;
}
}
}
return
(chars.join(
""
));
}
function
replaceSingleTags(row, code, tag)
{
var
chars = row.split(
""
);
for
(
var
i
in
chars)
{
if
(chars[i] == code)
{
if
(i > 0 && chars[i - 1] ==
'\\'
)
continue
;
else
chars[i] = tag;
}
}
return
(chars.join(
""
));
}
function
KCode2HTML(string, bb, rr, fc, fs)
{
var
p =
new
RegExp(
'(°.*?°)'
);
var
m = p.exec(string);
var
occurences =
new
Array();
var
i = 0;
while
(m !=
null
)
{
occurences.push(m[1]);
string = string.replace(m[1],
"{"
+ i +
"}"
);
m = p.exec(string);
i++;
}
string = TagReplacement(string, fc, fs);
for
(
var
x
in
occurences)
{
string = string.replace(
"{"
+ x +
"}"
, detect(occurences[x], bb, rr, fc, fs));
}
return
string;
}
function
detect(code, bb, rr, fc, fs)
{
code = code.toString();
if
(code.substr(code.length - 2, 1) ==
"\\"
)
{
return
code.replace(
'\\'
,
''
);
}
code = code.replace(
"°"
,
""
);
code = code.replace(
"°"
,
""
);
var
ChatColorShortCuts =
new
Array(
"W"
,
"E"
,
"R"
,
"O"
,
"P"
,
"A"
,
"D"
,
"G"
,
"K"
,
"Y"
,
"C"
,
"B"
,
"N"
,
"M"
,
"BB"
,
"RR"
);
var
HTMLColors =
new
Array(
"#FFFFFF"
,
"#00AC00"
,
"#FF0000"
,
"#FFC800"
,
"#FFAFAF"
,
"#808080"
,
"#404040"
,
"#00FF00"
,
"#000000"
,
"#FFFF00"
,
"#00FFFF"
,
"#0000FF"
,
"#964A00"
,
"#FF00FF"
, bb, rr);
if
(!code.startsWith(
">"
) && !code.startsWith(
"BB>"
))
{
if
(code.startsWith(
"["
))
{
return
code;
}
if
(code ==
"r"
)
{
code =
'<span style="color: '
+ fc +
'; font-size: '
+ fs +
'px;">'
;
return
code;
}
if
(code ==
"!"
)
{
code =
'.........'
return
code;
}
if
(code.length > 2)
{
var
colorcode =
""
;
var
color =
""
;
var
size = 0;
for
(
var
y = 0; y <= 16; y++)
{
if
(code.substr(code.length - 2, 2) == ChatColorShortCuts[y])
{
color = HTMLColors[y];
colorcode = code.substr(code.length - 2, 2);
break
;
}
else
if
(code.substr(0, 2) == ChatColorShortCuts[y])
{
color = HTMLColors[y];
colorcode = code.substr(0, 2);
break
;
}
else
if
(code.substr(0, 1) == ChatColorShortCuts[y])
{
color = HTMLColors[y];
colorcode = code.substr(0, 1);
break
;
}
else
if
(code.substr(code.length - 1, 1) == ChatColorShortCuts[y])
{
color = HTMLColors[y];
colorcode = code.substr(code.length - 1, 1);
break
;
}
}
code = code.replace(colorcode,
""
);
if
(code.length > 0)
{
size = code;
return
'<span style="color: '
+ color +
'; font-size: '
+ size +
'px;">'
;
}
}
for
(
var
i = 0; i <= 16; i++)
if
(code == ChatColorShortCuts[i])
return
'<span style="color: '
+ HTMLColors[i] +
';">'
;
if
(
typeof
parseInt(code) ==
"number"
)
return
'<span style="font-size: '
+ code +
'px;">'
;
}
else
{
if
(code.startsWith(
">_"
) || code.startsWith(
"BB>"
) || code.contains(
'|'
))
{
var
fontColor =
""
;
var
fontWeight =
'normal'
;
var
textDecoration =
''
;
if
(code.startsWith(
'BB'
)){
fontColor = bb;
textDecoration =
'underline'
}
if
(code.contains(
'_'
))
fontWeight =
'bold'
;
var
specialFormat =
' style="color: rgb('
+ fontColor +
'); font-weight:'
+ fontWeight +
'; text-decoration: '
+ textDecoration +
'"'
;
code = code.replace(
">_h"
,
""
);
code = code.replace(
">_"
,
""
);
code = code.replace(
"BB>"
,
""
);
code = code.replace(
"BB"
,
""
);
code = code.replace(
">"
,
""
);
var
params =
null
;
var
leadingImage =
""
;
if
(code.contains(
'<>'
)){
params = code.split(
'<>'
)[1].split(
'|'
);
leadingImage = code.split(
'<>'
)[0];
leadingImage = buildImageUrl(leadingImage);
}
else
{
params = code.split(
'|'
);
}
code = code.replace(
">"
,
""
);
code = code.replace(
"<"
,
""
);
var
elemt = document.createElement(
"span"
);
var
linkText = params[0];
var
leftClick = params[1];
var
rightClick = params[1];
if
(params.length >= 3){
rightClick = params[2];
rightClick = rightClick.replace(
'"'
, linkText);
elemt.oncontextmenu = linkRightClick;
}
else
elemt.oncontextmenu = linkLeftClick;
leftClick = leftClick.replace(
'"'
, linkText);
elemt.onclick = linkLeftClick;
if
(leadingImage ==
""
)
return
'<span '
+ specialFormat +
' class="linkedContent" name="'
+ leftClick +
'|'
+ rightClick +
'">'
+ linkText +
'</span>'
;
else
return
'<img src="'
+ leadingImage +
'"><span '
+ specialFormat +
' class="linkedContent" name="'
+ leftClick +
'|'
+ rightClick +
'">'
+ linkText +
'</span>'
;
}
else
if
(code.startsWith(
">sm_"
))
{
var
bgImg =
""
;
if
(code.contains(
'<>'
))
{
bgImg = code.split(
'<>'
)[0];
bgImg = bgImg.replace(
'>'
);
code = code.split(
'<>'
)[1];
}
code = code.replace(
">"
,
""
);
code = code.replace(
"<"
,
""
);
code = buildImageUrl(code);
return
'<img style="background-image: url('
+ bgImg +
');" src="'
+ code +
'">'
;
}
}
return
code;
}
function
buildImageUrl(code){
var
end =
""
;
if
(code.endsWith(
".png"
))
end =
".png"
;
else
if
(code.endsWith(
".jpg"
))
end =
".jpg"
;
else
if
(code.endsWith(
".gif"
))
end =
".gif"
;
if
(code.contains(
'/'
) && !code.contains(
"features"
) && !code.contains(
"icons"
))
code = code.split(
'/'
)[code.split(
'/'
).Length - 1];
if
(code.contains(
"..."
))
code = code.substring(0, code.indexOf(
"..."
));
code = code.replace(
"?"
,
"´"
);
code = code.replace(
"%"
,
"~"
);
if
(!code.endsWith(
".png"
) && !code.endsWith(
".jpg"
) && !code.endsWith(
".gif"
))
code += end;
if
(!code.contains(
"pics"
))
code =
"knuddels.de"
+
"/pics/"
+ code;
else
code =
"knuddels.de"
+
"/"
+ code;
return
code;
}