-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransAssist.user.js
291 lines (280 loc) · 12.8 KB
/
transAssist.user.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// ==UserScript==
// @name 光辉物语翻译辅助
// @namespace hoothin
// @version 0.3.6
// @description 为光辉物语汉化项目在腾讯文档顶部添加翻译辅助按钮,点击条目后增加翻译直达按钮
// @author hoothin
// @match https://docs.qq.com/sheet/DWnZ6a2hpUkJRd2JZ*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_setClipboard
// @license MIT License
// ==/UserScript==
(function() {
'use strict';
const wordPlace = [
["Vainqueur","ヴァンクール","梵奎尔"],
["Cygnus","シグナス","希格纳斯"],
["Alistel","アリステル","阿里斯特尔"],
["Granorg","グランオルグ","格兰奥冈"],
["Imperial Ruins","帝国跡地","帝国遗迹"],
["Audience Hall","謁見の間","谒见之间"],
["Palace","王宮","王宫"],
["El Dorado","エルドラド","埃尔多拉多"],
["Cornet Village","コルネ村","科恩村"],
["Alma Mine","アルマ鉱山","阿尔玛矿山"],
["downtown","観光区","观光区"],
["Gran Plain","グラン平原","格兰平原"],
["lodging","宿屋","旅馆"],
["Forest Square","森の広場","森之广场"],
["South Hill","南の高台","南之高台"],
["south hill","南の丘","南之丘"],
["sewers","地下水路","下水道"],
["lookout","展望台","展望台"],
["Lazvil Hills","ラズヴィル丘陵","拉斯维尔丘陵"],
["Sand Fortress","砂の砦","砂之要塞"],
["Judgement Cliffs","裁きの断崖","裁决断崖"],
["","コルネ","科恩"],
["","秘密の場所","秘密基地"],
["commercial district","商業区","商业区"],
["Skalla","スカラ","斯卡拉"],
["Itolia","イトリア","伊托利亚"],
["Itolia Wasteland","イトリア荒野","伊托利亚荒野"],
["","書の迷宮","书之迷宫"],
["Celestia","セレスティア","塞拉斯提亚"]
];
const wordName = [
["Marco","マルコ","马尔科"],
["Eruca","エルーカ","艾露卡"],
["Selvan","セルバン","塞尔凡"],
["Stocke","ストック","斯托克"],
["Dias","ディアス","迪亚斯"],
["Queen","Eruca","艾露卡女王"],
["Sir Dias","ディアス様","迪亚斯爵士"],
["Protea","プロテア","普罗蒂亚"],
["Resistance","レジスタンス","抵抗军"],
["Queen Protea","プロテア女王","普罗蒂亚女王"],
["","ウィル","威尔"],
["Princess Eruca","","艾露卡王女"],
["Lady Eruca","エルーカ様","艾露卡大人"],
["Count Selvan","セルバン伯爵","塞尔凡伯爵"],
["Prophet Noah","ノア様","诺亚先知"],
["Liese","リーズ","莉丝"],
["Rosch","ロッシュ","罗施"],
["Field Marshal Viola","ビオラ准将","薇奥拉准将"],
["Aht","アト","阿托"],
["Granorg army","グランオルグ騎士団","格兰奥冈骑士团"],
["Hugo","","雨果"],
["Noah guy","","诺亚大人"],
["Fennel","フェンネル","芬内鲁"],
["Bram","ブラム","布拉姆"],
["Sir Dias","騎士団長ディアス","骑士团长迪亚斯"],
["Garland","ガーランド","加兰德"],
["rebel troops","反乱軍","叛军"],
["King Viktor","ヴィクトール様","维克托国王"],
["High Colonel Dias","ディアス将軍","迪亚斯将军"],
["Hilster","ヒルスター","希尔斯特"],
["Heiss","ハイス","海斯"],
["Desert Crows","砂漠のカラス","沙漠乌鸦"],
["thieves","怪盗","怪盗"],
["Ricky","リッキー","瑞奇"],
["troops","従士隊","侍从部队"],
["Pierre","","皮埃尔"],
["","新兵部隊","新兵部队"],
["Raynie","レイニー","蕾妮"],
["Valkyrie","戦女神","女武神"],
["Lt. General Raul","ラウル","劳尔中将"],
["Desert Crow","砂漠のカラス","砂漠之鸦"],
["Golhda","ゴルダ","戈尔达"],
["Kaizan","カイザン","凯赞"],
["Vanoss","バノッサ","瓦诺萨"],
["Gutral","ブルート","古特尔"],
["Gafka","ガフカ","加夫卡"],
["Bergas","ベルガ","贝尔加"],
["Galva","ガルヴァ","加尔瓦"],
["Lieutenant Stocke","ストック中尉","斯托克中尉"],
["Sergeant","副隊長","副队长"],
["Rosch's brigade","ロッシュ隊","罗施部队"],
["Anna","アンナ","安娜"],
["Nemesia","ネメシア","妮米西亚"],
["Ernst","エルンスト","恩斯特"],
["Lippti","リプティ","莉普缇"],
["Teo","ティオ","提奥"],
["General Hugo","ヒューゴ大将","雨果大将"],
["Young Lion","","幼狮"],
["Tarquin","タルキン","塔昆"],
["Ditto","ディトー","迪托"],
["Captain Rosch","ロッシュ隊長","罗施队长"],
["Sergeant","中尉","中尉"],
["Sergeant","少尉","少尉"],
["Lieutenant","","中尉"],
["Cedric","","塞德里克"],
["Samra","サムラ","萨姆拉"],
["Wand","ワンド","万德"],
["Sonja","ソニア","索尼娅"]
];
const wordItem = [
["Divine Water","神聖水","圣水"],
["Death Crimson","デスクリムゾン","死亡猩红"],
["Sand Sword","砂の剣","沙剑"],
["Anti−Curse","アンチカース","反诅咒"],
["Red Knife","レッドナイフ","红刀"],
["Tourniquets","救命薬","救命药"],
["thaumatech","魔動機械","魔动机械"],
["Element Shell","エレメントシェル","元素外壳"],
["Celes Branch","セレスのえだ","赛雷斯之枝"],
["Thaumachine","魔動兵","魔动兵"],
["ivy","","藤蔓"],
["produce","食材","食材"],
["soothing balm","","舒缓香膏"],
["charm","","护身符"],
["Herbal Tea","","药草茶"],
["Holy Water","","复苏之水"],
["Almakalite","アルマラカイト","孔雀石"],
["Withered Branch","かわいた木","干枯树枝"],
["Beast God's Nail","獣神の爪","兽神之爪"],
["senior disciple","兄弟子","大弟子"],
["Etherion","エーテリオン","以太宝石"],
["monocle","モノクル","单片眼镜"],
["Goblin Killer","ゴブリンころし","哥布林杀手"],
["Anti-Sleep","アンチスリープ","防睡眠剂"],
["Mana Crystal","マナの結晶","法力水晶"],
["Artifact","アーティファクト","神器"],
["conut","コルナッツ","科恩果"],
["Alma coal","アルマ石炭","阿尔玛石炭"]
];
const wordOther = [
["White Chronicle","白示録","白示录"],
["Strike","スマッシュ","打击"],
["swordsman","剣士","剑士"],
["possible world","可能性世界","可能性世界"],
["node","刻印","刻印"],
["Alistellians","","阿里斯特尔人"],
["Beastkind","獣人","兽人"],
["giant boar","大イノシシ","大野猪"],
["skills","","武技"],
["goblin","ゴブリン","哥布林"],
["change","","变换"],
["Mana","マナ","法力"],
["timeline","","时间线"],
["obtained","手に入れた","获得"],
["White Page","白示録の切れ端","白示录的残页"],
["sword dancing","剣舞","剑舞"],
["Gutral","ブルート","猩人"],
["Satyros","サテュロス","羊人"],
["shaman","シャーマン","萨满"],
["joined the party","パーティに加わった","加入了你的队伍"]
];
var transBody = "";
var tagCon,btnOrder,txtCount;
function initListener() {
let container = document.querySelector("div.excel-container");
let formulaInput = document.querySelector("div.formula-input");
let barLabel = document.querySelector("div.bar-label");
if (!container || !formulaInput || !barLabel) {
setTimeout(() => {
initListener();
}, 500);
return;
}
container.addEventListener("click", e => {
if(/^C/.test(barLabel.innerText)){
txtCount.innerText = formulaInput.innerText.trim().length;
return;
}
let targetText = formulaInput.innerText.split("\n");
targetText = targetText.slice(0, parseInt(targetText.length - 2));
targetText = targetText.join("\n").replace(/\<p\>/g,"\n").replace(/\<.*?\>/g," ");
transBody = dbC2sbC(targetText).trim();
if(transBody){
btnOrder.style.display = "";
tagCon.innerHTML = "";
checkWord(wordPlace, transBody);
checkWord(wordName, transBody);
checkWord(wordItem, transBody);
checkWord(wordOther, transBody);
}
});
}
function initView() {
btnOrder = document.createElement("div");
btnOrder.style.cssText = "position: fixed;top: 10px;width: 100%;z-index: 9;text-align: center;pointer-events: none;display: none";
var transSpan = document.createElement("span");
var gooBtn = createTransBtn("Google", (target) => {
window.open(`https://translate.google.cn/?client=gtx&dj=1&q=${target}&sl=auto&tl=zh-CN&hl=zh-CN&ie=UTF-8&oe=UTF-8&source=icon&dt=t&dt=bd`,'_blank','height=600,width=800,left=30,top=30,location=no,status=no,toolbar=no,menubar=no,scrollbars=yes');
});
var bdBtn = createTransBtn("Baidu", (target) => {
window.open(`https://fanyi.baidu.com/#auto/zh/${target}`,'_blank','height=600,width=1200,left=30,top=30,location=no,status=no,toolbar=no,menubar=no,scrollbars=yes');
});
var deeplBtn = createTransBtn("Deepl", (target) => {
window.open(`https://www.deepl.com/zh/translator#auto/zh/${target}`,'_blank','height=600,width=800,left=30,top=30,location=no,status=no,toolbar=no,menubar=no,scrollbars=yes');
});
var papagoBtn = createTransBtn("Papago", (target) => {
window.open(`https://papago.naver.com/?sk=auto&tk=zh-CN&st=${target}`,'_blank','height=600,width=800,left=30,top=30,location=no,status=no,toolbar=no,menubar=no,scrollbars=yes');
});
transSpan.style.cssText = "padding-right: 5px;pointer-events: all;";
transSpan.appendChild(gooBtn);
transSpan.appendChild(bdBtn);
transSpan.appendChild(deeplBtn);
transSpan.appendChild(papagoBtn);
btnOrder.appendChild(transSpan);
tagCon = document.createElement("span");
tagCon.style.pointerEvents="all";
btnOrder.appendChild(tagCon);
txtCount = document.createElement("span");
txtCount.style.margin = "10px";
btnOrder.appendChild(txtCount);
document.body.appendChild(btnOrder);
}
function createTransBtn(serverName, clickFun) {
var transBtn = document.createElement("button");
transBtn.style.cssText = "padding: 3px;cursor: pointer;"
transBtn.innerText = serverName;
transBtn.addEventListener("click", e=>{
if(transBody){
clickFun(encodeURIComponent(transBody));
}
});
return transBtn;
}
function checkWord(dictArr, str) {
dictArr.forEach(target => {
if(target.length != 3)return;
if((target[0] && new RegExp("\\b"+target[0]+"['s]*\\b","i").test(str)) || (target[1] && str.indexOf(target[1]) != -1)){
createTag(target[2]);
}
});
}
function createTag(str){
var tagBtn = document.createElement("button");
tagBtn.style.cssText = "padding: 3px;cursor: pointer;";
tagBtn.innerText = str;
tagBtn.title = "点击复制";
tagBtn.addEventListener("click", e => {
GM_setClipboard(str);
tagBtn.innerText = "复制成功";
setTimeout(()=>{if(tagBtn && tagBtn.parentNode)tagBtn.innerText = str;}, 500);
});
tagCon.appendChild(tagBtn);
}
function dbC2sbC(str){
var result="",d;
for(var i=0;i<str.length;i++) {
var code = str.charCodeAt(i);
if (code >= 65281 && code <= 65373) {
d=str.charCodeAt(i)-65248;
result += String.fromCharCode(d);
} else if (code == 12288) {
d=str.charCodeAt(i)-12288+32;
result += String.fromCharCode(d);
} else {
result += str.charAt(i);
}
}
return result;
}
function init() {
initView();
initListener();
}
init();
})();