this post was submitted on 12 Jun 2023
14 points (100.0% liked)

Lemmy

13486 readers
3 users here now

Everything about Lemmy; bugs, gripes, praises, and advocacy.

For discussion about the lemmy.ml instance, go to !meta@lemmy.ml.

founded 5 years ago
MODERATORS
 

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 that 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. 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. If you find a bug or make it better... please fix it and update us. I never code in javascript... so this was all stack overflow searches.

For whatever reason, often I 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 until everything is loaded perhaps?

Remote Community:

"Easy Button Click - Takes you back to your homepage ready to click back and subscribe from your home instance".

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

 window.onload = function() {
  var homeInstance = "https://yourhomelemmy.ml"
  var url = window.location.href;
  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";
  if (document.querySelector('meta[name="Description"]').content.includes("Lemmy")) {
    if ((url.includes(homeInstance) == false) && (url.includes("/c/"))) {
      document.querySelectorAll('[role="alert"]').forEach(function(el) {
        el.innerHTML += "<br /><br /><a href=" + subString + " target='_blank'><button>Easy Subscribe</button></a>";
      });
    }
  }
}
you are viewing a single comment's thread
view the rest of the comments
[–] fcuks@lemmy.world 1 points 2 years ago

We're all learning dude :D I just played around with the fork, broke it, reverted it, played around again etc. until it worked nicely to be honest.