33 lines
882 B
JavaScript
33 lines
882 B
JavaScript
// Function for populating settings
|
|
async function loadSettings() {
|
|
// Retrieve settings from storage
|
|
const server = document.getElementById('mastodon-server')
|
|
new Promise(function (resolve) {
|
|
chrome.storage.sync.get(function (data) {
|
|
console.log(data)
|
|
// Server setting
|
|
if (data.userServer) {
|
|
server.value = data.userServer
|
|
} else {
|
|
document.querySelector('#mastodon-server-alert').classList.remove('d-none')
|
|
}
|
|
resolve()
|
|
})
|
|
}).then(function () {
|
|
// Allow interaction on settings
|
|
server.removeAttribute('disabled')
|
|
})
|
|
}
|
|
|
|
// Save settings after any input change
|
|
document.querySelectorAll('input,select').forEach(function (el) {
|
|
el.addEventListener('change', function () {
|
|
chrome.storage.sync.set({
|
|
userServer: document.querySelector('#mastodon-server').value,
|
|
}, function() {
|
|
console.log('Settings saved')
|
|
})
|
|
})
|
|
})
|
|
|
|
loadSettings() |