Script for opening unread topics

Hi! :wave:

If you’re like me and like opening unread topics in new tabs when you visit the forum but don’t want to click on each topic manually, I made a JavaScript-snippet that can help do it automatically! :computer:

However, as there seems to be no way to programmatically control whether a link is opened in a new tab or window, this script will replicate what your preferred way of opening links is in your browser settings. You probably want to make sure your browser prefers tabs, as this script will open a maximum of 10 tabs at a time; you can vary this number by changing the MAX_INSTANCES variable. You should be able to verify this by CTRL/CMD-clicking on any link; if the link is opened in a new tab, this script should also open your unread topics in tabs.

You activate this script by pasting it in the developer console of your browser when you’re in a section of the forum that displays unread topics (white links). The developer console can be accessed in various ways, but pressing F12 should work for pretty much all browsers. If the console isn’t displayed by default it can be accessed by selecting the tab named Console or similar.

Paste this script in the console, press Enter, and it should open unread topics. If you want to repeat the action at a later stage, you can press the up arrow in the console to until you find the script and press Enter again, or type openUnreadTopics() if you haven’t closed the tab since you last run the script.

function openUnreadTopics() {
  const MAX_INSTANCES = 10;

  const unreadLinks = Array.from(
    document.querySelectorAll(
      "tr.topic-list-item:not(.visited) a.raw-topic-link"
    )
  );

  if (unreadLinks.length === 0) console.log("No unread topics found!");
  else {
    const excess = unreadLinks.splice(MAX_INSTANCES);

    console.log(
      `Opening ${unreadLinks.length} unread topic${
        unreadLinks.length > 1 ? "s" : ""
      }...`
    );
    unreadLinks.forEach((link) => window.open(link.getAttribute("href")));

    if (excess.length > 0)
      console.log(
        `${excess.length} additional unread topic${
          excess.length > 1 ? "s" : ""
        } currently remaining.`
      );
  }
}
openUnreadTopics();
2 Likes

From one js nerd to another, nice work :+1: :+1:

If I didn’t already have so many tabs open with api endpoints and data results, various stack overflow articles to help me do my job for me etc, I’d do use this script lol I just can’t take any more tabs open though. I can barely read the title in the tabs I’ve got open as it is because I have so many open haha. Maybe this just means I need a bigger monitor…hmmm

Thanks! :+1:
I usually open a new window, navigate to the forum, and the run the script. Then, I cycle through the tabs with the keyboard and read the new posts, and If I find some particularly interesting topic I want to keep open, I move the tab to the far most left. Once I’ve come back to the initial tab, I just close the rest of the opened tabs with Chrome’s Close Tabs to the Right command.

2 Likes