-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpage-search-preload.js
77 lines (68 loc) · 2.5 KB
/
page-search-preload.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
document.addEventListener("DOMContentLoaded",()=>{
const {ipcRenderer} = require('electron')
console.log(1)
ipcRenderer.on('page-search-data', (e, panelKey, tabKey, progress, state) => {
window.panelKey = panelKey
window.tabKey = tabKey
document.querySelector('.search-num').innerHTML = progress
for(let id of ['case','or','reg']){
const ele = document.querySelector(`#${id}`)
const checkbox = ele.parentNode
if(!state[id]){
checkbox.querySelector('input').checked = false
checkbox.classList.remove('checked')
}
else{
checkbox.querySelector('input').checked = true
checkbox.classList.add('checked')
}
}
const text = document.querySelector('#text')
text.value = state.value || ""
if(state.focus){
text.focus()
}
})
const text = document.querySelector('#text')
text.addEventListener('keydown', (e)=>{
if (e.keyCode == 13) {
e.preventDefault()
ipcRenderer.send('page-search-event',window.panelKey, window.tabKey, 'text-keydown', e.target.value, e.shiftKey)
}
else
if (e.keyCode == 27) { // ESC
ipcRenderer.send('page-search-event', window.panelKey, window.tabKey, 'close')
}
})
text.addEventListener('input', (e)=>{
e.preventDefault()
ipcRenderer.send('page-search-event', window.panelKey, window.tabKey,'text-input', e.target.value)
})
const back = document.querySelector('#back')
back.addEventListener('click', (e)=>{
ipcRenderer.send('page-search-event', window.panelKey, window.tabKey, 'back')
})
const forward = document.querySelector('#forward')
forward.addEventListener('click', (e)=>{
ipcRenderer.send('page-search-event', window.panelKey, window.tabKey, 'forward')
})
for(let id of ['case','or','reg','all']){
const ele = document.querySelector(`#${id}`)
ele.addEventListener('click', (e)=>{
const checkbox = e.target.closest('.ui.checkbox')
if(checkbox.classList.contains('checked')){
checkbox.querySelector('input').checked = false
checkbox.classList.remove('checked')
}
else{
checkbox.querySelector('input').checked = true
checkbox.classList.add('checked')
}
ipcRenderer.send('page-search-event', window.panelKey, window.tabKey, 'check', id, checkbox.classList.contains('checked'))
})
}
const close = document.querySelector('#close')
close.addEventListener('click', (e)=>{
ipcRenderer.send('page-search-event', window.panelKey, window.tabKey, 'close')
})
})