-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
148 lines (135 loc) · 3.58 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>新同文堂</title>
<meta charset="utf-8">
<script src="./lib/tongwen_opera_init.js"></script>
<script src="./lib/tongwen_table_ss2t.js"></script>
<script src="./lib/tongwen_table_st2s.js"></script>
<script type="text/javascript">
// 合併新舊版本的設定值
function mergeConfig() {
if (typeof localStorage["tongwen"] === "undefined") {
localStorage["tongwen"] = JSON.stringify(tongwen);
} else {
oTongwen = JSON.parse(localStorage["tongwen"]);
for (var i in oTongwen) {
if (i == "version") {
if (parseFloat(oTongwen[i]) < 0.4) {
oTongwen.fontCustom.enable = tongwen.fontCustom.enable;
oTongwen.fontCustom.trad = tongwen.fontCustom.trad;
oTongwen.fontCustom.simp = tongwen.fontCustom.simp;
}
continue;
}
tongwen[i] = oTongwen[i];
}
if (typeof tongwen.userPhrase["enable"] === "undefined") {
tongwen.userPhrase["enable"] = false;
}
localStorage["tongwen"] = JSON.stringify(tongwen); // 回存設定
}
}
// 重新載入設定值
function reloadConfig() {
tongwen = JSON.parse(localStorage["tongwen"]);
}
// 點選圖示動作
function iconAction(tab) {
var data = {
'act' : '',
'tongwen': tongwen
};
data.tongwen['symbolS2T'] = symbolS2T;
data.tongwen['symbolT2S'] = symbolT2S;
switch (tongwen.iconAction) {
case "trad":
data.act = 'btnTrad';
tab.postMessage(data);
break;
case "simp":
data.act = 'btnSimp';
tab.postMessage(data);
break;
default:
data.act = 'btnAuto';
tab.postMessage(data);
}
}
function urlFilterAction(uri) {
var lst = tongwen.urlFilter.list, i = 0, c = 0,
url = '', re = null;
for (i = 0, c = lst.length; i < c; i++) {
if (lst[i].url.indexOf("*")) {
// var url = lst[i].url.replace(/(\W+)/ig, "\\$1").replace("*.", "*\\.").replace(/\*/ig, "\\w*"); // 較為嚴謹
url = lst[i].url.replace(/(\W)/ig, "\\$1").replace(/\\\*/ig, "*").replace(/\*/ig, ".*"); // 寬鬆比對
re = new RegExp("^" + url + "$","ig");
if (uri.match(re) !== null) {
return lst[i].zhflag;
}
} else if (uri == lst[i].url) {
return lst[i].zhflag;
}
}
return "";
}
function docLoaded(tab, uri) {
// 自動轉換
var
zhflag = '',
data = {
'act': '',
'tongwen': tongwen
};
data.tongwen['symbolS2T'] = symbolS2T;
data.tongwen['symbolT2S'] = symbolT2S;
if (tongwen.urlFilter.enable) {
zhflag = urlFilterAction(uri);
}
if (zhflag === '') {
zhflag = tongwen.autoConvert;
}
// 轉換標點符號
if (tongwen.symConvert) {
}
switch (zhflag) {
case 'trad':
data.act = 'btnTrad';
tab.postMessage(data);
break;
case 'simp':
data.act = 'btnSimp';
tab.postMessage(data);
break;
default:
}
}
var conList = [];
window.addEventListener("load", function TongWenInit() {
var btnTongwen = null, uiToolbarProperties = null;
mergeConfig();
uiToolbarProperties = {
disabled: false,
title: '新同文堂',
icon: './icons/icon-16.png',
onclick: function (e) {
var tab = opera.extension.tabs.getFocused();
iconAction(tab);
}
}
btnTongwen = opera.contexts.toolbar.createItem(uiToolbarProperties);
opera.contexts.toolbar.addItem(btnTongwen);
opera.extension.onmessage = function(event) {
// opera.postError(event.origin);
switch (event.data) {
case 'docLoaded':
docLoaded(event.source, event.origin);
break;
}
};
}, false );
</script>
</head>
<body>
</body>
</html>