Skip to content

Commit 32adec9

Browse files
committed
feat: Added ProxyPopup class for chrome proxy.
1 parent 4799c70 commit 32adec9

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

app.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,51 @@
1-
console.log('chrome proxy')
1+
class ProxyPopup {
2+
3+
constructor() {
4+
5+
const [ set, clear ] = document.querySelectorAll('button')
6+
7+
this._element = { set, clear }
8+
9+
}
10+
11+
run() {
12+
13+
this.get()
14+
15+
this._element.set.onclick = _ => this.set(this.proxy())
16+
this._element.clear.onclick = _ => this.clear()
17+
18+
}
19+
20+
noti = message => document.querySelector('p').innerText = typeof message === 'object' ? JSON.stringify(message) : message
21+
22+
proxy = () => {
23+
24+
const [ scheme, host, port ] = Array.from(document.querySelectorAll('input')).map(e => e.value)
25+
26+
return { scheme, host, port : parseInt(port) }
27+
28+
}
29+
30+
set = proxy => {
31+
32+
const value = {
33+
mode: 'fixed_servers',
34+
rules: {
35+
proxyForHttp: proxy
36+
}
37+
}
38+
39+
chrome.proxy.settings.set({ value, scope: 'regular' }, this.get)
40+
41+
}
42+
43+
clear = () => chrome.proxy.settings.clear({}, this.get)
44+
45+
get = () => chrome.proxy.settings.get({}, this.noti)
46+
47+
}
48+
49+
const proxyPopup = new ProxyPopup()
50+
51+
proxyPopup.run()

0 commit comments

Comments
 (0)