2017-11-22 04:35:22 -08:00
|
|
|
'use strict';
|
2017-12-13 04:45:54 -08:00
|
|
|
|
2018-08-15 04:47:16 -07:00
|
|
|
function notify(msg, period = 750) {
|
2017-12-13 04:45:54 -08:00
|
|
|
// Update status to let user know options were saved.
|
|
|
|
const status = document.getElementById('status');
|
|
|
|
status.textContent = msg;
|
|
|
|
clearTimeout(notify.id);
|
2018-08-15 04:47:16 -07:00
|
|
|
notify.id = setTimeout(() => status.textContent = '', period);
|
2017-12-13 04:45:54 -08:00
|
|
|
}
|
|
|
|
|
2017-11-22 04:35:22 -08:00
|
|
|
function prepare(str) {
|
|
|
|
return str.split(/\s*,\s*/)
|
2019-06-25 00:43:08 -07:00
|
|
|
.map(s => s.replace('http://', '')
|
2017-11-22 04:35:22 -08:00
|
|
|
.replace('https://', '').split('/')[0].trim())
|
2019-06-25 00:43:08 -07:00
|
|
|
.filter((h, i, l) => h && l.indexOf(h) === i);
|
2017-11-22 04:35:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2017-12-13 04:45:54 -08:00
|
|
|
let custom = {};
|
2018-08-15 04:47:16 -07:00
|
|
|
const c = document.getElementById('custom').value;
|
2017-12-13 04:45:54 -08:00
|
|
|
try {
|
2018-08-15 04:47:16 -07:00
|
|
|
custom = JSON.parse(c);
|
2017-12-13 04:45:54 -08:00
|
|
|
}
|
|
|
|
catch (e) {
|
2018-08-15 04:47:16 -07:00
|
|
|
window.setTimeout(() => {
|
|
|
|
notify('Custom JSON error: ' + e.message, 5000);
|
|
|
|
document.getElementById('custom').value = c;
|
|
|
|
}, 1000);
|
2017-12-13 04:45:54 -08:00
|
|
|
}
|
|
|
|
|
2017-11-22 04:35:22 -08:00
|
|
|
chrome.storage.local.set({
|
2018-11-04 01:37:09 -08:00
|
|
|
exactMatch: document.getElementById('exactMatch').checked,
|
2017-11-22 04:38:04 -08:00
|
|
|
faqs: document.getElementById('faqs').checked,
|
2018-08-20 04:41:47 -07:00
|
|
|
cache: document.getElementById('cache').checked,
|
2017-11-22 04:35:22 -08:00
|
|
|
blacklist: prepare(document.getElementById('blacklist').value),
|
|
|
|
whitelist: prepare(document.getElementById('whitelist').value),
|
2017-12-13 04:45:54 -08:00
|
|
|
custom,
|
2019-06-25 00:43:08 -07:00
|
|
|
mode: document.querySelector('[name="mode"]:checked').value,
|
|
|
|
protected: document.getElementById('protected').value.split(/\s*,\s*/).filter(s => s.length > 4)
|
2017-11-22 04:35:22 -08:00
|
|
|
}, () => {
|
|
|
|
restore();
|
2017-12-13 04:45:54 -08:00
|
|
|
notify('Options saved.');
|
2017-11-22 04:35:22 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function restore() {
|
|
|
|
chrome.storage.local.get({
|
2018-11-04 01:37:09 -08:00
|
|
|
exactMatch: false,
|
2017-11-22 04:38:04 -08:00
|
|
|
faqs: true,
|
2018-08-20 04:41:47 -07:00
|
|
|
cache: true,
|
2017-11-22 04:35:22 -08:00
|
|
|
mode: 'blacklist',
|
|
|
|
whitelist: [],
|
2017-12-13 04:45:54 -08:00
|
|
|
blacklist: [],
|
2019-06-25 00:43:08 -07:00
|
|
|
custom: {},
|
|
|
|
protected: ['google.com/recaptcha', 'gstatic.com/recaptcha']
|
2017-11-22 04:35:22 -08:00
|
|
|
}, prefs => {
|
2018-11-04 01:37:09 -08:00
|
|
|
document.getElementById('exactMatch').checked = prefs.exactMatch;
|
2017-11-22 04:38:04 -08:00
|
|
|
document.getElementById('faqs').checked = prefs.faqs;
|
2018-08-20 04:41:47 -07:00
|
|
|
document.getElementById('cache').checked = prefs.cache;
|
2017-12-13 04:45:54 -08:00
|
|
|
document.querySelector(`[name="mode"][value="${prefs.mode}"`).checked = true;
|
2017-11-22 04:35:22 -08:00
|
|
|
document.getElementById('blacklist').value = prefs.blacklist.join(', ');
|
|
|
|
document.getElementById('whitelist').value = prefs.whitelist.join(', ');
|
2017-12-13 04:45:54 -08:00
|
|
|
document.getElementById('custom').value = JSON.stringify(prefs.custom, null, 2);
|
2019-06-25 00:43:08 -07:00
|
|
|
document.getElementById('protected').value = prefs.protected.join(', ');
|
2017-11-22 04:35:22 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', restore);
|
|
|
|
document.getElementById('save').addEventListener('click', save);
|
2017-12-13 04:45:54 -08:00
|
|
|
|
2018-04-10 00:50:58 -07:00
|
|
|
document.getElementById('sample').addEventListener('click', e => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2017-12-13 04:45:54 -08:00
|
|
|
document.getElementById('custom').value = JSON.stringify({
|
|
|
|
'www.google.com': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
|
2018-05-15 00:54:51 -07:00
|
|
|
'www.bing.com': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0',
|
|
|
|
'www.example.com': ['random-useragent-1', 'random-user-agent-2'],
|
|
|
|
'*': 'useragent-for-all-hostnames'
|
2017-12-13 04:45:54 -08:00
|
|
|
}, null, 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('donate').addEventListener('click', () => {
|
|
|
|
chrome.tabs.create({
|
2018-04-10 00:50:58 -07:00
|
|
|
url: chrome.runtime.getManifest().homepage_url + '?rd=donate'
|
2017-12-13 04:45:54 -08:00
|
|
|
});
|
|
|
|
});
|
2018-04-10 00:50:58 -07:00
|
|
|
|
|
|
|
document.getElementById('reset').addEventListener('click', e => {
|
|
|
|
if (e.detail === 1) {
|
|
|
|
notify('Double-click to reset!');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
localStorage.clear();
|
|
|
|
chrome.storage.local.clear(() => {
|
|
|
|
chrome.runtime.reload();
|
|
|
|
window.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2019-05-11 01:57:29 -07:00
|
|
|
|
|
|
|
document.getElementById('help').addEventListener('click', () => {
|
|
|
|
chrome.tabs.create({
|
|
|
|
url: chrome.runtime.getManifest().homepage_url
|
|
|
|
});
|
|
|
|
});
|