this post was submitted on 23 Jun 2023
55 points (100.0% liked)

Lemmy Plugins and Userscripts

375 readers
1 users here now

A general repository for user scripts and plugins used to enhance the Lemmy browsing experience.

Post (or cross-post) your favorite Lemmy enhancements here!

General posting suggestions:

Thanks!

founded 1 year ago
MODERATORS
 

Description

Lemmy Universal Link Switcher, or LULs for short, scans all links on all websites, and if any link points to a Lemmy instance that is not your main/home instance, it rewrites the link so that it instead points to your main instance. Currently only works for community/user links.

Home Instance Setup

Simply visit the Lemmy instance you want to set as your home while the script is active. You will be asked if you want to set this instance to your home instance:
home

If you initially set your home instance wrong or just want to change it, no worries - simply go to your settings on your new home instance and press the button for it!
settings

Features

  • Rewrite all links of communities or users on all websites everywhere to your new instance! The rewritten links will have an icon next to it, and hovering/touching the icon will show you the original link, allowing you to go there if you want to.
    rewrite

  • If you are already on a page that has a corresponding page on your home instance, a link will automatically be added to the page header.
    redirect

Coming soon

  • Post & comment links. Those are a bit harder because the URL has to be requested from the instances.

Repository & Issues

top 41 comments
sorted by: hot top controversial new old
[–] [email protected] 7 points 1 year ago* (last edited 1 year ago)

Also works on Android on Firefox with TamperMonkey, that's what I'm mainly using it on. Also only tested it on Firefox, no idea about Chrome or anything else.

[–] [email protected] 5 points 1 year ago* (last edited 1 year ago) (4 children)

I installed it on Firefox with Greasemonkey. I don't get the dialog asking if I want to set my instance to my home instance, and I have no button in my settings. So, at the moment, the script appears to be inoperative.

Edit: Tried a few more things. I visited several other instances, other than my home instance of lemmy.ca, and still don't get any dialog about setting an instance to my home instance. Greasemonkey shows the script as enabled, but that's it. I'm running Firefox 114.0.2 on Arch Linux.

Edit2: Attempted to post an issue at the referenced Gitlab page, but this page does not exist, and a search for this project was a dead end. I have disabled the script until/unless the authors provide more information as to what is going on.

Edit3: Found the Gitlab project. The provided URL on the Greasyfork page is incorrect. It should be https://gitlab.com/foundry-azzurite/lemmy-rewrite-links

I will leave an issue.

[–] [email protected] 3 points 1 year ago

Same experience here.

[–] [email protected] 2 points 1 year ago

Went to bed after I posted this. Will take a look in a bit.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago) (1 children)

Need to get a bit of feedback from you.

Any errors in the browser console (F12 by default)? So go to lemmy.ca, press F12, make sure the console is open, refresh, look for red error messages. If there are, copy them to me.

[–] [email protected] 1 points 1 year ago (1 children)

Yes. The following error appears:

