Skip to content

Instantly share code, notes, and snippets.

@hcschuetz
Last active March 24, 2025 23:17
Show Gist options
  • Save hcschuetz/f712949563758291d0f42861643a6d82 to your computer and use it in GitHub Desktop.
Save hcschuetz/f712949563758291d0f42861643a6d82 to your computer and use it in GitHub Desktop.
A bookmarklet jumping from "plain" mastodon pages to phanpy.social

Phanpy Bookmarklet

I like to read mastodon content with phanpy.social (primarily because it displays threads nicely). But of course links to accounts and toots usually point to the original mastodon UI. The bookmarklet here jumps from there to the corresponding phanpy UI.

The bookmarklet also works for several other mastodon pages, including pages for hashtags. (The other supported cases are probably less useful.)

MIT License
Copyright (c) 2025 Heribert Schütz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
javascript:(async () => {
try {
const to = "phanpy.social";
function go(...args) {
document.location = `https://${to}/#/${args.join("/")}`;
}
const {protocol, host, pathname} = document.location;
if (protocol !== "https:") {
throw `Mastodon pages are expected to use HTTPS`;
}
if (host === to) {
throw `You are already on ${to}!`;
}
const [seg0, seg1] = pathname.replace(/^\/(:?deck\/)?/, "").split("/", 2);
switch (seg0) {
case "home": return go();
case "notifications": return go("notifications");
case "conversations": return go("mentions?type=private");
case "bookmarks": return go("b");
case "favourites": return go("f");
case "lists": return seg1 ? go("l", seg1): go("l");
case "public": switch (seg1) {
case "local": return go(host, "p", "l");
case undefined: return go(host, "p");
default: throw `Public feed "${seg1}" not supported on phanpy`;
}
case "tags": return go(host, "t", seg1);
default: if (seg0.startsWith("@")) {
if (seg1) return go(host, "s", seg1);
const response = await fetch(
`https://${host}/api/v1/accounts/lookup?acct=${seg0.substring(1)}`
);
if (!response.ok) throw "Could not retrieve account id";
const account = await response.json();
return go(host, "a", account.id);
}
}
throw `Not a supported mastodon page`;
} catch (exception) {
alert(exception);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment