Update custom sites (edit options)

This commit is contained in:
magnolia1234 2020-08-18 20:19:15 +02:00
parent cc349e8fa1
commit 6c6bbcfc37
2 changed files with 24 additions and 2 deletions

View file

@ -16,7 +16,7 @@
<body>
<h2>Custom Sites</h2>
<div style="width:90%;">
To add new site, enter a unique title/domain (without www.) and select options for Googlebot/block Javascript (block on (sub)domain(s) of site and/or external domains).<br>
To add a new site, enter an unique title/domain (without www.) and select options for Googlebot/block Javascript (block on (sub)domain(s) of site and/or external domains).<br>
Custom sites are enabled automatically in <a href="options.html" style="color:black">options</a> (cookies will be removed by default).
<br/><br/>
</div>
@ -36,6 +36,7 @@
<div id="status_delete"></div>
<span style='float:left;padding-bottom:20px'>
<button id="delete">Delete</button>
<button id="edit">Edit (re-Add)</button>
</span>
<div style="clear:both;"></div>
<div style="width:90%;">

View file

@ -160,6 +160,26 @@ function delete_options() {
});
}
// Edit custom site (copy to add)
function edit_options() {
var selectEl = document.querySelector('#custom_sites select');
var sites_custom = {};
var title = selectEl.value;
// copy site to add-fields
ext_api.storage.sync.get({
sites_custom: {}
}, function (items) {
sites_custom = items.sites_custom;
var edit_site = sites_custom[title];
document.querySelector('input[data-key="title"]').value = title;
document.querySelector('input[data-key="domain"]').value = edit_site.domain;
document.querySelector('input[data-key="googlebot"]').checked = (edit_site.googlebot > 0);
document.querySelector('input[data-key="block_javascript"]').checked = (edit_site.block_javascript > 0);
document.querySelector('input[data-key="block_javascript_ext"]').checked = (edit_site.block_javascript_ext > 0);
});
}
// Restores checkbox input states using the preferences stored in ext_api.storage.
function renderOptions() {
ext_api.storage.sync.get({
@ -233,4 +253,5 @@ document.getElementById('export').addEventListener('click', export_options);
document.getElementById('import').onclick = function () {importInput.click()}
document.getElementById('importInput').addEventListener("change", import_options, false);
document.getElementById('add').addEventListener('click', add_options);
document.getElementById('delete').addEventListener('click', delete_options);
document.getElementById('delete').addEventListener('click', delete_options);
document.getElementById('edit').addEventListener('click', edit_options);