forked from syhyz1990/panAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanai.user.js
612 lines (571 loc) · 28 KB
/
panai.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
// ==UserScript==
// @name 网盘智能识别助手
// @namespace https://github.com/syhyz1990/panAI
// @version 1.8.5
// @author YouXiaoHou
// @description 智能识别选中文字中的🔗网盘链接和🔑提取码,识别成功打开网盘链接并自动填写提取码,省去手动复制提取码在输入的烦恼。支持识别 ✅百度网盘 ✅阿里云盘 ✅腾讯微云 ✅蓝奏云 ✅天翼云盘 ✅移动云盘 ✅迅雷云盘 ✅123云盘 ✅360云盘 ✅115网盘 ✅奶牛快传 ✅城通网盘 ✅夸克网盘 ✅FlowUs息流 ✅Chrome 扩展商店 ✅Edge 扩展商店 ✅Firefox 扩展商店 ✅Windows 应用商店。
// @license AGPL-3.0-or-later
// @homepage https://www.youxiaohou.com/tool/install-panai.html
// @supportURL https://github.com/syhyz1990/panAI
// @updateURL https://www.youxiaohou.com/panai.user.js
// @downloadURL https://www.youxiaohou.com/panai.user.js
// @match *://*/*
// @require https://unpkg.com/[email protected]/dist/sweetalert2.min.js
// @require https://unpkg.com/hotkeys-js/dist/hotkeys.min.js
// @resource swalStyle https://unpkg.com/[email protected]/dist/sweetalert2.min.css
// @run-at document-idle
// @grant GM_openInTab
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @grant GM_getResourceText
// @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMjggMTI4Ij48cGF0aCBkPSJNMTA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iM0NDQiLz48L3N2Zz4=
// ==/UserScript==
(function () {
'use strict';
const customClass = {
container: 'panai-container',
popup: 'panai-popup',
};
let toast = Swal.mixin({
toast: true,
position: 'top',
showConfirmButton: false,
timer: 3500,
timerProgressBar: false,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer);
toast.addEventListener('mouseleave', Swal.resumeTimer);
}
});
let util = {
clog(c) {
console.group('[网盘智能识别助手]');
console.log(c);
console.groupEnd();
},
parseQuery(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = location.search.substr(1).match(reg);
if (r != null) return (r[2]);
return null;
},
getValue(name) {
return GM_getValue(name);
},
setValue(name, value) {
GM_setValue(name, value);
},
sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
},
addStyle(id, tag, css) {
tag = tag || 'style';
let doc = document, styleDom = doc.getElementById(id);
if (styleDom) return;
let style = doc.createElement(tag);
style.rel = 'stylesheet';
style.id = id;
tag === 'style' ? style.innerHTML = css : style.href = css;
document.head.appendChild(style);
},
isHidden(el) {
try {
return el.offsetParent === null;
} catch (e) {
return false;
}
},
query(selector) {
if (Array.isArray(selector)) {
let obj = null;
for (let i = 0; i < selector.length; i++) {
let o = document.querySelector(selector[i]);
if (o) {
obj = o;
break;
}
}
return obj;
}
return document.querySelector(selector);
}
};
let opt = {
'baidu': {
reg: /((?:https?:\/\/)?(?:e?yun|pan)\.baidu\.com\/(doc\/|enterprise\/)?(?:s\/[\w~]*(((-)?\w*)*)?|share\/\S{4,}))/,
host: /(pan|e?yun)\.baidu\.com/,
input: ['#accessCode', '.share-access-code', '#wpdoc-share-page > .u-dialog__wrapper .u-input__inner'],
button: ['#submitBtn', '.share-access .g-button', '#wpdoc-share-page > .u-dialog__wrapper .u-btn--primary'],
name: '百度网盘',
storage: 'hash'
},
'aliyun': {
reg: /((?:https?:\/\/)?(?:(?:www\.)?aliyundrive\.com\/s|alywp\.net)\/[a-zA-Z\d]+)/,
host: /www\.aliyundrive\.com|alywp\.net/,
input: ['form .ant-input', 'form input[type="text"]'],
button: ['form .button--fep7l', 'form button[type="submit"]'],
name: '阿里云盘',
storage: 'hash'
},
'weiyun': {
reg: /((?:https?:\/\/)?share\.weiyun\.com\/[a-zA-Z\d]+)/,
host: /share\.weiyun\.com/,
input: ['.mod-card-s input[type=password]'],
button: ['.mod-card-s .btn-main'],
name: '微云',
storage: 'hash'
},
'lanzou': {
reg: /((?:https?:\/\/)?(?:[a-zA-Z0-9\-.]+)?lanzou[a-z]\.com\/[a-zA-Z\d_\-]+)/,
host: /(?:[a-zA-Z\d-.]+)?lanzou[a-z]\.com/,
input: ['#pwd'],
button: ['.passwddiv-btn', '#sub'],
name: '蓝奏云',
storage: 'hash'
},
'tianyi': {
reg: /((?:https?:\/\/)?cloud\.189\.cn\/(?:t\/|web\/share\?code=)?[a-zA-Z\d]+)/,
host: /cloud\.189\.cn/,
input: ['.access-code-item #code_txt'],
button: ['.access-code-item .visit'],
name: '天翼云盘',
storage: 'hash'
},
'caiyun': {
reg: /((?:https?:\/\/)?caiyun\.139\.com\/(?:m\/i|w\/i\/|web\/|front\/#\/detail)\??(?:linkID=)?[a-zA-Z\d]+)/,
host: /caiyun\.139\.com/,
input: ['.token-form input[type=text]'],
button: ['.token-form .btn-token'],
name: '移动云盘',
storage: 'local',
storagePwdName: 'tmp_caiyun_pwd'
},
'xunlei': {
reg: /((?:https?:\/\/)?pan\.xunlei\.com\/s\/[\w-]{10,})/,
host: /pan\.xunlei\.com/,
input: ['.pass-input-wrap .td-input__inner'],
button: ['.pass-input-wrap .td-button'],
name: '迅雷云盘',
storage: 'hash'
},
'123pan': {
reg: /((?:https?:\/\/)?www\.123pan\.com\/s\/[\w-]{6,})/,
host: /www\.123pan\.com/,
input: ['.ca-fot input'],
button: ['.ca-fot button'],
name: '123云盘',
storage: 'hash'
},
'360': {
reg: /((?:https?:\/\/)?(?:[a-zA-Z\d\-.]+)?yunpan\.360\.cn(\/lk)?\/surl_\w{6,})/,
host: /yunpan\.360\.cn/,
input: ['.pwd-input'],
button: ['.submit-btn'],
name: '360云盘',
storage: 'hash'
},
'115': {
reg: /((?:https?:\/\/)?115\.com\/s\/[a-zA-Z\d]+)/,
host: /115\.com/,
input: ['.form-decode input'],
button: ['.form-decode .submit a'],
name: '115网盘',
storage: 'hash'
},
'cowtransfer': {
reg: /((?:https?:\/\/)?(?:[a-zA-Z\d-.]+)?cowtransfer\.com\/s\/[a-zA-Z\d]+)/,
host: /(?:[a-zA-Z\d-.]+)?cowtransfer\.com/,
input: ['.receive-code-input input'],
button: ['.open-button'],
name: '奶牛快传',
storage: 'hash'
},
'ctfile': {
reg: /((?:https?:\/\/)?(?:[a-zA-Z\d-.]+)?ctfile\.com\/\w+\/[a-zA-Z\d-]+)/,
host: /(?:[a-zA-Z\d-.]+)?ctfile\.com/,
input: ['#passcode'],
button: ['.card-body button'],
name: '城通网盘',
storage: 'hash'
},
'quark': {
reg: /((?:https?:\/\/)?pan\.quark\.cn\/s\/[a-zA-Z\d-]+)/,
host: /pan\.quark\.cn/,
input: ['.ant-input'],
button: ['.ant-btn-primary'],
name: '夸克网盘',
storage: 'local',
storagePwdName: 'tmp_quark_pwd'
},
'flowus': {
reg: /((?:https?:\/\/)?flowus\.cn\/[\S ^\/]*\/?share\/[a-z\d]{8}-[a-z\d]{4}-[a-z\d]{4}-[a-z\d]{4}-[a-z\d]{12})/,
host: /flowus\.cn/,
name: 'FlowUs息流',
storage: 'hash'
},
'chrome': {
reg: /^https?:\/\/chrome.google.com\/webstore\/.+?\/([a-z]{32})(?=[\/#?]|$)/,
host: /chrome\.google\.com/,
replaceHost: "chrome.crxsoso.com",
name: 'Chrome商店',
},
'edge': {
reg: /^https?:\/\/microsoftedge.microsoft.com\/addons\/.+?\/([a-z]{32})(?=[\/#?]|$)/,
host: /microsoftedge\.microsoft\.com/,
replaceHost: "microsoftedge.crxsoso.com",
name: 'Edge商店',
},
'firefox': {
reg: /^https?:\/\/(reviewers\.)?(addons\.mozilla\.org|addons(?:-dev)?\.allizom\.org)\/.*?(?:addon|review)\/([^/<>"'?#]+)/,
host: /addons\.mozilla\.org/,
replaceHost: "addons.crxsoso.com",
name: 'Firefox商店',
},
'microsoft': {
reg: /^https?:\/\/(?:apps|www).microsoft.com\/(?:store|p)\/.+?\/([a-zA-Z\d]{10,})(?=[\/#?]|$)/,
host: /(apps|www)\.microsoft\.com/,
replaceHost: "apps.crxsoso.com",
name: 'Windows商店',
},
};
let main = {
lastText: "lorem&",
//初始化配置数据
initValue() {
let value = [{
name: 'setting_success_times',
value: 0
}, {
name: 'setting_auto_click_btn',
value: true
}, {
name: 'setting_active_in_front',
value: true
}, {
name: 'setting_timer_open',
value: false
}, {
name: 'setting_timer',
value: 5000
}];
value.forEach((v) => {
if (util.getValue(v.name) === undefined) {
util.setValue(v.name, v.value);
}
});
},
// 监听选择事件
addPageListener() {
document.addEventListener("mouseup", this.smartIdentify.bind(this), true);
document.addEventListener("keydown", this.pressKey.bind(this), true);
},
smartIdentify(event, str = '') {
let selection = window.getSelection();
let text = str || selection.toString();
if (text !== this.lastText && text !== '') { //选择相同文字或空不识别
let start = performance.now();
this.lastText = text;
//util.clog(`当前选中文字:${text}`);
let linkObj = this.parseLink(text);
let link = linkObj.link;
let name = linkObj.name;
let pwd = this.parsePwd(text);
if (!link) {
linkObj = this.parseParentLink(selection);
link = linkObj.link;
name = linkObj.name;
}
if (link) {
if (!/https?:\/\//.test(link)) {
link = 'https://' + link;
}
let end = performance.now();
let time = (end - start).toFixed(3);
util.clog(`文本识别结果:${name} 链接:${link} 密码:${pwd} 耗时:${time}毫秒`);
let option = {
toast: true,
showCancelButton: true,
position: 'top',
title: `发现<span style="color: #2778c4;margin: 0 5px;">${name}</span>链接`,
html: `<span style="font-size: 0.8em;">${!!pwd ? '密码:' + pwd : '是否打开?'}</span>`,
confirmButtonText: '打开',
cancelButtonText: '关闭',
customClass
};
if (util.getValue('setting_timer_open')) {
option.timer = util.getValue('setting_timer');
option.timerProgressBar = true;
}
util.setValue('setting_success_times', util.getValue('setting_success_times') + 1);
Swal.fire(option).then((res) => {
this.lastText = 'lorem&';
selection.empty();
if (res.isConfirmed || res.dismiss === 'timer') {
if (name === '移动云盘') { //移动云盘无法携带参数和Hash
util.setValue('tmp_caiyun_pwd', pwd);
}
if (name === '夸克网盘') {
util.setValue('tmp_quark_pwd', pwd);
}
let active = util.getValue('setting_active_in_front');
if (pwd) {
let extra = `${link}?pwd=${pwd}#${pwd}`;
if (~link.indexOf('?')) {
extra = `${link}&pwd=${pwd}#${pwd}`;
}
GM_openInTab(extra, {active});
} else {
GM_openInTab(`${link}`, {active});
}
}
});
}
}
},
pressKey(event) {
if (event.key === 'Enter') {
let confirmBtn = document.querySelector('.panai-container .swal2-confirm');
confirmBtn && confirmBtn.click()
}
if (event.key === 'Escape') {
let cancelBtn = document.querySelector('.panai-container .swal2-cancel');
cancelBtn && cancelBtn.click()
}
},
addHotKey() {
hotkeys('f1', (event, handler) => {
event.preventDefault();
this.showIdentifyBox();
});
},
//正则解析网盘链接
parseLink(text = '') {
let obj = {name: '', link: ''};
if (text) {
text = text.replace(/[点點]/g, '.');
text = text.replace(/[\u4e00-\u9fa5\u200B()(),,]/g, '');
text = text.replace(/lanzous/g, 'lanzouw'); //修正lanzous打不开的问题
for (let name in opt) {
let val = opt[name];
if (val.reg.test(text)) {
let matches = text.match(val.reg);
obj.name = val.name;
obj.link = matches[0];
if (val.replaceHost) {
obj.link = obj.link.replace(val.host, val.replaceHost);
}
return obj;
}
}
}
return obj;
},
//正则解析超链接类型网盘链接
parseParentLink(selection) {
let anchorNode = selection.anchorNode.parentElement.href;
let focusNode = selection.focusNode.parentElement.href;
if (anchorNode) return this.parseLink(anchorNode);
if (focusNode) return this.parseLink(focusNode);
return this.parseLink();
},
//正则解析提取码
parsePwd(text) {
text = text.replace(/\u200B/g, '');
let reg = /(?<=\s*(?:密|提取|访问|訪問|key|password|pwd|#)\s*[码碼]?\s*[::=]?\s*)[a-zA-Z0-9]{3,8}/i;
if (reg.test(text)) {
let match = text.match(reg);
return match[0];
}
return '';
},
//根据域名检测网盘类型
panDetect() {
let hostname = location.hostname;
for (let name in opt) {
let val = opt[name];
if (val.host.test(hostname)) {
return name;
}
}
return '';
},
//自动填写密码
autoFillPassword() {
let url = location.href;
let query = util.parseQuery('pwd');
let hash = location.hash.slice(1);
let pwd = query || hash;
let panType = this.panDetect();
for (let name in opt) {
let val = opt[name];
if (panType === name) {
if (val.storage === 'local') {
pwd = util.getValue(val.storagePwdName) ? util.getValue(val.storagePwdName) : '';
pwd && this.doFillAction(val.input, val.button, pwd);
}
if (val.storage === 'hash') {
if (!/^[a-zA-Z0-9]{3,8}$/.test(pwd)) { //过滤掉不正常的Hash
return;
}
pwd && this.doFillAction(val.input, val.button, pwd);
}
}
}
},
doFillAction(inputSelector, buttonSelector, pwd) {
let maxTime = 10;
let ins = setInterval(async () => {
maxTime--;
let input = util.query(inputSelector);
let button = util.query(buttonSelector);
if (input && !util.isHidden(input)) {
clearInterval(ins);
Swal.fire({
toast: true,
position: 'top',
showCancelButton: false,
showConfirmButton: false,
title: 'AI已识别到密码!正自动帮您填写',
icon: 'success',
timer: 2000,
customClass
});
let lastValue = input.value;
input.value = pwd;
//Vue & React 触发 input 事件
let event = new Event('input', {bubbles: true});
let tracker = input._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
input.dispatchEvent(event);
if (util.getValue('setting_auto_click_btn')) {
await util.sleep(1000); //1秒后点击按钮
button.click();
}
} else {
maxTime === 0 && clearInterval(ins);
}
}, 800);
},
//重置识别次数
clearIdentifyTimes() {
let res = Swal.fire({
showCancelButton: true,
title: '确定要重置识别次数吗?',
icon: 'warning',
confirmButtonText: '确定',
cancelButtonText: '取消',
customClass
}).then(res => {
this.lastText = 'lorem&';
if (res.isConfirmed) {
util.setValue('setting_success_times', 0);
history.go(0);
}
});
},
//识别输入框中的内容
showIdentifyBox() {
Swal.fire({
title: '识别剪切板中文字',
input: 'textarea',
inputPlaceholder: '若选方式一,请按 Ctrl+V 粘贴要识别的文字',
html: `<div style="font-size: 12px;color: #999;margin-bottom: 8px;text-align: center;">提示:在任意网页按下 <span style="font-weight: 700;">F1</span> 键可快速打开本窗口。</div><div style="font-size: 14px;line-height: 22px;padding: 10px 0 5px;text-align: left;"><div style="font-size: 16px;margin-bottom: 8px;font-weight: 700;">支持以下两种方式:</div><div><b>方式一:</b>直接粘贴文字到输入框,点击“识别方框内容”按钮。</div><div><b>方式二:</b>点击“读取剪切板”按钮。<span style="color: #d14529;font-size: 12px;">会弹出“授予网站读取剪切板”权限,同意后会自动识别剪切板中的文字。</span></div></div>`,
showCloseButton: false,
showDenyButton: true,
confirmButtonText: '识别方框内容',
denyButtonText: '读取剪切板',
customClass
}).then(res => {
if (res.isConfirmed) {
this.smartIdentify(null, res.value);
}
if (res.isDenied) {
navigator.clipboard.readText().then(text => {
this.smartIdentify(null, text);
}).catch(() => {
toast.fire({title: '读取剪切板失败,请先授权或手动粘贴后识别!', icon: 'error'});
});
}
});
},
//显示设置
showSettingBox() {
let html = `<div style="font-size: 1em;">
<label class="panai-setting-label">填写密码后自动提交<input type="checkbox" id="S-Auto" ${util.getValue('setting_auto_click_btn') ? 'checked' : ''} class="panai-setting-checkbox"></label>
<label class="panai-setting-label">前台打开网盘标签页<input type="checkbox" id="S-Active" ${util.getValue('setting_active_in_front') ? 'checked' : ''}
class="panai-setting-checkbox"></label>
<label class="panai-setting-label">倒计时结束自动打开<input type="checkbox" id="S-Timer-Open" ${util.getValue('setting_timer_open') ? 'checked' : ''} class="panai-setting-checkbox"></label>
<label class="panai-setting-label" id="Panai-Range-Wrapper" style="${util.getValue('setting_timer_open') ? '' : 'display: none'}"><span>倒计时 <span id="Timer-Value">(${util.getValue('setting_timer') / 1000}秒)</span></span><input type="range" id="S-Timer" min="0" max="10000" step="500" value="${util.getValue('setting_timer')}" style="width: 200px;"></label>
</div>`;
Swal.fire({
title: '识别助手配置',
html,
icon: 'info',
showCloseButton: true,
confirmButtonText: '保存',
footer: '<div style="text-align: center;font-size: 1em;">点击查看 <a href="https://www.youxiaohou.com/tool/install-panai.html" target="_blank">使用说明</a>,助手免费开源,Powered by <a href="https://www.youxiaohou.com">油小猴</a></div>',
customClass
}).then((res) => {
res.isConfirmed && history.go(0);
});
document.getElementById('S-Auto').addEventListener('change', (e) => {
util.setValue('setting_auto_click_btn', e.target.checked);
});
document.getElementById('S-Active').addEventListener('change', (e) => {
util.setValue('setting_active_in_front', e.target.checked);
});
document.getElementById('S-Timer-Open').addEventListener('change', (e) => {
let rangeWrapper = document.getElementById('Panai-Range-Wrapper');
e.target.checked ? rangeWrapper.style.display = 'flex' : rangeWrapper.style.display = 'none';
util.setValue('setting_timer_open', e.target.checked);
});
document.getElementById('S-Timer').addEventListener('change', (e) => {
util.setValue('setting_timer', e.target.value);
document.getElementById('Timer-Value').innerText = `(${e.target.value / 1000}秒)`;
});
},
registerMenuCommand() {
GM_registerMenuCommand('👀 已识别:' + util.getValue('setting_success_times') + '次', () => {
this.clearIdentifyTimes();
});
GM_registerMenuCommand('📋️ 识别剪切板中文字(快捷键 F1)', () => {
this.showIdentifyBox();
});
GM_registerMenuCommand('⚙️ 设置', () => {
this.showSettingBox();
});
},
addPluginStyle() {
let style = `
.panai-container { z-index: 99999!important }
.panai-popup { font-size: 14px !important }
.panai-setting-label { display: flex;align-items: center;justify-content: space-between;padding-top: 20px; }
.panai-setting-checkbox { width: 16px;height: 16px; }
`;
if (document.head) {
util.addStyle('swal-pub-style', 'style', GM_getResourceText('swalStyle'));
util.addStyle('panai-style', 'style', style);
}
const headObserver = new MutationObserver(() => {
util.addStyle('swal-pub-style', 'style', GM_getResourceText('swalStyle'));
util.addStyle('panai-style', 'style', style);
});
headObserver.observe(document.head, {childList: true, subtree: true});
},
isTopWindow() {
return window.self === window.top;
},
init() {
this.initValue();
this.addPluginStyle();
this.addHotKey();
this.autoFillPassword();
this.addPageListener();
this.isTopWindow() && this.registerMenuCommand();
},
};
main.init();
})();