[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 sh.itjust.works/post/33762](local instance redirect script) by @soy
I started using Tampermonkey today, so dunno if this works with GreaseMonkey, but I assume it does.
<span style="color:#323232;">// ==UserScript==
</span><span style="color:#323232;">// @name Lemmings Redirect
</span><span style="color:#323232;">// @version 1.0
</span><span style="color:#323232;">// @description Redirect to your local Lemmy instance
</span><span style="color:#323232;">// @author @reddthat.com/u/Fanghole
</span><span style="color:#323232;">// @match https://*/c/*@*
</span><span style="color:#323232;">// @icon https://join-lemmy.org/static/assets/icons/favicon.svg
</span><span style="color:#323232;">// ==/UserScript==
</span><span style="color:#323232;">
</span><span style="color:#323232;">var unknownLemmy =
</span><span style="color:#323232;"> document.body.textContent === "404: couldnt_find_community";
</span><span style="color:#323232;">
</span><span style="color:#323232;">if (unknownLemmy) {
</span><span style="color:#323232;"> // Get URL info
</span><span style="color:#323232;"> var splitUrl = location.href.split("/");
</span><span style="color:#323232;"> var split2 = splitUrl[4].split("@");
</span><span style="color:#323232;"> var instanceUrl = split2[1];
</span><span style="color:#323232;"> var community = split2[0];
</span><span style="color:#323232;"> var searchUrl =
</span><span style="color:#323232;"> "https://" + splitUrl[2] + "/search/q/!" + community + "%40" + instanceUrl + "/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1";
</span><span style="color:#323232;">
</span><span style="color:#323232;"> window.location.replace(searchUrl);
</span><span style="color:#323232;">}
</span>
Add comment