Skip Navigation

[Userscript] Simple 404 Community not found straight to local search

If you try to access a community on your local instance and it gives you a 404, this automatically takes you to your local instance's search instead and puts the community in for you.

Recommended to use with https://sh.itjust.works/post/33762](local instance redirect script) by @[email protected]

I started using Tampermonkey today, so dunno if this works with GreaseMonkey, but I assume it does.

// ==UserScript==
// @name         Lemmings Redirect
// @version      1.0
// @description  Redirect to your local Lemmy instance
// @author       @reddthat.com/u/Fanghole
// @match        https://*/c/*@*
// @icon         https://join-lemmy.org/static/assets/icons/favicon.svg
// ==/UserScript==

var unknownLemmy =
  document.body.textContent === "404: couldnt_find_community";

if (unknownLemmy) {
    // Get URL info
    var splitUrl = location.href.split("/");
    var split2 = splitUrl[4].split("@");
    var instanceUrl = split2[1];
    var community = split2[0];
    var searchUrl =
        "https://" + splitUrl[2] + "/search/q/!" + community + "%40" + instanceUrl + "/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1";

    window.location.replace(searchUrl);
}
0
0 comments