-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathproxy.js
63 lines (61 loc) · 1.51 KB
/
proxy.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
/* global browser, ui, tor */
'use strict';
const proxy = {
onchanges: [],
set: (info, callback = function() {}) => {
chrome.proxy.settings.set({
value: {
mode: 'pac_script',
pacScript: {
data: `
function FindProxyForURL() {
return 'SOCKS5 ${tor.info['socks-host']}:${tor.info['socks-port']}';
}
`
}
}
}, () => {
proxy.onchanges.forEach(c => c(true));
callback();
});
},
reset: (callback = function() {}) => {
chrome.proxy.settings.set({
value: {
mode: 'system'
}
}, () => {
proxy.onchanges.forEach(c => c(false));
callback();
});
},
addListener: (method, callback) => {
if (method === 'change') {
proxy.onchanges.push(callback);
}
}
};
if (/Firefox/.test(navigator.userAgent)) {
proxy.set = (info, callback = function() {}) => {
browser.proxy.settings.set({
value: {
proxyType: 'manual',
socks: `http://${tor.info['socks-host']}:${tor.info['socks-port']}`,
socksVersion: 5,
passthrough: '',
proxyDNS: true
}
}, () => {
const lastError = chrome.runtime.lastError;
if (lastError) {
ui.notification(lastError.message);
tor.emit('stdout', 'WebExtension API [err] ' + lastError.message + '\n');
tor.disconnect();
callback();
}
});
};
proxy.reset = (callback = function() {}) => {
browser.proxy.settings.clear({}).then(callback);
};
}