this post was submitted on 13 Jun 2023
24 points (100.0% liked)

Lemmy Plugins and Userscripts

2017 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
 

Original post, containing the original code @[email protected] 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 the localLemmy var 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);
}
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 1 year ago (1 children)

Hahah, not the most respectful thing to do but that's okay c: glad you got it working the way you wanted.

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

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.

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

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