From 2a7dc36678d775d21647ee373bd65b6176423e6a Mon Sep 17 00:00:00 2001 From: Marcus Jaschen Date: Thu, 21 Dec 2023 13:19:25 +0100 Subject: [PATCH] store/retrieve last used Mastodon instance to/from local storage --- js/control/ShareRoute.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/js/control/ShareRoute.js b/js/control/ShareRoute.js index ef4408f..ad017b1 100644 --- a/js/control/ShareRoute.js +++ b/js/control/ShareRoute.js @@ -31,16 +31,26 @@ BR.ShareRoute = L.Class.extend({ }); if (this.options.services.mastodon === true) { + let storedMastodonInstance; + if (BR.Util.localStorageAvailable()) { + storedMastodonInstance = localStorage.getItem('share/mastodonInstance'); + } $('.share-service-mastodon') .removeAttr('hidden') .on('click', function () { let mastodonServer = window.prompt( i18next.t('share.mastodon-enter-server-name'), - 'mastodon.social' + storedMastodonInstance ?? 'mastodon.social' ); + if (mastodonServer.indexOf('http') !== 0) { mastodonServer = 'https://' + mastodonServer; } + + if (BR.Util.localStorageAvailable()) { + localStorage.setItem('share/mastodonInstance', new URL(mastodonServer).hostname); + } + window.open(mastodonServer + '/share?text=' + encodeURIComponent(self.getShareUrl()), '_blank'); }); }