This commit is contained in:
parent
a985977fdd
commit
f6ef6f977c
3 changed files with 93 additions and 22 deletions
|
@ -5,6 +5,10 @@
|
|||
<style>
|
||||
body { padding: 10px; }
|
||||
textarea { width: 100%; }
|
||||
#custom {
|
||||
white-space: nowrap;
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -24,13 +28,22 @@
|
|||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><textarea id="whitelist" rows="3"></textarea></td>
|
||||
<td><textarea id="whitelist" rows="3" placeholder="e.g.: www.google.com, www.bing.com"></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label><input type="radio" name="mode" value="custom" id="mode-custom"> Custom mode: Only apply user-agent string to the tabs with a matching top-level hostnames.</label> <a href="#" id="sample">Insert</a> a sample.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><textarea id="custom" rows="5"></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><input type="checkbox" id="faqs"> Open FAQs page on updates</label></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<button id="donate">Support Development</button>
|
||||
<button id="save">Save</button>
|
||||
<span id="status"></span>
|
||||
</p>
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function prepare(str) {
|
||||
return str.split(/\s*,\s*/)
|
||||
.map(s => s.replace('http://', '')
|
||||
|
@ -7,17 +16,23 @@ function prepare(str) {
|
|||
}
|
||||
|
||||
function save() {
|
||||
let custom = {};
|
||||
try {
|
||||
custom = JSON.parse(document.getElementById('custom').value);
|
||||
}
|
||||
catch (e) {
|
||||
notify(e.message);
|
||||
}
|
||||
|
||||
chrome.storage.local.set({
|
||||
faqs: document.getElementById('faqs').checked,
|
||||
blacklist: prepare(document.getElementById('blacklist').value),
|
||||
whitelist: prepare(document.getElementById('whitelist').value),
|
||||
mode: document.getElementById('mode-blacklist').checked ? 'blacklist' : 'whitelist'
|
||||
custom,
|
||||
mode: document.querySelector('[name="mode"]:checked').value
|
||||
}, () => {
|
||||
restore();
|
||||
// Update status to let user know options were saved.
|
||||
const status = document.getElementById('status');
|
||||
status.textContent = 'Options saved.';
|
||||
setTimeout(() => status.textContent = '', 750);
|
||||
notify('Options saved.');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -26,14 +41,28 @@ function restore() {
|
|||
faqs: true,
|
||||
mode: 'blacklist',
|
||||
whitelist: [],
|
||||
blacklist: []
|
||||
blacklist: [],
|
||||
custom: {}
|
||||
}, prefs => {
|
||||
document.getElementById('faqs').checked = prefs.faqs;
|
||||
document.getElementById('mode-blacklist').checked = prefs.mode === 'blacklist';
|
||||
document.getElementById('mode-whitelist').checked = prefs.mode === 'whitelist';
|
||||
document.querySelector(`[name="mode"][value="${prefs.mode}"`).checked = true;
|
||||
document.getElementById('blacklist').value = prefs.blacklist.join(', ');
|
||||
document.getElementById('whitelist').value = prefs.whitelist.join(', ');
|
||||
document.getElementById('custom').value = JSON.stringify(prefs.custom, null, 2);
|
||||
});
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', restore);
|
||||
document.getElementById('save').addEventListener('click', save);
|
||||
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue