const stammTVBaseUrl = document.getElementById('stammtv-base-url'); const stammTVWSSUrl = document.getElementById('stammtv-wss-url'); const saveButton = document.getElementById('save'); // Saves options to chrome.storage function save_options() { 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!'; } } // Restores select box and checkbox state using the preferences // stored in chrome.storage. function load_options() { chrome.storage.local.get({ baseURL: 'Please fill in.', wssURL: 'Please fill in.' }, function (items) { stammTVBaseUrl.value = items.baseURL; stammTVWSSUrl.value = items.wssURL; }); } document.addEventListener('DOMContentLoaded', load_options); saveButton.addEventListener('click', save_options);