Another way to view your favorited observations in the explore page

Note: I have made this to work in firefox, someone else can modify it to work in other browsers

When on iNat, open the browser console and enter this (insert your username where it says your username here):

async function getFavesBatch(userId, page = 1) {
  const response = await fetch(`https://www.inaturalist.org/faves/${userId}?page=${page}`);
  const text = await response.text();
  const parser = new DOMParser();
  const doc = parser.parseFromString(text, 'text/html');

  const observations = doc.getElementsByClassName('observation');
  const list = [];
  for (let obs of observations) {
    list.push(obs.id.replace('observation-', ''));
  }

  const navigationChildren = doc.querySelector('[role=navigation]')?.children;
  const maxBatch = navigationChildren ? parseInt(navigationChildren[navigationChildren.length - 2].innerText, 10) : 1;

  if (page === 1) {
    console.log(`Total pages: ${maxBatch}`);
  }

  return { obsList: list, maxPage: maxBatch };
}

async function fetchAllFavorites(userId) {
  let obsList = [];
  let maxPage = 1;

  for (let i = 1; i <= maxPage; i++) {
    const batchData = await getFavesBatch(userId, i);
    obsList.push(...batchData.obsList);
    maxPage = batchData.maxPage;
    console.log(`Extracted page ${i}`);
  }

  console.log(obsList.join(','));
}

// Call the function with the specific user ID
fetchAllFavorites('your username here');

This will return back a list of observation id’s
Copy that list and paste it in front of https://www.inaturalist.org/observations?id=

did this not already work in Firefox and other browsers?

1 Like

oh I did not even see that exists

convergent evolution

the code is too similar to be just convergent evolution. if you didn’t see the previous code, then i assume you started with code that came from some sort of coding AI, and i assume that that AI “learned” from that previous code.

by the way…

because folks sometimes fave casual observations and since some folks have default place filters, you should generally include verifiable=any&place_id=any in the fitler parameters.

2 Likes