Open profiles and posts from every Mastodon instance with phanpy.social
0
Phanpy bookmarklet
29 lines 995 B view raw
1javascript:(async function(){ 2 var url = new URL(window.location.href); 3 var domain = url.hostname; 4 var path = url.pathname; 5 6 /* Check if it's a post (it has an ID at the end) */ 7 var postMatch = path.match(/\/@[^\/]+\/(\d+)/); 8 if (postMatch) { 9 window.location.href = "https://phanpy.social/#/" + domain + "/s/" + postMatch[1]; 10 return; 11 } 12 13 /* If it's a profile: Look up the ID via the API */ 14 var profileMatch = path.match(/\/(@[^\/]+)/); 15 if (profileMatch) { 16 try { 17 var response = await fetch("https://" + domain + "/api/v1/accounts/lookup?acct=" + profileMatch[1]); 18 var data = await response.json(); 19 if (data.id) { 20 window.location.href = "https://phanpy.social/#/" + domain + "/a/" + data.id; 21 } else { 22 throw new Error(); 23 } 24 } catch (e) { 25 /* Fallback to search if the API lookup fails */ 26 window.location.href = "https://phanpy.social/#/search?q=" + encodeURIComponent(window.location.href); 27 } 28 } 29})();