Original post, containing the original code @soy@lemmy.world made: https://sh.itjust.works/post/33762
his original message:
For those that use Tampermonkey or GreaseMonkey, here’s a quick script I whipped up that creates a button that redirects communities from other instances to your local instance. If your instance isn’t
lemmy.world, then change thelocalLemmyvar at the top. Enjoy!
My small fix:
For personal use, I changed localLemmy to sh.itjust.works because that's my instance. I also embedded some styles and made it so it's top right instead of bottom left, and so that it's red and works better for me. Soy's original code didn't work for me so I had to make these small alterations to get it working.
// ==UserScript==
// @name Lemmings Fix
// @version 1.0
// @description Redirect to your local Lemmy instance
// @author @lemmy.world/u/soy
// @match https://*/c/*
// @icon https://join-lemmy.org/static/assets/icons/favicon.svg
// ==/UserScript==
const localLemmy = "sh.itjust.works";
var isLemmy =
document.head.querySelector("[name~=Description][content]").content ===
"Lemmy";
if (isLemmy) {
// Get URL info
var splitUrl = location.href.split("/");
var instanceUrl = splitUrl[2];
var community = splitUrl[4];
var localizedUrl =
"https://" + localLemmy + "/c/" + community + "@" + instanceUrl;
// Create redirect button if not on local
if (instanceUrl !== localLemmy) {
var zNode = document.createElement("div");
zNode.innerHTML = "Open in local instance";
zNode.setAttribute("id", "localizeContainer");
// add styles to the button embedded
zNode.setAttribute(
"style",
"cursor: pointer; padding: 16px; background-color: red; border-radius: 10%; border-width: 3px; border-style: solid; padding: 3px; z-index: 10;max-width:200px;position:fixed;top:0;right:0;"
);
zNode.addEventListener("click", onLocalize);
document.body.appendChild(zNode);
}
}
function onLocalize() {
window.location.replace(localizedUrl);
}
12 Comments
Lyxea@lemmy.world · 5 pts · 3y
god@sh.itjust.works · 5 pts · 3y
And God rested on the seventh day or something. I didn't sleep today from so much Lemmying. I should sleep soon or perish.
Lyxea@lemmy.world · 3 pts · 3y
ShutYourPieHole@sh.itjust.works · 5 pts · 3y
This is awesome and removes a lot of the stumbling that I've been doing in the federated world. Thank you!
boo@lemmy.world · 3 pts · 3y
Thanks! This is the exact script that I was hoping to find!
god@sh.itjust.works · 3 pts · 3y
easily one of the things i use the most 😎 if not THE one
SilentStorms@lemmy.fmhy.ml · 3 pts · 3y
Thanks for this script! With next to no scripting experience, I managed to edit this to cover the other instance's logo with the one from mine. img
god@sh.itjust.works · 3 pts · 3y
Hahah, not the most respectful thing to do but that's okay c: glad you got it working the way you wanted.
SilentStorms@lemmy.fmhy.ml · 3 pts · 3y
Oh I didn't even consider that it might be disrespectful, I just wanted it to blend in :(. I was trying to get it to be an icon on the navbar, but I couldn't figure out how to make it not snap to a corner lol.
I do browse other instances a lot by visiting their homepage, so I'm not totally missing the logos.
god@sh.itjust.works · 2 pts · 3y
That's all good 😎 just browse to your own liking! Nothing matters, god is dead, morality is a spook, Epstein killed himself and Santa killed all the elves
flauschke@feddit.de · 3 pts · 3y
I've adapted it to work on kbin - let me know if anyone finds any issues