-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (106 loc) · 3.81 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="stylesheet" type="text/css" href="/css/base.css">
<style type="text/css">
body {overflow:hidden;position:absolute;width:1000px;height:662px;}
.webview {display:block;width:1000px;height:602px;}
</style>
</head>
<body>
<webview class="webview" src="https://im.dingtalk.com" partition="persist:googlepluswidgets"></webview>
<script type="text/javascript">
let win = nw.Window.get();
let $wv = document.querySelector('.webview');
let tray = new nw.Tray({ title: '钉钉', icon: 'icon.png' });
let menu = new nw.Menu();
let show = new nw.MenuItem({label: '显示钉钉'})
let quit = new nw.MenuItem({label: '退出钉钉'})
show.click = function(){
win.show()
}
quit.click = function(){
win.close(true)
}
menu.append(show)
menu.append(quit)
tray.menu = menu
tray.on('click', function(){
win.show()
})
$wv.addEventListener('permissionrequest', function(ev) {
ev.request.allow();
});
function dialog(o, ev){
let res = o[ev.messageType](ev.messageText)
if(ev.messageType === 'confirm' || ev.messageType === 'prompt'){
if(res){
ev.dialog.ok(res);
}else{
ev.dialog.cancel();
}
}
}
$wv.addEventListener('dialog', function(ev) {
dialog(window, ev)
});
$wv.addEventListener('newwindow', function(ev){
ev.preventDefault();
if(ev.targetUrl !== 'about:blank'){
nw.Window.open(ev.targetUrl, {width: 1200, height: 700, resizable: true})
}else{
let elem = document.createElement('webview');
elem.className = 'webview';
elem.addEventListener('permissionrequest', function(ev) {
ev.request.allow();
});
elem.setAttribute('partition', 'persist:googlepluswidgets')
ev.window.attach(elem)
nw.Window.open('blank.html', {width: 1200, height: 700, resizable: true, title: '钉钉邮箱'}, function(w){
elem.addEventListener('dialog', function(ev) {
dialog(w.window, ev)
});
w.window.addEventListener('load', function(){
w.window.document.body.appendChild(elem)
})
})
}
})
$wv.addEventListener('contentload', function(ev){
$wv.executeScript({ code: `
nw.gui = nw.gui || nw;
let pwd = localStorage.getItem("pwd") || ''
localStorage.setItem("isBeepOpen", "true");
localStorage.setItem("notification", "true");
localStorage.setItem("newUserState", "secTip");
document.querySelectorAll('.tab-items li')[1].click()
let $form = document.querySelector('form[name=passwordForm]'), $pwd;
for(let i = 0,el;el = $form.elements[i++];){
if(el.type === 'password'){
$pwd = el;
el.value = pwd;
if(el.value){
let ev = document.createEvent('Event')
ev.initEvent('change', false, false)
el.dispatchEvent(ev);
}
}else if(el.type === 'submit'){
el.onclick = function(){
localStorage.setItem('pwd', $pwd.value)
}
// el.click()
}
}
`});
})
win.on('close', function(ev){
this.hide()
})
win.on('maximize', function(ev){
this.restore()
})
</script>
</body>
</html>