-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickproxy.js
More file actions
89 lines (63 loc) · 2.16 KB
/
quickproxy.js
File metadata and controls
89 lines (63 loc) · 2.16 KB
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
/*
Author: Inazo
Website : www.kanjian.fr
GitHub : https://github.com/inaz0/
*/
function activateProxy(){
let quickProxyState = {
isActive: true
}
let proxySettings = {};
//-- necessary put it in the promise because if not the code keep run and has no effect
function onGot(item) {
if( item.quickProxyState && item.quickProxyState.isActive && item.quickProxyState.isActive === true ){
quickProxyState.isActive = false;
proxySettings = {
proxyType: "none"
}
browser.browserAction.setIcon({path: "icons/quickproxy-gray.png"});
browser.browserAction.setTitle({title: "No Proxy. Activate it?"});
}
else{
quickProxyState.isActive = true;
proxySettings = {
proxyType: "manual",
http: "http://127.0.0.1:8080",
socksVersion: 5,
httpProxyAll: true
}
browser.browserAction.setIcon({path: "icons/quickproxy.png"});
browser.browserAction.setTitle({title: "Proxy activate."});
}
browser.storage.local.set({quickProxyState});
browser.proxy.settings.set({value: proxySettings});
}
function onError(error) {
console.log('ko')
quickProxyState.isActive = false;
}
let isSettingItem = browser.storage.local.get('quickProxyState');
isSettingItem.then(onGot, onError);
}
browser.browserAction.onClicked.addListener(activateProxy);
function controlIsActiveProxy(){
//-- necessary put it in the promise because if not the code keep run and has no effect
function onGot(item) {
if( item.quickProxyState && item.quickProxyState.isActive && item.quickProxyState.isActive === true ){
browser.browserAction.setIcon({path: "icons/quickproxy.png"});
browser.browserAction.setTitle({title: "Proxy activate."});
}
else{
browser.browserAction.setIcon({path: "icons/quickproxy-gray.png"});
browser.browserAction.setTitle({title: "No Proxy. Activate it?"});
}
}
function onError(error) {
console.log('ko')
quickProxyState.isActive = false;
}
let isSettingItem = browser.storage.local.get('quickProxyState');
isSettingItem.then(onGot, onError);
}
// adding listner on startup if we quit the browser without turn off
browser.runtime.onStartup.addListener(controlIsActiveProxy);