File tree Expand file tree Collapse file tree 1 file changed +51
-1
lines changed Expand file tree Collapse file tree 1 file changed +51
-1
lines changed Original file line number Diff line number Diff line change 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 ( )
You can’t perform that action at this time.
0 commit comments