• 0 Posts
  • 1 Comment
Joined 2 years ago
cake
Cake day: June 16th, 2023

help-circle
  • Ich habe dein Script mal erweitert, nun fügt es neben einem hinzufügen Link auch einen öffnen Link hinzu.

    // @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/community@remote.tld"
    // @author       SomeDude
    // @author       NoXPhasma
    // @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 openOn = communityDescription.textContent.match(/!(.*@.*)/)[1];
         const searchOn = communityDescription.textContent.match(/(!.*@.*)/)[1];
    
          // Create the remote community link
          const remoteCommunityLink = document.createElement("a");
          remoteCommunityLink.href = `https://${home}/c/${openOn}`
          remoteCommunityLink.textContent = `Open on ${home}`;
          remoteCommunityLink.target = "_blank";
    
          // Append the link to the community description
          communityDescription.appendChild(document.createElement("br"));
          communityDescription.appendChild(remoteCommunityLink);
    
          const remoteSearchLink = document.createElement("a");
          remoteSearchLink.href = `https://${home}/search/q/${encodeURIComponent(searchOn)}/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1`
          remoteSearchLink.textContent = `Add to ${home}`;
          remoteSearchLink.target = "_blank";
    
          // Append the link to the community description
          communityDescription.appendChild(document.createElement("br"));
          communityDescription.appendChild(remoteSearchLink);
      }
    }, false);