Skip Navigation

Tampermonkey Script, um Remote Communities schnell adden zu können.

Hi,

ich habe hier ein kleines Tampermonkey-Script zusammengetippt, was bei einer Remoteinstanz einen Link auf die Suche nach der Community in der Heimatinstanz anzeigt. Das ganze funktioniert, wenn der Link der Community in der Alarm-Box rechts steht:

You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

https://i.imgur.com/jSVY19F.png

https://i.imgur.com/5iijXd5.png

Sicher nicht perfekt, Verbesserungsvorschläge gern gesehen. Public Domain Lizenz.

// ==UserScript==
// @name         Add Remote Community Link to Lemmy Descriptions
// @version      0.4
// @description  Add a link to a remote community description in the form of "https://home.tld/c/[email protected]"
// @author       SomeDude
// @match        https://*/c/*
// @match        https://*/post/*
// @match        https://*/comment/*
// @grant        none
// ==/UserScript==

window.addEventListener('load', function() {
   const home = "feddit.de";
   const communityDescription = document.querySelector(".alert.alert-info");
   if(communityDescription) {
     const remCom = communityDescription.textContent.match(/(!.*@.*)/)[1];

      // Create the remote community link
      const remoteCommunityLink = document.createElement("a");
      remoteCommunityLink.href = `https://${home}/search/q/${encodeURIComponent(remCom)}/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1`
      remoteCommunityLink.textContent = `Search on ${home}`;
      remoteCommunityLink.target = "_blank";

      // Append the link to the community description
      communityDescription.appendChild(document.createElement("br"));
      communityDescription.appendChild(remoteCommunityLink);
  }
}, false);
3

You're viewing a single thread.

3 comments