Don't show server list if only one server is saved

This commit is contained in:
Corbin Davenport 2023-02-12 17:10:40 -05:00
parent 15b00bde2a
commit e806404e43
3 changed files with 16 additions and 7 deletions

View File

@ -14,16 +14,29 @@ var shareLink = ''
*/ */
async function init() { async function init() {
// Generate links to options page
document.querySelectorAll('.extension-settings-link').forEach(function(el) {
el.addEventListener('click', function() {
chrome.runtime.openOptionsPage()
window.close()
})
})
// Get data from URL and storage // Get data from URL and storage
var inputParams = new URL((window.location.href)).searchParams var inputParams = new URL((window.location.href)).searchParams
var shareLink = inputParams.get('link') var shareLink = inputParams.get('link')
var shareText = inputParams.get('text') var shareText = inputParams.get('text')
var data = await chrome.storage.sync.get() var data = await chrome.storage.sync.get()
// Show warning if no servers are saved // Show warning if no servers are saved
if (!data.serverList) { if ((!data.serverList) || (data.serverList.length === 0)) {
document.querySelector('#server-warning').classList.remove('d-none') document.querySelector('#server-warning').classList.remove('d-none')
return false return false
} }
// If there's only one server, redirect to that one
if (data.serverList.length === 1) {
document.querySelector('#server-loading').classList.remove('d-none')
window.location = 'https://' + data.serverList[0] + '/share?text=' + encodeURIComponent(shareText + '\n\n' + shareLink)
return false
}
// Create list of servers // Create list of servers
var serverListEl = document.querySelector('#server-list') var serverListEl = document.querySelector('#server-list')
for (server in data.serverList) { for (server in data.serverList) {

View File

@ -16,10 +16,6 @@
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
<!-- Alert for no server -->
<div class="alert alert-primary d-none mb-3" id="mastodon-server-alert" role="alert">
You have to enter a server before you can share links!
</div>
<!-- Server select --> <!-- Server select -->
<div class="mb-1"> <div class="mb-1">
<label for="mastodon-server-list" class="form-label">Mastodon servers</label> <label for="mastodon-server-list" class="form-label">Mastodon servers</label>

View File

@ -21,14 +21,14 @@
<body> <body>
<!-- UI for no servers saved --> <!-- UI for no servers saved -->
<div id="server-warning" class="container text-center p-5 d-none"> <div id="server-warning" class="container text-center p-5 d-none">
You don't have any servers saved! Why don't you <a href="#">add some</a>? You don't have any servers saved! Why don't you <a href="#" class="extension-settings-link">add some</a>?
</div> </div>
<!-- Server selection UI --> <!-- Server selection UI -->
<div id="server-list" class="list-group mb-2 list-group-flush border-bottom d-none"> <div id="server-list" class="list-group mb-2 list-group-flush border-bottom d-none">
<li class="list-group-item list-group-item-dark"> <li class="list-group-item list-group-item-dark">
Select a server Select a server
<div class="float-end"> <div class="float-end">
<a href="#" target="_blank"> <a href="#" class="extension-settings-link">
Edit servers Edit servers
</a> </a>
</div> </div>