Free Game Alert (Old Reddit)

Highlight posts containing the word "free"

// ==UserScript==
// @name         Free Game Alert (Old Reddit)
// @namespace    http://tampermonkey.net/
// @version      2025-05-04
// @description  Highlight posts containing the word "free"
// @author       SwanKnight
// @match        https://old.reddit.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// @license     GPLv3
// ==/UserScript==

(function() {
    'use strict';

    var elements = document.getElementsByClassName("title");

    // Convert HTMLCollection to an array
    Array.from(elements).forEach(element => {
        const regex = /\bfree\b/i; 
        var str = element.textContent.toLowerCase();
        if (regex.test(str)) {
            var parentDiv = element.closest('div.top-matter');
            if (parentDiv) {
                parentDiv.style.backgroundColor = "lightgreen"; // Change the background color of the parent div
            }
        }
    });
})();