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
132 lines (125 loc) · 3.42 KB
/
common.js
File metadata and controls
132 lines (125 loc) · 3.42 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
124
125
126
127
128
129
130
131
132
/* globals Tor, proxy, privacy, ui */
'use strict';
const 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
};
const tor = new Tor({
directory: ''
});
window.tor = tor;
// 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 => {
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 */
{
const {onInstalled, setUninstallURL, getManifest} = chrome.runtime;
const {name, version} = getManifest();
const page = getManifest().homepage_url;
if (navigator.webdriver !== true) {
onInstalled.addListener(({reason, previousVersion}) => {
chrome.storage.local.get({
'faqs': true,
'last-update': 0
}, prefs => {
if (reason === 'install' || (prefs.faqs && reason === 'update')) {
const doUpdate = (Date.now() - prefs['last-update']) / 1000 / 60 / 60 / 24 > 45;
if (doUpdate && previousVersion !== version) {
chrome.tabs.create({
url: page + '?version=' + version +
(previousVersion ? '&p=' + previousVersion : '') +
'&type=' + reason,
active: reason === 'install'
});
chrome.storage.local.set({'last-update': Date.now()});
}
}
});
});
setUninstallURL(page + '?rd=feedback&name=' + encodeURIComponent(name) + '&version=' + version);
}
}