store/retrieve last used Mastodon instance to/from local storage

This commit is contained in:
Marcus Jaschen 2023-12-21 13:19:25 +01:00 committed by Gautier P
parent 0d15726250
commit 2a7dc36678

View file

@ -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');
});
}