-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
51 lines (29 loc) · 1.03 KB
/
app.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
class ProxyPopup {
constructor() {
const [ set, clear ] = document.querySelectorAll('button')
this._element = { set, clear }
}
run() {
this.get()
this._element.set.onclick = _ => this.set(this.proxy())
this._element.clear.onclick = _ => this.clear()
}
noti = message => document.querySelector('p').innerText = typeof message === 'object' ? JSON.stringify(message) : message
proxy = () => {
const [ scheme, host, port ] = Array.from(document.querySelectorAll('input')).map(e => e.value)
return { scheme, host, port : parseInt(port) }
}
set = proxy => {
const value = {
mode: 'fixed_servers',
rules: {
proxyForHttp: proxy
}
}
chrome.proxy.settings.set({ value, scope: 'regular' }, this.get)
}
clear = () => chrome.proxy.settings.clear({}, this.get)
get = () => chrome.proxy.settings.get({}, this.noti)
}
const proxyPopup = new ProxyPopup()
proxyPopup.run()