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

sh.itjust.works Main Community

7584 readers
4 users here now

Home of the sh.itjust.works instance.

Matrix

founded 1 year ago
MODERATORS
 

I made a little thing to more easily move to another instance:

A way to quickly grab a list of your subscribed communities.

Go to your list of subscribed communities, /communities/listing_type/Subscribed/page/1 and create a bookmark with the following code as link:

code

javascript:(function() {
    const currentHostname = window.location.hostname;
    const table = document.getElementById('community_table');
    const anchorTags = table.getElementsByTagName('a');
    const communityUrls = [];

    for (let i = 0; i < anchorTags.length; i++) {
      const title = anchorTags[i].title.substring(1);
      const parts = title.split('@');
      const community = parts[0].trim();
      const domain = parts[1] ? parts[1].trim() : currentHostname;
      const communityUrl = `https://${domain}/c/${community}`;
      communityUrls.push(communityUrl);
    }

    const urlsText = communityUrls.join('\n');

    navigator.clipboard.writeText(urlsText)
      .then(() => {
        alert('Community URLs copied to clipboard!');
      })
      .catch((error) => {
        alert('Failed to copy Community URLs to clipboard:', error);
      });
})();
Clicking this bookmark will automatically copy a list of all your subscribed communities and format the links so that you can pop them in the search bar of another instance to subscribe to them from another account. It can only scrape what's on screen, so if your subscribed communities list is several pages long just click the bookmark for each page.
top 12 comments
sorted by: hot top controversial new old
[–] Gamera8ID@lemmy.world 5 points 1 year ago (1 children)

I made a slight modification to your bookmarklet asking to which instance you are migrating, which produces a list of links you can paste into something like https://www.openallurls.com so it becomes just a matter of clicking all of the "Subscribe" buttons:

javascript:(function() {
  const currentHostname = window.location.hostname;
  const tld = prompt("Please enter the name of the instance to which you are migrating:");
  const table = document.getElementById('community_table');
  const anchorTags = table.getElementsByTagName('a');
  const communityUrls = [];

  for (let i = 0; i < anchorTags.length; i++) {
    const title = anchorTags[i].title.substring(1);
    const parts = title.split('@');
    const community = parts[0].trim();
    const domain = parts[1] ? parts[1].trim() : currentHostname;
    const communityUrl = `https://${tld}/c/${community}@${domain}`;
    communityUrls.push(communityUrl);
  }

  const urlsText = communityUrls.join('\n');

  navigator.clipboard.writeText(urlsText)
    .then(() => {
      alert('Community URLs copied to clipboard!');
    })
    .catch((error) => {
      alert('Failed to copy Community URLs to clipboard:', error);
    });
})();
[–] 15Redstones@feddit.de 1 points 1 year ago

Does it cause issues if domain and tld match?

[–] administrator@lemmy.pro 4 points 1 year ago* (last edited 1 year ago) (1 children)

Oh wow that’s cool. In case anyone is looking to spread out and take load off of the most popular instances, we made a new instance on a very robust server at Lemmy.pro - registration is open to come try it out :-)

[–] Paneer@burggit.moe 1 points 1 year ago

Great collection of articles!

[–] Barbarian@sh.itjust.works 2 points 1 year ago (1 children)

You're awesome! Gonna save this just in case.

[–] 15Redstones@feddit.de 2 points 1 year ago (1 children)

I don't have a script to automatically subscribe to a list of communities on a new account yet, that's a bit more difficult...

[–] 15Redstones@feddit.de 2 points 1 year ago (1 children)

By the way, this code was 90% written by ChatGPT.

[–] RandomBit@sh.itjust.works 3 points 1 year ago

This is the way!

[–] PriorProject@lemmy.world 1 points 1 year ago (1 children)

You should post this as an end-user workaround in https://github.com/LemmyNet/lemmy/issues/506. LOTS of people are interested in this, and they commonly get redirected to that ticket to watch progress. If there was a workaround that didn't depend on the devs available, lots of semi-technical folks could help themselves before the feature is done. It could maybe even help someone understand how to get started on the ticket to see what API calls are involved.

[–] 15Redstones@feddit.de 2 points 1 year ago

This doesn't really do any API calls, it just scrapes the page in the browser and reformats the links. Bookmark-code is neat for stuff like that. I have another bookmark that disables the "anti-Ctrl+C" protection on another site I use, and one that sets the videos on my university's website to 1.25 speed (they disabled that feature in the video player by making it unclickable, my bookmark makes it clickable again).

[–] Gamera8ID@lemm.ee 1 points 1 year ago

You might also want to check out this Python script which syncs profiles, communities, and blocks between multiple Lemmy accounts.

load more comments
view more: next ›