JS Bookmarklet for Switching to lemmy.world

3 years ago by Ɀeus to c/lemmyworld

i find it annoying to have to manually change urls to subscribe to a community outside lemmy.world, so i wrote a bookmarklet to quickly switch to the lemmy.world instance

to use, just drag the following code to your bookmarks bar (name it whatever you like), then click it when you want to use it

javascript:(function(){const myInst="lemmy.world";let currUrl=window.location.toString().split("/");let currInst=currUrl[2];currUrl[2]=myInst;if(currUrl[3]=="m"){currUrl[3]="c";}let newUrl=currUrl.join("/");if(!(currUrl[-1].includes("@"))){newUrl=newUrl+"@"+currInst;}window.location=newUrl;})()

readable version:

javascript:(
    function() {
        // make sure to change this if using on a different instance
        const myInst="lemmy.world";
        let currUrl=window.location.toString().split("/");
        let currInst=currUrl[2];
        currUrl[2]=myInst;
        // fix for kbin using "m" instead, 
        // without overriding /u/ for user
        if (currUrl[3]=="m") {
            currUrl[3]="c";
        }
        let newUrl=currUrl.join("/");
        // fix for already foreign instances (e.g. lemm.ee/c/jerboa@lemmy.ml)
        if (!currUrl[-1].includes("@")) {
            newUrl=newUrl+"@"+currInst;
        }
        window.location=newUrl;
    })
()
old version

javascript:(function(){const myInst="lemmy.world";let currUrl=window.location.toString().split("/");let currInst=currUrl[2];currUrl[2]=myInst;currUrl[3]="c";let newUrl=currUrl.join("/")+"@"+currInst;window.location=newUrl;})()

readable version:

javascript:(
    function() {
        // make sure to change this if using on a different instance
        const myInst="lemmy.world";
        let currUrl=window.location.toString().split("/");
        let currInst=currUrl[2];
        currUrl[2]=myInst;
        currUrl[3]="c";  // fix for kbin using "m" instead
        let newUrl=currUrl.join("/")+"@"+currInst;
        window.location=newUrl;
    })
()

update 2023-06-27: add compatibility for kbin magazines
update 2023-07-01: compatibility with users, kbin, and already foreign instances

load all comments
god 2 points 3 years ago

do you know of any way to switch not a community but a post to another instance? afaik they're numeric so the number identifier is different on each instance which makes it hard.

path: 0 67461, hotness: undefined, score: 2, children: 5
Zeus 2 points 3 years ago

i'm afraid i don't. i did fiddle around a bit trying to find a relationship between url's, but I couldn't see one

if anyone more familiar with lemmy/activitypub can tell me, I'll update / add to the bookmarklet

path: 0 67461 71811, hotness: undefined, score: 2, children: 4
god 2 points 3 years ago

You probably understood me the first time but I'm editing because I made a mistake in how I phrased it.

to another community → instance

the number identifier is different on each community → instance

path: 0 67461 71811 74771, hotness: undefined, score: 2, children: 1
LonelyNematocyst 2 points 3 years ago

Staying on your home instance is currently an issue on the repo. Implementing it yourself would need using the search, which is complicated because it only works through a websocket connection.

path: 0 67461 71811 166849, hotness: undefined, score: 2, children: 1
lemmyworld
lemmyworld

@lemmy.world

login for more options
31476
771
648

This Community is intended for posts about the Lemmy.world server by the admins.

Follow us for server news 🐘

Outages 🔥

https://status.lemmy.world

For support with issues at Lemmy.world, go to the Lemmy.world Support community.

Support e-mail

Any support requests are best sent to info@lemmy.world e-mail.

Report contact

Donations 💗

If you would like to make a donation to support the cost of running this platform, please do so at the following donation URLs.

If you can, please use / switch to Ko-Fi, it has the lowest fees for us

Ko-Fi (Donate)

Bunq (Donate)

Open Collective backers and sponsors

Patreon

Join the team

go to feed...