Skip to content

Commit

Permalink
store/retrieve last used Mastodon instance to/from local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaschen authored and bagage committed Jun 1, 2024
1 parent 0d15726 commit 2a7dc36
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion js/control/ShareRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}
Expand Down

0 comments on commit 2a7dc36

Please sign in to comment.