Script error in [Greasemonkey script http://azzurite.tv//Lemmy - Rewrite Links to Home Instance; version 1.0.0]: ReferenceError: GM_getValue is not defined

[–] [email protected] 1 points 1 year ago (1 children)

What addon are you using for userscripts?

[–] [email protected] 1 points 1 year ago (1 children)
[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

Alrighty, try updating, I've released a new version.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

Got the 'home instance' dialog this time. Briefly checked it out, some of the links seem to be now directed towards my home instance, but there are no icons beside any link to show the original link as indicated in the description above.

Edit: Noticed the following error in the console:

Source map error: Error: URL constructor: tippy-bundle.umd.min.js.map is not a valid URL. Resource URL: user-script:http%3A//azzurite.tv//Lemmy%20-%20Rewrite%20Links%20to%20Home%20Instance Source Map URL: tippy-bundle.umd.min.js.map

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (2 children)

That error's irrelevant. Can you check that you have version 1.0.2 not 1.0.1?

[–] [email protected] 1 points 1 year ago (1 children)

Ah, yes. It's 1.0.1. Let me upgrade once again.

[–] [email protected] 2 points 1 year ago

Yep I fucked up :D

[–] [email protected] 1 points 1 year ago (1 children)

I have 1.0.1. An attempted update shows 'No newer update available.'

[–] [email protected] 1 points 1 year ago (1 children)

Go to https://greasyfork.org/en/scripts/469273-lemmy-rewrite-links-to-home-instance and press the button there. There's probably some throttling or whatever.

[–] [email protected] 1 points 1 year ago (2 children)

Got it. Upgraded to 1.0.2.

Still no icons to the right of links.

[–] [email protected] 2 points 1 year ago (3 children)

Maybe try violentmonkey instead of greasemonkey, which does not seem to be in development anymore.

[–] [email protected] 1 points 1 year ago

Yeah, that's not a bad idea. I think I'll give that a try a bit later when I get some time, as I'll have several scripts I'll need to move over to it.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

...and I spoke too soon. Worked fine when I installed it. As soon as I went to another page on the instance it stopped working again. No icons, no button in settings. No idea what's going on.

[–] [email protected] 1 points 1 year ago (1 children)

Does it work again when you do a full refresh? So F5/press enter in the adress bar? If so then somehow listening to page changes is broken for you, lemmy doesn't actually load new pages when you click on an (instance-local) link, it just exchanges all the content within the currently loaded page.

[–] [email protected] 1 points 1 year ago (1 children)

Does it work again when you do a full refresh? So F5/press enter in the adress bar?

It does not. I've tried that several times. Also tried opening a new tab and typing the site url directly.

[–] [email protected] 1 points 1 year ago (1 children)

I'm going to add a lot of logging and then give you a new version to try, then you can give me logs so I can diagnose this. There must be something weird about your setup, though I can't guess what.

[–] [email protected] 1 points 1 year ago (1 children)

Yup, that's my thinking too that there must be something weird going on here, though I can't imagine what.

Just for fun, I fired up Chrome instead of Firefox, installed violentmonkey, installed your script, and am having the exact same issue there! I did get the dialog asking me to set the home instance, which I did, but no button in settings and no icons. No idea what's going on.

[–] [email protected] 1 points 1 year ago (1 children)

Wild idea, but could it just be that you're using it wrong? :D if you're on lemmy.ca then almost nothing should be rewritten because almost all links already go to lemmy.ca. Only when you go to another instance somehow or a user posts a link, for example this one then it should be rewritten.

Anyway though, here is a debug version of the script: https://gitlab.com/-/snippets/2561468/raw/main/lemmy.user.js

To use, open the browser console, unselect all message types at the top right (errors, warnings, logs...) except for the "Debug" message type, then reload the page and right-click -> send me all messages.

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

Wild idea, but could it just be that you’re using it wrong? :D if you’re on lemmy.ca then almost nothing should be rewritten because almost all links already go to lemmy.ca. Only when you go to another instance somehow or a user posts a link, for example this one then it should be rewritten.

I did think of that! Sure wouldn't be the first time I've done something like that, hehehe!! But no. For example, I'm on lemmy.ca, so I tried going to lemmy.ml and lemmy.world to see what the links looked like there. One of those I have a different account which I was logged in to, and the other I have no account so wasn't signed in. Nothing.

However, I've been trying a few things here, including disabling all my other extensions and scripts, which didn't make any difference. So then I left every extension disabled, removed your script, removed the few other scripts I installed in violentmonkey, removed violentmonkey, reinstalled violentmonkey and your script....and it was working again once more. So, I figured some other script or extension was causing havoc, so I renabled the other extensions and reinstalled the other scripts one by one, checking each time. They're all enabled again. Still working. I dunno....... Obviously something really weird is happening on my end. Right now, it's working, so I'll let you know if it starts to act odd again. My thinking right now is some other extension or script was messing something up big time, and all the disabling and re-enabling sorted it out somehow.

My working hypothesis right now: The issue wasn't your script, it was something else on my system.

Thanks for your help with this, btw!

[–] [email protected] 1 points 1 year ago (1 children)

Very weird :D glad it works now though :)

[–] [email protected] 1 points 1 year ago

Me too. I went back and checked Chrome, and that was indeed my fault. I was being a doorknob, and so led myself astray, lol.

Still working, so far! :)

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Gave violentmonkey a try. Your script worked perfectly immediately. So yeah, something in greasemonkey was causing the issues.

Thanks for writing this, looks great so far!!

[–] [email protected] 1 points 1 year ago

Yeah no idea, you can change DEBUG from true to false and see if it's outputting any messages at all. I'd probably need to do some more advanced debugging steps, idk if you're willing to do that

[–] knifer 1 points 1 year ago

Same here. Error seems to be:

ReferenceError: GM_getValue is not defined Lemmy - Rewrite Links to Home Instance:331:19
    <anonymous> user-script:http://azzurite.tv//Lemmy - Rewrite Links to Home Instance:331
[–] Someology 3 points 1 year ago (1 children)

This should be integrated into Lemmy itself as a feature.

[–] weavejester 1 points 1 year ago (1 children)

I don't believe this would be possible without relying on a userscript or a centralised site.

[–] Someology 2 points 1 year ago (2 children)

Assuming you are logged in to the website, couldn't the website just check to see where you're logged in to? Seems like a cookie might be able to do that (if the user gave permission)?

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago)

The functionality in this script is indeed only possible as an addon or userscript. Browsers specifically spent a lot of work trying to make it impossible for one site to get any information about which other sites the user visited, and for good reason. Just imagine the phishing this would allow if it were possible.

That said, there could of course be an official lemmy browser addon/userscript for this functionality. But it definitely wouldn't be baked into the sites themselves.

Because idk if you noticed, but this script actually rewrites all links everywhere, so for example even if you get a result to some lemmy instance on duckduckgo, the link on duckduckgo itself will already point to your instance. Please tell me how that would be possible without an addon/userscipt :D

[–] weavejester 1 points 1 year ago

Cookies can only be read by the same domain (or subdomain). So a cookie set by lemmy.ml couldn't be read by lemmy.world, as their domains are different. This is called the "same-origin policy", and applies to all forms of local storage in browsers.

[–] wmrch 2 points 1 year ago (1 children)

This works great for me on lemmy instances! However, it doesn't seem to work on kbin.social (it is included in const INSTANCES_KBIN). Would be great if this was working on kbin instances too!

[–] [email protected] 3 points 1 year ago (1 children)

That's already known, see "Coming soon".

[–] wmrch 1 points 1 year ago

Right, it's right there, read past it, nvm.

[–] [email protected] 2 points 1 year ago

This is amazing! Just what I've been looking for, at least until this gets implemented into the site itself. Thanks a lot for making and sharing this.

load more comments
view more: next ›