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

Lemmy Plugins and Userscripts

2175 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);
}
top 14 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 1 year ago (1 children)

God´s work with this scripts,keep working guys!

[–] god 5 points 1 year ago (1 children)

And God rested on the seventh day or something. I didn't sleep today from so much Lemmying. I should sleep soon or perish.

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

AHAHHA rest well and thanks for the work XD

[–] ShutYourPieHole 5 points 1 year ago

This is awesome and removes a lot of the stumbling that I've been doing in the federated world. Thank you!

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

I've adapted it to work on kbin - let me know if anyone finds any issues

// ==UserScript==
// @name         kbin lemmy redirect
// @version      1.0
// @description  Redirect kbin to your local Lemmy instance
// @author       @[email protected]
// @match        https://*/m/*
// @icon         https://join-lemmy.org/static/assets/icons/favicon.svg
// ==/UserScript==

// best effort guess
const isKbin = typeof KBIN_USER !== 'undefined' && typeof KBIN_MAGAZINE !== 'undefined';

if (isKbin) {
    // Get URL info
    const localLemmy = "feddit.de";
    const splitUrl = location.href.split("/");
    const instanceUrl = splitUrl[2];
    const community = splitUrl[4];
    const localizedUrl = "https://" + localLemmy + "/c/" + community + "@" + instanceUrl;

    // Create redirect button if not on local
    if (instanceUrl !== localLemmy) {
        const wrapper = document.createElement("div");
        wrapper.setAttribute("style", "width: 100%;position: fixed;top: 0;")

        const container = document.createElement("div");
        container.setAttribute("style", "position:relative;max-width: 1650px;width: 100%;margin: 0 auto;")
        const zNode = document.createElement("button");
        zNode.innerText = "Open in local instance";
        zNode.setAttribute("id", "localizeContainer");
        // add styles to the button embedded
        zNode.setAttribute(
            "style",
            "cursor: pointer; padding: 5px; margin-top: 55px; background-color: red; border-radius: 10%; border-width: 3px; border-style: solid; z-index: 10;max-width:200px;position:absolute;top:0;right:0;"
        );
        zNode.addEventListener("click", e => window.location.replace(localizedUrl));
        container.appendChild(zNode);
        wrapper.appendChild(container);
        document.body.appendChild(wrapper);
    }
}
[–] [email protected] 3 points 1 year ago* (last edited 1 year ago) (1 children)

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 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.

[–] god 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

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

Thanks! This is the exact script that I was hoping to find!

[–] god 2 points 1 year ago

easily one of the things i use the most 😎 if not THE one

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

Thank you for this! This works even on mobile. Download Iceraven, which is a fork of Firefox for Android that supports extensions like GreaseMonkey.

[–] god 2 points 1 year ago

nice, i use kiwi and it also accepts extensions, but since i don't use mobile as much and i use it differently i have not needed the extensions

[–] altf3 2 points 1 year ago

Excellent! thank you

load more comments
view more: next ›