Skip to content

Commit

Permalink
fixes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Neomy committed May 27, 2018
1 parent 63e7355 commit 9be5290
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 44 deletions.
20 changes: 15 additions & 5 deletions webextension/common.js
Expand Up @@ -11,7 +11,8 @@ var prefs = {
version: null,
faqs: true,
'last-update': 0,
ffcurent: null
ffcurent: null,
'startup-proxy': 'no'
};

/* icon color */
Expand Down Expand Up @@ -149,13 +150,22 @@ chrome.storage.local.get(null, ps => {
color: prefs.color
});
// initial proxy
if (isFirefox && prefs.ffcurent) {
chrome.proxy.settings.set(prefs.ffcurent, () => {
if (prefs['startup-proxy'] === 'no') {
if (isFirefox && prefs.ffcurent) {
chrome.proxy.settings.set(prefs.ffcurent, () => {
chrome.proxy.settings.get({}, icon);
});
}
else {
chrome.proxy.settings.get({}, icon);
});
}
}
else {
chrome.proxy.settings.get({}, icon);
chrome.proxy.settings.set({
value: {
mode: prefs['startup-proxy']
}
}, icon);
}
// FAQs
const version = chrome.runtime.getManifest().version;
Expand Down
20 changes: 19 additions & 1 deletion webextension/data/options/index.html
Expand Up @@ -92,6 +92,15 @@
<option value="https://api.getproxylist.com/proxy">getproxylist.com</option>
</select></td>
</tr>
<tr>
<td>While Validating Switch to:</td>
<td><select id="validate-mode">
<option value="direct">Direct</option>
<option value="auto_detect">Auto Detect</option>
<option value="system">System Proxy</option>
<option value="fixed_servers">Manual Proxy</option>
</select></td>
</tr>
<tr>
<td>Anonymity</td>
<td><select id="anonymity">
Expand Down Expand Up @@ -156,6 +165,15 @@
</tr>
</thead>
<tbody>
<tr>
<td>Startup Proxy:</td>
<td><select id="startup-proxy">
<option value="no">Do not alter</option>
<option value="direct">Direct</option>
<option value="auto_detect">Auto Detect</option>
<option value="system">System Proxy</option>
</select></td>
</tr>
<tr>
<td>Open FAQs page on updates</td>
<td><input type="checkbox" id="faqs"></td>
Expand All @@ -166,7 +184,7 @@
<p style="display: flex; align-items: flex-end;">

</p>
<p style="display: flex;">
<p style="display: flex; align-items: center;">
<button id="import">Import<sup>2</sup></button>
<button id="export">Export</button>
<span style="flex: 1;"></span>
Expand Down
12 changes: 8 additions & 4 deletions webextension/data/options/index.js
@@ -1,17 +1,19 @@
'use strict';

var config = {
faqs: true,
text: false,
counter: true,
color: '#666666',
server: 'https://gimmeproxy.com/api/getProxy',
'validate-mode': 'direct',
anonymity: '',
allowsRefererHeader: '',
allowsUserAgentHeader: '',
allowsCustomHeaders: '',
allowsCookies: '',
country: ''
country: '',
faqs: true,
'startup-proxy': 'no'
};

function save() {
Expand All @@ -22,17 +24,19 @@ function save() {
localStorage.setItem('pac-proxy', document.getElementById('pac-proxy').value);

chrome.storage.local.set({
faqs: document.getElementById('faqs').checked,
text: document.getElementById('text').checked,
counter: document.getElementById('counter').checked,
color: document.getElementById('color').value,
server: document.getElementById('server').value,
'validate-mode': document.getElementById('validate-mode').value,
anonymity: document.getElementById('anonymity').value,
allowsRefererHeader: document.getElementById('allowsRefererHeader').value,
allowsUserAgentHeader: document.getElementById('allowsUserAgentHeader').value,
allowsCustomHeaders: document.getElementById('allowsCustomHeaders').value,
allowsCookies: document.getElementById('allowsCookies').value,
country: document.getElementById('country').value
country: document.getElementById('country').value,
faqs: document.getElementById('faqs').checked,
'startup-proxy': document.getElementById('startup-proxy').value,
}, () => {
const status = document.getElementById('status');
status.textContent = 'Options saved.';
Expand Down
72 changes: 38 additions & 34 deletions webextension/data/panel/search.js
Expand Up @@ -63,43 +63,47 @@ search.verify = proxy => new Promise((resolve, reject) => chrome.proxy.settings.
button.addEventListener('click', () => {
button.disabled = true;
// store proxy setting
const set = mode => {
if (mode === 'fixed_servers') {
return Promise.resolve();
}
return new Promise(resolve => chrome.proxy.settings.set({ //clear proxy
value: {mode}
}, resolve));
};
chrome.proxy.settings.get({}, ({value}) => {
chrome.proxy.settings.set({ //clear proxy
value: {
mode: 'direct'
}
}, () => {
chrome.storage.local.get({
server: 'https://gimmeproxy.com/api/getProxy',
anonymity: '',
allowsRefererHeader: '',
allowsUserAgentHeader: '',
allowsCustomHeaders: '',
allowsCookies: '',
country: ''
}, async(prefs) => {
Object.entries(prefs).forEach(([key, value]) => {
if (!value) {
delete prefs[key];
}
});
try {
log('Searching for a server ...');
const json = await search.fetch(prefs.server, prefs);
const {proxy, info} = search.convert(json);
log(`Validating ${info.ip}:${info.port}`);
await search.verify(proxy);
log('Proxy works!');
app.emit('update-manual-tab', proxy);
ui.manual.profile.value = 'new proxy from ' + info.country;
ui.manual.profile.dispatchEvent(new Event('input', {bubbles: true}));
}
catch (e) {
log(e.message || e || 'Error!');
chrome.proxy.settings.set({value});
chrome.storage.local.get({
server: 'https://gimmeproxy.com/api/getProxy',
'validate-mode': 'direct',
anonymity: '',
allowsRefererHeader: '',
allowsUserAgentHeader: '',
allowsCustomHeaders: '',
allowsCookies: '',
country: ''
}, async(prefs) => {
await set(prefs['validate-mode']);
Object.entries(prefs).forEach(([key, value]) => {
if (!value) {
delete prefs[key];
}
button.disabled = false;
});
try {
log('Searching for a server ...');
const json = await search.fetch(prefs.server, prefs);
const {proxy, info} = search.convert(json);
log(`Validating ${info.ip}:${info.port}`);
await search.verify(proxy);
log('Looks good! Press the save button to create a new profile');
app.emit('update-manual-tab', proxy);
ui.manual.profile.value = 'new proxy from ' + info.country;
ui.manual.profile.dispatchEvent(new Event('input', {bubbles: true}));
}
catch (e) {
log(e.message || e || 'Error!');
chrome.proxy.settings.set({value});
}
button.disabled = false;
});
});
});
Expand Down

0 comments on commit 9be5290

Please sign in to comment.