forked from andy-portmen/tor-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
123 lines (115 loc) · 3.07 KB
/
common.js
File metadata and controls
123 lines (115 loc) · 3.07 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* globals Tor, proxy, privacy, ui */
'use strict';
var prefs = {
webrtc: 2,
policy: {
'proxy': 0, // 0: turn on when tor is active and turn off when tor is disabled; 1: turn on when browser starts and do not turn off when tor is disabled
'webrtc': 0, // 0: turn on when tor is active and turn off when tor is disabled; 1: turn on when browser starts and do not turn off when tor is disabled
},
'auto-run': false,
'directory': null
};
var tor = new Tor({
directory: ''
});
// get external IP address
tor.on('status', status => {
ui.emit('title', {status});
if (status === 'connected') {
tor.getIP();
}
});
// Set proxy
tor.on('status', s => {
if (s === 'connected') {
proxy.set(tor.info);
privacy.set(prefs.webrtc);
}
else if (s === 'disconnected') {
if (prefs.policy.proxy === 0) {
proxy.reset();
}
if (prefs.policy.webrtc === 0) {
privacy.reset();
}
}
});
// ip changes
tor.on('ip', ip => ui.emit('title', {ip}));
//
proxy.addListener('change', bol => ui.emit('title', {
proxy: bol ? 'SOCKS' : 'default'
}));
chrome.storage.local.get(prefs, p => {
prefs = Object.assign(prefs, p);
// directory
tor.directory = p.directory;
// auto run?
if (prefs['auto-run']) {
tor.refresh();
}
if (prefs.policy.proxy === 1) {
privacy.set(prefs.proxy);
}
if (prefs.policy.webrtc === 1) {
privacy.set(prefs.webrtc);
}
});
// logs
proxy.addListener('change', s => {
tor.emit('stdout', `Proxy status is "${s}"`);
});
privacy.addListener('change', (type, state) => {
tor.emit('stdout', `Protection: module -> ${type}, status -> ${state}`);
});
chrome.runtime.onMessage.addListener(request => {
if (request.method === 'popup-command') {
if (request.cmd) {
tor.command(request.cmd);
}
}
else if (request.method === 'popup-action') {
if (request.cmd === 'connection') {
if (request.action === 'disconnect') {
tor.disconnect();
}
else {
if (prefs.directory) {
tor.refresh();
}
else {
ui.notification('Tor Bundle path is not set in the options page');
chrome.runtime.openOptionsPage();
}
}
}
}
});
// pref updates
chrome.storage.onChanged.addListener(ps => {
Object.keys(ps).forEach(p => {
prefs[p] = ps[p].newValue;
if (p === 'directory') {
tor.directory = ps.directory.newValue;
}
});
});
// FAQs & Feedback
chrome.storage.local.get({
'version': null,
'faqs': navigator.userAgent.toLowerCase().indexOf('firefox') === -1
}, prefs => {
const version = chrome.runtime.getManifest().version;
if (prefs.version ? (prefs.faqs && prefs.version !== version) : true) {
chrome.storage.local.set({version}, () => {
chrome.tabs.create({
url: 'http://add0n.com/tor-control.html?version=' + version +
'&type=' + (prefs.version ? ('upgrade&p=' + prefs.version) : 'install')
});
});
}
});
(function() {
const {name, version} = chrome.runtime.getManifest();
chrome.runtime.setUninstallURL('http://add0n.com/feedback.html?name=' + name + '&version=' + version);
})();