Improve server URL input (#4)

This commit is contained in:
Corbin Davenport 2023-07-10 23:39:55 -04:00
parent 36378cd25b
commit 135bc911a1
2 changed files with 20 additions and 13 deletions

View File

@ -30,16 +30,23 @@ function saveSettings() {
// Add server to list // Add server to list
document.querySelector('#server-add-btn').addEventListener('click', function () { document.querySelector('#server-add-btn').addEventListener('click', function () {
var domain = document.querySelector('#mastodon-server-text').value.replace(' ', '') // Get hostname from input
if (domain) { var serverInput = document.querySelector('#mastodon-server-text').value.replace(' ', '');
var el = document.createElement('option') var serverDomain = '';
el.value = domain if (serverInput.startsWith('https://')) {
el.innerText = domain var serverObj = new URL(serverInput);
serverList.appendChild(el) serverDomain = serverObj.hostname;
serverList.value = domain } else {
document.querySelector('#mastodon-server-text').value = '' serverDomain = serverInput;
saveSettings()
} }
// Add URL to list
var el = document.createElement('option')
el.value = serverDomain
el.innerText = serverDomain
serverList.appendChild(el)
serverList.value = serverDomain
document.querySelector('#mastodon-server-text').value = ''
saveSettings()
}) })
// Remove button // Remove button

View File

@ -31,7 +31,7 @@
<label for="mastodon-server-text" class="form-label">Add a server</label> <label for="mastodon-server-text" class="form-label">Add a server</label>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" id="mastodon-server-text" placeholder="yourserver.social" aria-label="Server domain" aria-describedby="server-help"> <input type="text" class="form-control" id="mastodon-server-text" placeholder="yourserver.social" aria-label="Server domain" aria-describedby="server-help">
<button class="btn btn-outline-primary" type="button" id="server-add-btn">Add</button> <button class="btn btn-outline-primary" type="button" id="server-add-btn">Add server</button>
</div> </div>
<div id="server-help" class="form-text">This must be a server running <a href="https://joinmastodon.org/" target="_blank">Mastodon</a>, <a href="https://calckey.org/" target="_blank">Calckey</a>, <a href="https://join.misskey.page/en-US/" target="_blank">Misskey</a>, or another compatible social media platform.</div> <div id="server-help" class="form-text">This must be a server running <a href="https://joinmastodon.org/" target="_blank">Mastodon</a>, <a href="https://calckey.org/" target="_blank">Calckey</a>, <a href="https://join.misskey.page/en-US/" target="_blank">Misskey</a>, or another compatible social media platform.</div>
<!-- Server select --> <!-- Server select -->
@ -56,9 +56,9 @@
<h2>Donate</h2> <h2>Donate</h2>
<p>If you find Share to Mastodon useful, please donate to support continued development. It would mean a lot!</p> <p>If you find Share to Mastodon useful, please donate to support continued development. It would mean a lot!</p>
<a href="https://www.patreon.com/corbindavenport" target="_blank"> <a href="https://www.patreon.com/corbindavenport" target="_blank">
<button type="button" class="btn btn-success w-100 mb-3">Join the Patreon</button> <button type="button" class="btn btn-success w-100 mb-3">Support via Patreon</button>
</a> </a>
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4SZVSMJKDS35J&lc=US&item_name=Peek%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank"> <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4SZVSMJKDS35J&lc=US&item_name=Share%20to%20Mastodon%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" target="_blank">
<button type="button" class="btn btn-success w-100 mb-3">Donate via PayPal</button> <button type="button" class="btn btn-success w-100 mb-3">Donate via PayPal</button>
</a> </a>
<a href="https://cash.app/$corbdav" target="_blank"> <a href="https://cash.app/$corbdav" target="_blank">