Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active November 19, 2024 16:33
Show Gist options
  • Save rauschma/677544618b73dc4e3d11611e298cbe3a to your computer and use it in GitHub Desktop.
Save rauschma/677544618b73dc4e3d11611e298cbe3a to your computer and use it in GitHub Desktop.
Bookmarklet for Mastodon: Transport a profile or post to your server

Bookmarklet for Mastodon: Transport a profile or post to your server

This bookmarklet shows a profile or a post on another Mastodon server in your server’s web app.

Installation

  • Change the value of HOST to the domain of your Mastodon server.
  • Create a bookmark and paste the lines in show-in-mastodon-web-app.js into its address (browsers are OK with pasting multiple lines).

Usage

  • Go to a profile or a post on another Mastodon server.
  • Click the bookmarklet.

Acknowledgement: Thanks to @[email protected] for telling me the authorize_interaction trick.

javascript: {
const HOST = 'mastodon.green';
const canonicalHref = document.querySelector('link[rel=canonical]')?.href;
const originalUrl = new URL(canonicalHref ?? location.href);
const parts = originalUrl.pathname.split('/');
if (parts.length === 2) {
/* Profile: ['', '@rauschma'] */
const userName = parts[1];
location.href = `https://${HOST}/${userName}@${originalUrl.host}`;
} else {
/* Post: ['', '@rauschma', '112728257468727280'] */
location.href = `https://${HOST}/authorize_interaction?uri=${originalUrl.href}`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment