this post was submitted on 11 Jun 2023
35 points (100.0% liked)

Lemmy.World Announcements

29165 readers
32 users here now

This Community is intended for posts about the Lemmy.world server by the admins.

Follow us for server news ๐Ÿ˜

Outages ๐Ÿ”ฅ

https://status.lemmy.world

For support with issues at Lemmy.world, go to the Lemmy.world Support community.

Support e-mail

Any support requests are best sent to [email protected] e-mail.

Report contact

Donations ๐Ÿ’—

If you would like to make a donation to support the cost of running this platform, please do so at the following donation URLs.

If you can, please use / switch to Ko-Fi, it has the lowest fees for us

Ko-Fi (Donate)

Bunq (Donate)

Open Collective backers and sponsors

Patreon

Join the team

founded 2 years ago
MODERATORS
 

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!

// ==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
// @grant        GM_addStyle
// ==/UserScript==

const localLemmy = 'lemmy.world';
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 = '<button id="localize" type="button">Open in local instance</button>';
        zNode.setAttribute('id', 'localizeContainer');
        document.body.appendChild(zNode);
        document.getElementById ("localize").addEventListener (
            "click", onLocalize
        );
    }
}

function onLocalize (zEvent) {
    window.location.replace(localizedUrl);
}

GM_addStyle ( `
    #localizeContainer {
        position: fixed;
        right: 0px;
        bottom: 0px;
    }
    #localize {
        cursor: pointer;
        padding: 16px;
    }
` );

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 5 points 2 years ago (2 children)

Henlo buddy, your script didn't work for me, so I fixed it. Works for me now. I also changed lemmy.world to sh.itjust.works so beware.

Here's my final one:

// ==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);
}
[โ€“] TCGM 3 points 2 years ago (2 children)

https://greasyfork.org/en/scripts/468521-lemmings-fix

Threw yours up on greasyfork so people can easily install it, just poke me if you'd like me to take it down so you can put your own up

[โ€“] [email protected] 3 points 2 years ago (1 children)

if you're willing could you tell me how to upload a script there?

[โ€“] TCGM 2 points 2 years ago (1 children)

First you need to sign in or up here:

https://greasyfork.org/en/users/sign_in

Then you need to visit this page and fill out the form, including with the script

https://greasyfork.org/en/script_versions/new

[โ€“] [email protected] 2 points 2 years ago

ty, i'll add a reminder to check this out 2moro when i'm more awake

[โ€“] [email protected] 2 points 2 years ago

i tried to upload it to tampermonkey and failed lol. if i knew how i'd do it. i'm always making userscripts and it'd be good to have them all somewhere.