2017-11-22 04:35:22 -08:00
|
|
|
'use strict';
|
2017-12-13 04:45:54 -08:00
|
|
|
|
|
|
|
function notify(msg) {
|
|
|
|
// Update status to let user know options were saved.
|
|
|
|
const status = document.getElementById('status');
|
|
|
|
status.textContent = msg;
|
|
|
|
clearTimeout(notify.id);
|
|
|
|
notify.id = setTimeout(() => status.textContent = '', 750);
|
|
|
|
}
|
|
|
|
|
2017-11-22 04:35:22 -08:00
|
|
|
function prepare(str) {
|
|
|
|
return str.split(/\s*,\s*/)
|
|
|
|
.map(s => s.replace('http://', '')
|
|
|
|
.replace('https://', '').split('/')[0].trim())
|
|
|
|
.filter((h, i, l) => h && l.indexOf(h) === i);
|
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
2017-12-13 04:45:54 -08:00
|
|
|
let custom = {};
|
|
|
|
try {
|
|
|
|
custom = JSON.parse(document.getElementById('custom').value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
notify(e.message);
|
|
|
|
}
|
|
|
|
|
2017-11-22 04:35:22 -08:00
|
|
|
chrome.storage.local.set({
|
2017-11-22 04:38:04 -08:00
|
|
|
faqs: document.getElementById('faqs').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,
|
|
|
|
mode: document.querySelector('[name="mode"]:checked').value
|
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({
|
2017-11-22 04:38:04 -08:00
|
|
|
faqs: true,
|
2017-11-22 04:35:22 -08:00
|
|
|
mode: 'blacklist',
|
|
|
|
whitelist: [],
|
2017-12-13 04:45:54 -08:00
|
|
|
blacklist: [],
|
|
|
|
custom: {}
|
2017-11-22 04:35:22 -08:00
|
|
|
}, prefs => {
|
2017-11-22 04:38:04 -08:00
|
|
|
document.getElementById('faqs').checked = prefs.faqs;
|
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);
|
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
|
|
|
|
|
|
|
document.getElementById('sample').addEventListener('click', () => {
|
|
|
|
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',
|
|
|
|
'www.bing.com': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0'
|
|
|
|
}, null, 2);
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('donate').addEventListener('click', () => {
|
|
|
|
chrome.tabs.create({
|
|
|
|
url: 'https://www.paypal.me/addondonation/10usd'
|
|
|
|
});
|
|
|
|
});
|