2023-02-10 07:30:26 +01:00
|
|
|
const serverList = document.querySelector('#mastodon-server-list')
|
|
|
|
|
|
|
|
// Function to load settings from storage
|
|
|
|
function loadSettings() {
|
|
|
|
chrome.storage.sync.get(function (data) {
|
|
|
|
for (const i of data.serverList) {
|
|
|
|
var el = document.createElement('option')
|
|
|
|
el.value = i
|
|
|
|
el.innerText = i
|
|
|
|
serverList.appendChild(el)
|
|
|
|
}
|
2022-12-18 19:47:46 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-10 07:30:26 +01:00
|
|
|
// Function to save settings to storage
|
|
|
|
function saveSettings() {
|
|
|
|
// Get list of servers
|
|
|
|
var array = []
|
|
|
|
document.querySelectorAll('#mastodon-server-list option').forEach(function (el) {
|
|
|
|
array.push(el.value)
|
|
|
|
})
|
|
|
|
console.log(array)
|
|
|
|
// Save to storage
|
|
|
|
chrome.storage.sync.set({
|
|
|
|
serverList: array
|
|
|
|
}, function () {
|
|
|
|
console.log('Settings saved')
|
2022-12-18 19:47:46 +01:00
|
|
|
})
|
2023-02-10 07:30:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add server to list
|
|
|
|
document.querySelector('#server-add-btn').addEventListener('click', function () {
|
|
|
|
var domain = document.querySelector('#mastodon-server-text').value.replace(' ', '')
|
|
|
|
if (domain) {
|
|
|
|
var el = document.createElement('option')
|
|
|
|
el.value = domain
|
|
|
|
el.innerText = domain
|
|
|
|
serverList.appendChild(el)
|
|
|
|
serverList.value = domain
|
|
|
|
saveSettings()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Remove button
|
|
|
|
document.querySelector('#server-remove-btn').addEventListener('click', function () {
|
|
|
|
var selectedOption = serverList.querySelector('option[value="' + serverList.value + '"]')
|
|
|
|
serverList.removeChild(selectedOption)
|
|
|
|
saveSettings()
|
2022-12-18 19:47:46 +01:00
|
|
|
})
|
|
|
|
|
2022-12-18 23:22:16 +01:00
|
|
|
// Open keyboard shortcut
|
2023-02-10 07:30:26 +01:00
|
|
|
document.querySelector('#mastodon-keyboard-shortcut').addEventListener('click', function () {
|
2022-12-18 23:22:16 +01:00
|
|
|
chrome.tabs.create({ url: 'chrome://extensions/shortcuts#:~:text=Share%20to%20Mastodon' })
|
|
|
|
})
|
|
|
|
|
2022-12-18 19:47:46 +01:00
|
|
|
loadSettings()
|