this post was submitted on 11 Jun 2023
26 points (100.0% liked)

Lemmy.World Announcements

28641 readers
71 users here now

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

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

Support e-mail

Any support requests are best sent to [email protected] e-mail.

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

founded 1 year ago
MODERATORS
26
submitted 1 year ago* (last edited 1 year ago) by Zeus 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/[email protected])
		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

all 21 comments
sorted by: hot top controversial new old
[โ€“] RockDeBilly 4 points 1 year ago* (last edited 1 year ago)

Thanks that super useful, especially in places like /c/newcommunities where people (including me) are still unsure how to properly link communities.

[โ€“] god 2 points 1 year ago* (last edited 1 year ago) (1 children)

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.

[โ€“] Zeus 2 points 1 year ago* (last edited 1 year ago) (2 children)

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

[โ€“] LonelyNematocyst 2 points 1 year ago (1 children)

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.

[โ€“] Zeus 1 points 1 year ago

i'm glad that's being tracked, as a bookmarklet is not really a great solution; but it's still not a complete solution. if i visit a lemmy post from outside lemmy.world (e.g. search engine), then there's no way to go to the l.w version (to my knowledge)

[โ€“] god 2 points 1 year ago (1 children)

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

[โ€“] Zeus 2 points 1 year ago

for clarity, i'm presuming you're talking about redirecting from e.g. this [https://lemmy.ml/post/1190997] to this [https://lemmy.world/post/38761]

but yeah, i'm afraid i can't help [yet?]

[โ€“] Yoru 2 points 1 year ago (2 children)

Hello, I just made a new bookmarklet where it automatically transfers all of your subscribed communities to another instance, can be found here

[โ€“] Zeus 2 points 1 year ago* (last edited 1 year ago) (1 children)

i'll be honest, i'm not sure what that's for? is it moving to another account if you want to change your home instance? if so, that's a good idea, i could add it to the post if you want in case this comment gets buried

spoileralthough i'm not entirely certain using https://github.com/Rob--W/cors-anywhere/issues/301 is a great idea..

[โ€“] Yoru 1 points 1 year ago

I didn't want to use it but I didn't see any other way to tackle the cors issue

[โ€“] [email protected] 1 points 1 year ago

Tried this with a throwaway, but it's broken.

Subscription location has changed.

When corrected, it asks to visit https://cors-anywhere.herokuapp.com/corsdemo to request access. Despite doing so, it never gets past that point.

When/if you fix it, you might give some context about how you're handling user credentials.

[โ€“] Yoru 2 points 1 year ago (1 children)

also, you should replace const myInst="lemmy.world"; with const myInst = window.location.hostname;, it automatically fetches what instance you're on.

[โ€“] Zeus 2 points 1 year ago* (last edited 1 year ago)

that (unless i'm misunderstanding) isn't the point of it. it's made for quickly taking you from e.g. https://lemmy.ml/c/jerboa to https://lemmy.world/c/[email protected], so it needs a const to know which instance to take you to

edit: i guess i could replace let currInst=currUrl[2]; with let currInst=window.location.hostname; but i can't see a practical difference and so i chose the shorter one

[โ€“] TeaHands 2 points 1 year ago

You goddamn hero.

[โ€“] [email protected] 2 points 1 year ago (1 children)

Do you know if the process works differently in FireFox? (Note that technically I use Ghostery but it's based in Firefox). I copied the script to a new bookmark URL and changed lemmy.world to lemmy.one since thats the instance I'm registered on. However, when clicked nothing happens. Is there something I'm missing?

[โ€“] Zeus 2 points 1 year ago (1 children)

i can tell you that i made and currently use it with firefox...

sanity check, when you select edit bookmark it should look like this

however, i don't know about ghostery (i didn't even know they made a browser). it's possible they block arbitrary js for security reasons? it would be a dumb choice in my opinion, but i guess it's protecting you from yourself?

however i can tell you a couple of things. this doesn't work with some communities (they just 404), but that happens if one puts the url in manually. i don't know when or why this happens, but it does seem to happen a lot with lemmy.one. i wonder if it's a l.1 federation issue

[โ€“] [email protected] 2 points 1 year ago (2 children)

Interesting. ok I'll dig further into it being Ghostery related then.

For your sanity, yes, looks relatively the same on me end when I edit bookmark.

[โ€“] Zeus 1 points 1 year ago

weird - sorry i couldn't help.. : (