pomf-rehost/options.js

82 lines
2.4 KiB
JavaScript

document.getElementById('status').textContent = 'Loading...';
custom = false;
function setUrlBox() {
var pomfclone = document.getElementById('pomfclone').value;
var urlbox = document.getElementById('urlbox');
if(custom) {
customUrl = urlbox.value;
}
if(pomfclone != "custom") {
urlbox.value = pomfclone;
urlbox.disabled = true;
custom = false;
} else {
urlbox.value = customUrl;
urlbox.disabled = false;
custom = true;
}
}
function saveOptions() {
var pomfclone = document.getElementById('pomfclone').value;
var url = document.getElementById('urlbox').value;
var tabbehaviour = document.querySelector('input[name="tabbehaviour"]:checked').value;
var copytoclipboard = document.getElementById('copytoclipboard').checked;
var replacebookmark = document.getElementById('replacebookmark').checked;
var disableblacklist = document.getElementById('disableblacklist').checked;
chrome.storage.sync.set({
pomfclone: pomfclone,
url: url,
customUrl: customUrl,
tabbehaviour: tabbehaviour,
copytoclipboard: copytoclipboard,
replacebookmark: replacebookmark,
disableblacklist: disableblacklist
}, function() {
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
function restoreOptions() {
var firstPomfclone = document.getElementById('pomfclone').getElementsByTagName('option')[0];
chrome.storage.sync.get({
pomfclone: firstPomfclone.innerHTML,
url: firstPomfclone.value,
customUrl: '',
tabbehaviour: document.querySelector('input[name="tabbehaviour"]:checked').value,
copytoclipboard: false,
replacebookmark: false,
disableblacklist: false
}, function(config) {
document.getElementById('pomfclone').value = config.pomfclone;
document.getElementById('urlbox').value = config.url;
customUrl = config.customUrl;
custom = config.pomfclone == "custom";
setUrlBox();
document.getElementById(config.tabbehaviour).checked = true;
document.getElementById('copytoclipboard').checked = config.copytoclipboard;
document.getElementById('replacebookmark').checked = config.replacebookmark;
document.getElementById('disableblacklist').checked = config.disableblacklist;
});
document.getElementById('status').textContent = '';
}
document.addEventListener('DOMContentLoaded', restoreOptions);
document.getElementById('save').addEventListener('click', saveOptions);
document.getElementById('pomfclone').onchange = setUrlBox;