2017-11-22 04:35:22 -08:00
|
|
|
'use strict';
|
|
|
|
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() {
|
|
|
|
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),
|
|
|
|
mode: document.getElementById('mode-blacklist').checked ? 'blacklist' : 'whitelist'
|
|
|
|
}, () => {
|
|
|
|
restore();
|
|
|
|
// Update status to let user know options were saved.
|
|
|
|
const status = document.getElementById('status');
|
|
|
|
status.textContent = 'Options saved.';
|
|
|
|
setTimeout(() => status.textContent = '', 750);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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: [],
|
|
|
|
blacklist: []
|
|
|
|
}, prefs => {
|
2017-11-22 04:38:04 -08:00
|
|
|
document.getElementById('faqs').checked = prefs.faqs;
|
2017-11-22 04:35:22 -08:00
|
|
|
document.getElementById('mode-blacklist').checked = prefs.mode === 'blacklist';
|
|
|
|
document.getElementById('mode-whitelist').checked = prefs.mode === 'whitelist';
|
|
|
|
document.getElementById('blacklist').value = prefs.blacklist.join(', ');
|
|
|
|
document.getElementById('whitelist').value = prefs.whitelist.join(', ');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', restore);
|
|
|
|
document.getElementById('save').addEventListener('click', save);
|