-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.js
50 lines (43 loc) · 1.36 KB
/
init.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
Plugins.OpenCC = {
orig_content: "data-opencc-orig-content",
self: this,
convert: function (id) {
const content = App.find(
App.isCombinedMode()
? `.cdm[data-article-id="${id}"] .content-inner`
: `.post[data-article-id="${id}"] .content`
);
const title = App.find(
App.isCombinedMode()
? `.cdm[data-article-id="${id}"] .title`
: `.post[data-article-id="${id}"] .title > a`
);
if (content.hasAttribute(self.orig_content)) {
content.innerHTML = content.getAttribute(self.orig_content);
content.removeAttribute(self.orig_content);
if (title.hasAttribute("title")) {
title.text = title.getAttribute("title");
}
if (App.isCombinedMode()) Article.cdmMoveToId(id);
return;
}
Notify.progress("Loading, please wait...");
xhr.json(
"backend.php",
App.getPhArgs("opencc", "convert", { id: id }),
(reply) => {
if (content && reply.content) {
content.setAttribute(self.orig_content, content.innerHTML);
content.innerHTML = reply.content;
if (reply.title) {
title.text = reply.title;
}
Notify.close();
if (App.isCombinedMode()) Article.cdmMoveToId(id);
} else {
Notify.error("Unable to convert via OpenCC for this article");
}
}
);
},
};