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) {
|
|
|
|
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')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-12-18 23:22:16 +01:00
|
|
|
// Open keyboard shortcut
|
|
|
|
document.querySelector('#mastodon-keyboard-shortcut').addEventListener('click', function() {
|
|
|
|
chrome.tabs.create({ url: 'chrome://extensions/shortcuts#:~:text=Share%20to%20Mastodon' })
|
|
|
|
})
|
|
|
|
|
2022-12-18 19:47:46 +01:00
|
|
|
loadSettings()
|