share-to-mastodon/js/settings.js

33 lines
884 B
JavaScript
Raw Permalink Normal View History

2022-12-18 19:47:46 +01:00
// Function for populating settings
async function loadSettings() {
// Retrieve settings from storage
const server = document.getElementById('mastodon-server')
new Promise(function (resolve) {
2022-12-20 19:59:20 +01:00
chrome.storage.local.get(function (data) {
2022-12-18 19:47:46 +01:00
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 () {
2022-12-20 19:59:20 +01:00
chrome.storage.local.set({
2022-12-18 19:47:46 +01:00
userServer: document.querySelector('#mastodon-server').value,
}, function() {
console.log('Settings saved')
})
})
})
loadSettings()