Removes the big obvious button, replaces the ![community] links instead
on mouseenter to get around the elements getting reset by something after loading
It works even if the url shown by the browser hasn't changed yet (weird)
I've only tested it on Firefox
Use it if you want.
// ==UserScript==
// @name Lemmings Fix
// @version 1.0
// @description Redirect to your local Lemmy instance
// @author @lemmy.world/u/soy @beehaw.org/u/abclop99
// @match https://*/c/*
// @icon https://join-lemmy.org/static/assets/icons/favicon.svg
// ==/UserScript==
// URL of your local lemmy instance
const localLemmy = "beehaw.org";
// Check html metadata description
var isLemmy =
document.head.querySelector("[name~=Description][content]").content ===
"Lemmy";
if (isLemmy) {
// Create url to local instance
var splitUrl = location.href.split("/");
var instanceUrl = splitUrl[2];
var community = splitUrl[4];
var localizedUrl = createLocalizedUrl(localLemmy, community)
// Create redirect button if not on local
if (instanceUrl !== localLemmy) {
// Selector for links
// a[href="/c/community"]g
var querySelector = 'a[href="/c/' + community + '"]';
// Get elements
var elements = document.querySelectorAll (querySelector);
// Add event listener to change link when the mouse enters the element
// This is so the link does not get overwritten by other js
elements.forEach(e => e.addEventListener(
"mouseenter",
() => e.setAttribute("href", localizedUrl),
))
}
}
function createLocalizedUrl(localLemmy, community) {
var localizedUrl =
"https://" + localLemmy + "/c/" + community + "@" + instanceUrl;
return localizedUrl;
}
I modified the script a lot:
![community]
links insteadmouseenter
to get around the elements getting reset by something after loading