-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtagparse.js
189 lines (171 loc) · 7.89 KB
/
tagparse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Outer Heaven - Custom Tag Parse Code (2018-03-20)
let chipData = {}, reduceChip = {}, virusData = {}, terrainData = {};
const chipFetch = fetch("https://execfera.github.io/rern/chip.json")
.then(res => res.json())
.then(data => {
chipData = data;
reduceChip = Object.keys(chipData).reduce(function (keys, k) {
keys[k.toLowerCase()] = k;
if (k[k.length - 1] === '1') keys[k.toLowerCase().slice(0, -1)] = k;
return keys;
}, {});
});
const virusFetch = fetch("https://execfera.github.io/rern/virus.json")
.then(res => res.json())
.then(data => virusData = data);
const terrainFetch = fetch("https://execfera.github.io/rern/terrain.json")
.then(res => res.json())
.then(data => terrainData = data);
function chipTagReplace(name, param) {
let elcolor;
switch (chipData[name].elem) {
case "Fire": elcolor = "<font color=#d22700>" + name + "</font>"; break;
case "Aqua": elcolor = "<font color=#6495ed>" + name + "</font>"; break;
case "Elec": elcolor = "<font color=orange>" + name + "</font>"; break;
case "Wood": elcolor = "<font color=#00c96b>" + name + "</font>"; break;
default: elcolor = name; break;
}
switch(param) {
case "i":
return `<img src='https://execfera.github.io/rern/chip/${name}.png'>`;
case "s":
return `${chipData[name].summ} (Acc: ${chipData[name].acc})`;
case "f":
return `<img src='https://execfera.github.io/rern/chip/${name.replace('+','')}.png'> <span class='chip'><span class='chipclick'>${name}</span><span class='chipbody'>${chipData[name].desc}<br>Trader Rank: ${chipData[name].rank}</span></span>`;
case "a":
if (!("alias" in chipData[name])) return match;
else return `<img src='https://execfera.github.io/rern/chip/${name.replace('+','')}.png'> <span class='chip'><span class='chipclick'>${chipData[name].alias}</span><span class='chipbody'>${chipData[name].desc}<br>Trader Rank: ${chipData[name].rank}</span></span>`;
case "c":
return `<img src='https://execfera.github.io/rern/chip/${name.replace('+','')}.png'> <span class='chip'><span class='chipclick'>${elcolor}</span><span class='chipbody'>${chipData[name].desc}<br>Trader Rank: ${chipData[name].rank}</span></span>`; break;
default:
return `<img src='https://execfera.github.io/rern/chip/${name.replace('+','')}.png'> <span class='chip'><span class='chipclick'>${elcolor}</span><span class='chipbody'>${chipData[name].desc}</span></span>: ${chipData[name].summ} (Acc: ${chipData[name].acc})`;
}
}
function chipTagFunction () {
$("body").unbind("click");
$("body").click(function(event) {
$("[class*=' bbcode-popup'], [class^='bbcode-popup']").hide();
$(".chipbody").hide();
}).click();
$(".chipclick").unbind("click");
$(".chipclick").click(function(event) {
$(this).next().toggle();
event.stopPropagation();
});
$(".chipbody, [class*=' bbcode-popup'], [class^='bbcode-popup']").unbind("click");
$(".chipbody, [class*=' bbcode-popup'], [class^='bbcode-popup']").click(function(event) {
event.stopPropagation();
});
$("[class^='bbcode-click']").each(function() {
$(this).attr('class').split(' ').forEach(cls => {
let matcl = cls.match(/bbcode-click(.+?)$/);
if(matcl && matcl[1]) {
if ($(".bbcode-popup"+matcl[1]).length > 0) {
$(".bbcode-click"+matcl[1]+", .bbcode-popup"+matcl[1]).wrapAll("<span class='bbcode-poppos'></span>");
}
$(".bbcode-click"+matcl[1]).unbind("click");
$(".bbcode-click"+matcl[1]).css("cursor</li></ul>","pointer");
$(".bbcode-click"+matcl[1]).click(function(event) {
$(".bbcode-hide"+matcl[1]).toggle();
$(".bbcode-popup"+matcl[1]).css('display',$(".bbcode-popup"+matcl[1]).css('display')==="none"?"block":"none");
if ($(".bbcode-swap"+matcl[1]).length === 1 && $(".bbcode-click"+matcl[1]).length === 1) {
$(".bbcode-click"+matcl[1]).replaceWith($(".bbcode-swap"+matcl[1]).clone(true));
$(".bbcode-swap"+matcl[1]).eq(1).empty();
$(".bbcode-swap"+matcl[1]).eq(0).show();
}
event.stopPropagation();
});
}
});
});
$("div.spoiler_toggle").unbind("click");
$("div.spoiler_toggle").click(function(event) {
$(this).next().toggle();
event.stopPropagation();
});
}
function virusTagFunction() {
$(".vr_tag").css("cursor", "pointer").click(function() {
openVrWnd($(this).attr("name") ? $(this).attr("name") : $(this).text());
});
}
function openVrWnd(srcname) {
var found = false;
var foundidx = 0;
var foundkey = "";
var foundentry1 = "";
var foundentry2 = "";
for (var key in virusData) {
for (var i = 0; i <= 6; i++) {
if (virusData[key].virus[i].name === srcname) {
found = true;
foundkey = key;
foundidx = i;
break;
}
}
}
if (found === true) {
foundentry1 = "<strong>" + virusData[foundkey].virus[foundidx].name + "</strong> <a href='javascript:window.open(\""
foundentry2 = "\", window.opener, false); window.close();'>(" + foundkey + ")</a><br><br>";
if (virusData[foundkey].family_note !== "") foundentry2 += (virusData[foundkey].family_note + "<br><br>");
foundentry2 += "Area:";
if (virusData[foundkey].family_area.length === 0) { foundentry2 += " All<br><br>"; }
else if (foundidx === 6) { foundentry2 += " Undernet<br><br>"; }
else {
for (var i = 0; i < virusData[foundkey].family_area.length; i++) {
if (i === virusData[foundkey].family_area.length-1) foundentry2 += " " + virusData[foundkey].family_area[i] + "<br><br>";
else foundentry2 += " " + virusData[foundkey].family_area[i] + ",";
}
}
foundentry2 += virusData[foundkey].virus[foundidx].desc;
var oWindow = window.open("", "", "height=640,width=480");
with (oWindow.document) {
write("");
write("");
write("<title>"+srcname+"<\/title>");
write("<\/head>");
write("<body style=\"background-color: #eeeeee; font-family: \'Inconsolata\', \'Helvetica\', \'Arial\', \'Bitstream Vera Sans\', \'Verdana\', sans-serif; font-size:93.3%;\">");
write(foundentry1);
write(encodeURI(virusData[foundkey].family_url));
write(foundentry2);
write("<hr>");
write("<input type='button' value='Close' onclick='window.close()'>");
write("<\/body>");
write("<\/html>");
close();
}
}
else alert("Virus entry not found.");
}
function tagInit() {
Promise.all([chipFetch, virusFetch, terrainFetch])
.then(() => {
$('.c_post:not(:has("textarea")), .c_sig:not(:has("textarea")), #topic_review').each(function() {
$(this).html($(this).html().replace(/\[chip=([^,\]]*)(,(i|s|f|a|c))?\]/gi, function(match, p1, p2, p3) {
if (!(p1.toLowerCase() in reduceChip)) return match;
return chipTagReplace(reduceChip[p1.toLowerCase()],p3);
}));
$(this).html($(this).html().replace(/\[terrain]([^[]*)\[\/terrain]/gi, function(match, p1) {
if (!(p1 in terrainData)) return p1;
return `<span class='chip'><span class='chipclick'>${p1}</span><span class='chipbody'>${terrainData[p1]}</span></span>`;
}));
$(this).html($(this).html().replace(/\[virus]([^[]*)\[\/virus]/gi, function(match, p1) {
return "<span class='vr_tag'>" + p1 + "</span>";
}));
$(this).html($(this).html().replace(/\[virus=([^[]*)]([^[]*)\[\/virus]/gi, function(match, p1, p2) {
return "<span class='vr_tag' name=" + p1 + ">" + p2 + "</span>";
}));
$(this).html($(this).html().replace(/\[furl=([0-9]*)(,([0-9]*),([0-9]*))?](.+?(?=\[\/furl]))\[\/furl]/gi, function(match, topic, p1, page, post, text) {
if (!p1) return "<a href ='" + $.zb.stat.url + "topic/" + topic + "/1/' target='_blank' rel='nofollow'>" + text + "</a>";
else return "<a href ='" + $.zb.stat.url + "topic/" + topic + "/" + page + "/#post-" + post + "' target='_blank' rel='nofollow'>" + text + "</a>";
}));
$(this).html($(this).html().replace(/\[imgur=([^\]]*)]/gi, function(match, id) {
return "<img src='http://i.imgur.com/" + id + ".png' alt='Posted Image'>";
}));
});
chipTagFunction();
virusTagFunction();
});
};
window.addEventListener('DOMContentLoaded', tagInit, false);