Hey all,

Here is a amateur script that will add a “easy subscribe” button to the community subscription box that will automatically link you back to you home instance’s search page, ready to click into the sub from your instance and subscribe. It should make your adding remote communities “slightly” easier than the manual method. You will need a Javascript Injector addon for your browser. I am using “JS Injector” for firefox. Make sure to get an addon that supports allowing the script to run on all sites. This will only add the button on the communities main page (/c/ in the url). Make sure to change the homeInstance var to your home lemmy instance where your account is. Feel free to use, copy and make it better (and less amateur!).

You will have to refresh the community page once before the button appears. Something to do with the javascript injector addons not being able to run when lemmy’s “client.js” script runs forever (live updater script I beleive). However, once your on a /c/ and refresh once that script doesn’t run. UPDATE: FIXED!

Remote Community:

Enjoy, I hope it is of use. Remember never run a script that you don’t understand.


// Easier Subscribe Script 
/* EDIT YOUR HOME INSTANCE */
var homeInstance = "https://thesimplecorner.org";
/* ---------------------- */
/* Script */
var url = window.location.href;
var currentPage = url;
var broken = url.split('/c/');
var site = broken[0];
site = site.replace('https://', '');
var community = broken[1];
var subString = homeInstance + "/search/q/!" + community + "@" + site + "/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1";

function update(comm, page) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      console.log("updating html xhr");
      document.querySelectorAll('[role="alert"]').forEach(function(el) {
        el.innerHTML += "<br /><br /><a href=" + subString + " target='_blank'><button>Easy Subscribe</button></a>";
      });
    }
  }
  xhttp.open("GET", this, true);
  xhttp.send(page);
}
//Browsing remote instance
setInterval(function() {
  url = window.location.href;
  if (currentPage != location.href) {
    broken = url.split('/c/');
    site = broken[0];
    site = site.replace('https://', '');
    community = broken[1];
    subString = homeInstance + "/search/q/!" + community + "@" + site + "/type/All/sort/TopAll/listing_type/All/community_id/0/creator_id/0/page/1";
    // page has changed, set new page as 'current'
    console.log("Easy Sub Running...");
    if (document.querySelector('meta[name="Description"]').content.includes("Lemmy")) {
      console.log("On lemmy");
      if ((url.includes(homeInstance) == false) && (url.includes("/c/"))) {
        console.log("On remote instance community");
        update(community, url);
      }
    }
    currentPage = location.href;
  }
}, 500);
// Direct to community
if (document.querySelector('meta[name="Description"]').content.includes("Lemmy")) {
  console.log("On lemmy");
  if ((url.includes(homeInstance) == false) && (url.includes("/c/"))) {
    console.log("On remote instance community");
    update(community, url);
  }
}

  • fcuks@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    1 year ago

    Nice work dude! I forked and tweaked and put together a Firefox and Chrome addon which does something similar with adding icons. You can see from the screenshots on the readme. It’s pending being accepted in the stores but you can build it and load it manually for now if you want.

    Do you want to work together on something like this and see if we can add some cool features?

    https://github.com/FackJox/lemmy-link

    • Rick@thesimplecorner.orgOP
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      I’ve never done typescript before but I am interested. I was actually looking into making an addon… I’ll pull your repo and play around but it’s gonna be a learning curve. My javascript method get’s hung up because the lemmy client.js script (the updater I believe). Always runs until you refresh once on a community page.