Automatically Refresh Twitch Stream Page Upon Keyword Detection with Alerts

Hi everyone, I need some assistance with a script for Twitch!

I’m looking to build a browser script that checks Twitch channel pages for specific keywords and performs actions based on that.

Here’s what I need it to do:

  • Refresh the page every 15 seconds while monitoring for certain words.
  • Specifically, I want to detect words like “LIVE” and the error code “5000”.
  • If either of these terms appear, I want the page to reload automatically and alert me beforehand.
  • It should function across multiple tabs at once.

Why I need this: I often have various Twitch streams running in different tabs, and they sometimes return an error stating that the video is not available. By setting up this script, I can be notified and refreshed automatically when the streams come back online.

Example scenario: I visit a Twitch channel and it’s offline. Once I enable the script and set it to check for the terms “LIVE” and “5000”, it needs to query every 15 seconds in the background for those words. When the streamer goes live, the script should refresh the page and notify me, stopping further checks afterward.

Here’s my current approach using a JavaScript template:

(function() {
    'use strict';
    
    $(document).ready(function() {
        var keyword = "LIVE"; // You can change this to look for different terms.
        
        if($('body:contains("' + keyword + '")').length > 0) {
            alert("Detected: " + keyword);
        } else {
            location.reload();
        }
    });
})();

I’m having issues making it work correctly with more features like multiple keyword handling and proper notifications. If anyone has suggestions or solutions, I’d really appreciate your insights. The script doesn’t need to be tied to Tampermonkey specifically.

Thanks a bunch!

The main problem is you’re using jQuery, but Twitch pages don’t have it by default. I ran into this same issue building my own stream monitors. Don’t check the entire body text - target Twitch’s specific DOM elements instead. The video player uses consistent class names that change when streams go offline. Use vanilla JavaScript with querySelector to grab elements like the offline banner or player error messages. For timing, wrap everything in setInterval instead of running it immediately. Add a flag variable so you don’t get spammed with multiple alerts. Check for your keywords first, then decide whether to keep monitoring or stop. Error 5000 shows up in an error overlay div, not as regular text. Use textContent instead of the contains selector - it’s way more reliable with dynamic content. Also, add a small delay before reloading so users actually see the alert.

Your script’s stuck in an endless reload loop because of a logic problem. You’re checking for “LIVE” but reloading when it’s NOT found - so offline streams just refresh forever. I’ve worked on similar monitoring setups before. Skip the constant page reloads and use MutationObserver with setInterval instead. Way better to watch DOM changes than refresh the whole page every time. For Twitch, target the player container or stream status elements directly instead of scanning the entire body. These sections update automatically when streams go live or hit errors, so they’re much more reliable to monitor. That “5000” error shows up in the player when there’s connection issues. Set your script to catch both error and live states, then only refresh when going from error to live. The multi-tab thing should work fine - each tab runs its own instance with userscripts. Just add proper cleanup so your intervals don’t cause memory leaks.

I’ve been running something like this for months. Move your setInterval outside the document ready function - Twitch loads everything dynamically, so DOM ready fires way before the actual content loads. Check for ‘.live-indicator’ or ‘[data-a-target=“player-overlay-play-button”]’ instead of text content. That 15-second refresh will get you rate limited fast. Bump it to at least 30-45 seconds or Twitch will start blocking your requests.