|
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); |
|
} |
|
})(); |