You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.9 KiB
JavaScript

2 years ago
// Saves options to chrome.storage
function save_options() {
let stammTVBaseUrl = document.getElementById('stammtv-base-url');
let stammTVWSSUrl = document.getElementById('stammtv-wss-url');
let saveButton = document.getElementById('save');
let valid = true;
if (stammTVBaseUrl.value.startsWith('http')) {
stammTVBaseUrl.classList.add('is-valid');
valid = valid && true;
} else {
stammTVBaseUrl.classList.add('is-invalid');
valid = false;
}
if (stammTVWSSUrl.value.startsWith('wss://')) {
stammTVWSSUrl.classList.add('is-valid');
valid = valid && true;
} else {
stammTVWSSUrl.classList.add('is-invalid');
valid = false;
}
if(valid) {
chrome.storage.local.set({
baseURL: stammTVBaseUrl.value,
wssURL: stammTVWSSUrl.value
}, function () {
// Update form controls to let user know options were saved.
saveButton.classList.replace('btn-primary', 'btn-success');
saveButton.classList.replace('btn-danger', 'btn-success');
saveButton.textContent = '... saved!';
});
} else {
saveButton.classList.replace('btn-primary', 'btn-danger');
saveButton.classList.replace('btn-success', 'btn-danger');
saveButton.textContent = '... failed to save!';
}
2 years ago
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
chrome.storage.local.get({
baseURL: 'Please fill in.',
wssURL: 'Please fill in.'
}, function (items) {
document.getElementById('stammtv-base-url').value = items.baseURL;
document.getElementById('stammtv-wss-url').value = items.wssURL;
});
}
document.addEventListener('DOMContentLoaded', restore_options);
document.getElementById('save').addEventListener('click', save_options);