Don't show server list if only one server is saved
This commit is contained in:
parent
15b00bde2a
commit
e806404e43
15
js/share.js
15
js/share.js
|
@ -14,16 +14,29 @@ var shareLink = ''
|
|||
*/
|
||||
|
||||
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
|
||||
var inputParams = new URL((window.location.href)).searchParams
|
||||
var shareLink = inputParams.get('link')
|
||||
var shareText = inputParams.get('text')
|
||||
var data = await chrome.storage.sync.get()
|
||||
// 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')
|
||||
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
|
||||
var serverListEl = document.querySelector('#server-list')
|
||||
for (server in data.serverList) {
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
|
||||
<body>
|
||||
<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 -->
|
||||
<div class="mb-1">
|
||||
<label for="mastodon-server-list" class="form-label">Mastodon servers</label>
|
||||
|
|
|
@ -21,14 +21,14 @@
|
|||
<body>
|
||||
<!-- UI for no servers saved -->
|
||||
<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>
|
||||
<!-- Server selection UI -->
|
||||
<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">
|
||||
Select a server
|
||||
<div class="float-end">
|
||||
<a href="#" target="_blank">
|
||||
<a href="#" class="extension-settings-link">
|
||||
Edit servers
|
||||
</a>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue