Improving your web experience with userscripts and LLMs

8 Feb 2026

The problem at hand

While surfing the web I am often met with websites that I wish had better UX or functionality, but they don’t really warrant a big overhaul or a replacement, just a little fix. Whether it’s the website’s shortcoming or a specific requirement of mine, I’m left with these options:

  1. Sending feedback and receiving no reply, or waiting an eternity.
  2. Joining the company, fixing the problem then leaving.
  3. Browser extensions with specific goals.
  4. Running JavaScript code on my browser:
    1. Copy paste in the console
    2. Bookmarklet scripts
    3. Userscripts

Pasting code in the console is a good first step but you have to save the scripts somewhere. Very manual. Bookmarklets are fine as a basic solution, but you will have to click on the bookmarklet every time you want to run them. I made one to add filtering on my Youtube watch later list and total runtime: ytplstats Userscripts managers have the most features: auto run scripts on specific web pages, UI to handle multiple scripts, easy export/import…

I used Tampermonkey as my usercripts manager. For the scripts themselves you can start by looking at the many shared userscripts on Greasy Fork, Tamper Monkey or this Awesome List. There are also some useful dev bookmarklets here: 1, 2, 3, 4

As a reminder, it is important to review the code you are using, you can easily copy something obscure, especially with long scripts, that can have suboptimal or malicious intent. Some directories even mark the userscripts as having “Antifeatures”, like injecting referral links.

Printing scripts with LLMs

LLMs opened the door for the possibility of making many personal userscript, even for the smallest of itches we encounter that we wouldn’t have bothered with or found the time to get around to. LLMs happen to be a good fit here: small scripts, easily reviewed and tested, web oriented. It is still paramount to review the code, data can be leaked by omission, hallucination or by way of embedded flawed designs the models might have learned from us. This also serves as a practical alternative to reviewing multi-feature code when you’re only planning to use a subset of its functionality, dealing with LLMs ends up being much faster.

Making the web feel like home

Canada computers

On canadacomputers.com, you can filter availability by a specific store location. If you live close to multiple stores you can’t filter by city or region, you will have to refresh the search for each location. Moreover, the listings are littered with unavailable products “Online - Sold out. In Store Sold out”, I don’t like the clutter, but maybe useful to compare prices on the fly. And sometimes the filters miss products that are actually available. In the end, the simplest solution I thought of is to gray out the unavailable products and check manually for store availability for each product

CanadaComputers listings with multiple products unavailble for order

I analyzed the listings’ HTML myself, thought about the solution and wrote this prompt:

# duck.ai gpt-5 mini
> make a browser userscript that:
> - works on www.canadacomputers.com
> - gray out products that are not available
>
>
>
> here is how to detect products that are not available at all:
> - select and loop over `div.product`, these are the listings
> - each product has availability in the attributes of a subelement `div.available-tag`
> - check the attributes which can be of 3 things, empty, 0, 1.
> - there is 3 attributres: data-available_for_order, data-stock_availability_online, data-stock_availability_retail
> - if data-available_for_order is empty or 0, gray out the div.product
> - another case is if both data-stock_availability_online and data-stock_availability_retail are empty or 0, also gray out div.product

Good result: works as intended, had to correct 4 lines, uses Mutation Observer for scroll loading.

CanadaComputers listings with the userscript applied, now they are completely grayed out, easier to skip over
// ==UserScript==
// @name         CanadaComputers: Gray out unavailable products
// @namespace    https://www.canadacomputers.com/
// @version      1.0
// @description  Gray out product tiles on www.canadacomputers.com when product is not available according to available-tag attributes.
// @match        https://www.canadacomputers.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

/*
Behavior:
- Loops over `div.product` tiles.
- Reads attributes on child `div.available-tag`:
    data-available_for_order
    data-stock_availability_online
    data-stock_availability_retail
- Grays out (applies reduced opacity and pointer-events: none) a product when:
    * data-available_for_order is "" (empty string) or "0", OR
    * both data-stock_availability_online and data-stock_availability_retail are "" or "0"
- Runs once on load and again when the page changes (mutation observer) to handle dynamically loaded content.
*/

(function () {
  "use strict";

  const UNAVAILABLE_CLASS = "cc-unavailable-grayed";

  // CSS for grayed-out products
  const style = document.createElement("style");
  style.textContent = `
    .${UNAVAILABLE_CLASS} {
      opacity: 0.45 !important;
      filter: grayscale(80%) !important;
    }
  `;
  document.head.appendChild(style);

  function isEmptyOrZero(val) {
    // treat null/undefined, empty string, "0", 0 as empty/unavailable
    return val === null || val === undefined || val === "" || String(val) === "0";
  }

  function evaluateProduct(productEl) {
    if (!productEl || !(productEl instanceof HTMLElement)) return;

    // find child available-tag element
    const avail = productEl.querySelector("div.available-tag");
    if (!avail) {
      // If no available-tag, do nothing (assume available)
      productEl.classList.remove(UNAVAILABLE_CLASS);
      return;
    }

    const afo = avail.getAttribute("data-available_for_order");
    const online = avail.getAttribute("data-stock_availability_online");
    const retail = avail.getAttribute("data-stock_availability_retail");

    const unavailableByAfo = isEmptyOrZero(afo);
    const unavailableByBothStock = isEmptyOrZero(online) && isEmptyOrZero(retail);

    if (unavailableByAfo || unavailableByBothStock) {
      productEl.classList.add(UNAVAILABLE_CLASS);
    }

    //      else {
    //      productEl.classList.remove(UNAVAILABLE_CLASS);
    //    }
  }

  function scanAllProducts(root = document) {
    const products = root.querySelectorAll("div.product");
    products.forEach(evaluateProduct);
  }

  // initial scan
  scanAllProducts();

  // observe changes (pages that lazy-load or modify product list)
  const observer = new MutationObserver((mutations) => {
    let recheckRoots = new Set();
    for (const m of mutations) {
      if (m.type === "childList") {
        // if new nodes added, check them (and their descendants)
        m.addedNodes.forEach((node) => {
          if (node.nodeType === Node.ELEMENT_NODE) recheckRoots.add(node);
        });
      } else if (m.type === "attributes") {
        // attribute changes on available-tag or product -> re-evaluate closest product
        const target = m.target;
        if (target instanceof HTMLElement) {
          const product = target.closest && target.closest("div.product");
          if (product) recheckRoots.add(product);
        }
      }
    }

    if (recheckRoots.size === 0) return;

    recheckRoots.forEach((root) => {
      // if root is a product, evaluate single product, else scan for products under root
      if (root.matches && root.matches("div.product")) {
        evaluateProduct(root);
      } else {
        scanAllProducts(root);
      }
    });
  });

  observer.observe(document.body, {
    childList: true,
    subtree: true,
    attributes: true,
    attributeFilter: [
      // monitor attributes used for availability if present on elements
      "data-available_for_order",
      "data-stock_availability_online",
      "data-stock_availability_retail",
    ],
  });

  // Optional: periodically re-scan as a fallback for SPA navigations
  //  setInterval(() => scanAllProducts(), 5000);
})();

Youtube: highlight time since video was posted

Same thing here, had to do some edits, but it works: highlights time since posted with green for less than a day, orange for 1 days ago, red for 2+ days ago. Useful to me when scanning my subscription feed or checking the Home page.

Youtube list of videos with highlighted time since posting
// ==UserScript==
// @name         YouTube: Highlight Time Since Posted (adaptive)
// @namespace
// @version      0.3
// @description  <1d green, 1-2d orange, >=2d red on home and subscription feed
// @author
// @match        https://www.youtube.com/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(() => {
  "use strict";

  const STYLE_ID = "yt-time-highlight-style-v3";
  const DONE_ATTR = "data-ytTimeBoxDone_v3";

  function addStyles() {
    if (document.getElementById(STYLE_ID)) return;
    const s = document.createElement("style");
    s.id = STYLE_ID;
    s.textContent = `
      .yt-time-box{
        display:inline-block;
        padding:4px 8px;
        border-radius:10px;
        font-size:11px;
        line-height:1;
        color:#fff;
        margin-left:6px;
        transform: translateY(-1px);
        white-space: nowrap;
      }
      .yt-time-box.recent{background:#1aa15a;}
      .yt-time-box.one-day{background:#ff9f1c;}
      .yt-time-box.twoplus{background:#d64545;}
    `;
    document.head.appendChild(s);
  }

  function unitToDays(v, unit) {
    switch (unit) {
      case "second":
        return v / 86400;
      case "minute":
        return v / 1440;
      case "hour":
        return v / 24;
      case "day":
        return v;
      case "week":
        return v * 7;
      case "month":
        return v * 30;
      case "year":
        return v * 365;
      default:
        return Infinity;
    }
  }

  // Supports: "1h ago", "2d ago", "5mo ago", "2 hours ago", etc.
  function parseAgeDays(text) {
    if (!text) return Infinity;
    const t = text.trim().toLowerCase();

    // Shorthand: 1h ago, 2d ago, 5mo ago, 3w ago, 10m ago (minutes), 30s ago
    let m = t.match(/(\d+(?:[.,]\d+)?)\s*(s|sec|m|min|h|d|w|mo|y)\s*ago\b/);
    if (m) {
      const v = parseFloat(m[1].replace(",", ""));
      const u = m[2];
      switch (u) {
        case "s":
        case "sec":
          return unitToDays(v, "second");
        case "m":
        case "min":
          return unitToDays(v, "minute");
        case "h":
          return unitToDays(v, "hour");
        case "d":
          return unitToDays(v, "day");
        case "w":
          return unitToDays(v, "week");
        case "mo":
          return unitToDays(v, "month");
        case "y":
          return unitToDays(v, "year");
      }
    }

    // Long form: 2 hours ago, 1 day ago, 3 weeks ago, etc.
    m = t.match(/(\d+(?:[.,]\d+)?)\s*(second|minute|hour|day|week|month|year)s?\s*ago\b/);
    if (m) return unitToDays(parseFloat(m[1].replace(",", "")), m[2]);

    // If it’s exactly like "2mo ago" it should match above; otherwise fail
    return Infinity;
  }

  function classify(days) {
    if (days < 1) return "recent";
    if (days < 2) return "one-day";
    return "twoplus";
  }

  function getTextLikeTime(el) {
    const aria = el.getAttribute && el.getAttribute("aria-label");
    const text = aria && aria.trim() ? aria : (el.textContent || "").trim();
    if (!text) return "";
    return text;
  }

  function looksLikeTimeSincePosted(text) {
    const t = (text || "").trim().toLowerCase();
    if (!t.includes("ago")) return false;

    // Must match either shorthand or long form.
    const shorthand = /(\b\d+(?:[.,]\d+)?\s*(s|sec|m|min|h|d|w|mo|y)\s*ago\b)/i;
    const longhand = /(\b\d+(?:[.,]\d+)?\s*(second|minute|hour|day|week|month|year)s?\s*ago\b)/i;

    if (!shorthand.test(t) && !longhand.test(t)) return false;

    // Reduce false positives like "50:45" etc.
    if (/^\s*\d{1,2}:\d{2}\s*$/.test(t)) return false;

    return true;
  }

  // Replace the element’s text with a styled chip that keeps layout stable.
  function highlightElement(el) {
    if (!el || el[DONE_ATTR] === "1") return;

    const rawText = el.textContent.trim().toLowerCase();

    const days = parseAgeDays(rawText);
    if (!isFinite(days)) return;

    const chip = document.createElement("span");
    chip.className = "yt-time-box " + classify(days);
    chip.textContent = rawText;

    // Replace the element’s content with the chip while keeping the element for selectors/selection.
    el.textContent = "";
    el.appendChild(chip);

    el[DONE_ATTR] = "1";
  }

  function candidatesIn(root) {
    // Focus on metadata text spans that are most likely to be the time label.
    return root.querySelectorAll("span[aria-label], span.ytContentMetadataViewModelMetadataText");
  }

  function process(root = document) {
    for (const el of candidatesIn(root)) {
      try {
        // Skip if already processed (directly on the element we might replace)
        if (el[DONE_ATTR] === "1") continue;
        const txt = getTextLikeTime(el);
        if (looksLikeTimeSincePosted(txt)) highlightElement(el);
      } catch (_) {}
    }
  }

  function startObserver() {
    const root =
      document.querySelector(
        "ytd-two-column-browse-results-renderer, ytd-rich-grid-renderer, #contents, ytd-page-manager",
      ) || document.body;

    let scheduled = false;
    const obs = new MutationObserver(() => {
      if (scheduled) return;
      scheduled = true;
      setTimeout(() => {
        scheduled = false;
        process(root);
      }, 150);
    });

    obs.observe(root, { childList: true, subtree: true });
  }

  addStyles();
  process(document);
  setTimeout(() => process(document), 800);
  startObserver();
})();

Hacker news quick score

I guess everybody scans the posts and process mentally the ratio of points/time/comments, if it’s high and got 900 points Apple probably just launched something, 1800 comments some new controversial law passed that erodes privacy or some part of the internet broke… So I made a visual for that. Not going to lie, this is the most vibed one, I don’t even know if it’s really useful to me, I didn’t check the algorithm and I have no idea if these scores make sense but they seem fine, that’s as far as I want to go for now.

Hackernews homepage with usescript applying a compound score to each post
# duck.ai OSS GPT 120B
what\'s a good mathematical algorithm, that would do a score like ELO i guess, for a list of tuples: time since posted + score + number of comments + position (first being best).

extra considerations:
score is the leading factor, maybe give it a bit of oomph weight wise.
fresh post with no reaction obviously low, but fresh with lots of comments would be interesting
I think position would be leading, because it already considers score+time, a score of 30 but posted 5min ago is much better than 100 but posted 8hours ago


----

now make a userscript to use that on hacker news ( news.ycombinator.com/ ) posts

here is an excerpt of the HTML so you can find the correct times, position, comment number, points:

[A blob of hackernews\' post list HTML]


# second prompt
good work, now for the numbers you added, add a background color, and match the color with the scores like from barely visibile to strong color

Algorithm idea – a weighted “fresh‑ELO” score

For each post we combine four factors:

factor Symbol Typical range Desired influence
Score (up‑votes) s 0 – ∞ strong (base rating)
Age (seconds since posting) t 0 – ≈ 86 400 (1 day) decay – newer → higher
Comments c 0 – ∞ boost “discussion”
Rank (position on page) p 1 – 30 (typical front page) very strong (already reflects s + t)

The final ranking value R can be computed as

R=wp ⁣(1p)  +  ws ⁣(ss+Ks)  +  wc ⁣(cc+Kc)  −  wt ⁣(tt+Kt)R=wp​(p1​)+ws​(s+Ks​s​)+wc​(c+Kc​c​)−wt​(t+Kt​t​)

  • 1/p makes the top‑ranked item get the biggest contribution; lower ranks get rapidly smaller values.
  • The logistic‑like terms x/(x+K) keep each factor bounded (0 → 1) and smooth out extreme outliers.
  • The age term is subtracted because a larger t (older post) should lower the score.

Typical weight choices (tweakable in the script)

weight default effect
wₚ 4 makes the current position the dominant term
wₛ 2 gives points strong but not overwhelming influence
w_c 1.5 rewards many comments, especially on fresh posts
w_t 1 modest decay for age
Kₛ 30 smooths the score curve (≈30 points → 0.5 contribution)
K_c 20 similar smoothing for comments
K_t 3 600 1 hour half‑life for the age decay

The resulting R is a single number; higher values mean “more interesting now”. You can re‑rank the page by sorting posts descending on R.


Userscript for Hacker News

Below is a self‑contained Tampermonkey/Greasemonkey script that:

  1. Parses each item’s score, comment count, age, and displayed rank.
  2. Converts the age string (e.g., “3 hours ago”) into seconds.
  3. Computes R using the formula above (weights are exposed as a settings object).
  4. Inserts a new column “Fresh‑ELO” showing the computed value (rounded).
  5. Optionally re‑orders the table by this value (uncomment the call to reorderRows()).
// ==UserScript==
// @name        Hacker News Fresh‑ELO ranking (coloured)
// @namespace   https://duckduckgo.com/
// @version     1.1
// @description Adds a weighted score with a background colour that reflects its magnitude.
// @match       https://news.ycombinator.com/*
// @grant       none
// @run-at      document-end
// ==/UserScript==

(() => {
  // ------------------- configuration -------------------
  const cfg = {
    wPos: 4, // position weight
    wScore: 2, // up‑vote weight
    wComm: 1.5, // comment weight
    wAge: 1, // age decay weight
    kScore: 30, // smoothing for score
    kComm: 20, // smoothing for comments
    kAge: 3600, // smoothing for age (seconds)

    // colour range: from light gray (low) to strong orange (high)
    minColor: [240, 240, 240], // RGB for barely visible
    maxColor: [255, 165, 0], // RGB for strong colour (orange)
  };

  // ------------------- helpers -------------------
  // Convert “3 hours ago” → seconds
  const parseAge = (txt) => {
    const m = txt.match(/(\d+)\s+(second|minute|hour|day)s?\s+ago/);
    if (!m) return 0;
    const val = +m[1];
    const mul = { second: 1, minute: 60, hour: 3600, day: 86400 }[m[2]];
    return val * mul;
  };

  // Compute the Fresh‑ELO rating
  const computeR = (pos, score, comm, ageSec) => {
    const posTerm = cfg.wPos * (1 / pos);
    const scoreTerm = cfg.wScore * (score / (score + cfg.kScore));
    const commTerm = cfg.wComm * (comm / (comm + cfg.kComm));
    const ageTerm = cfg.wAge * (ageSec / (ageSec + cfg.kAge));
    return posTerm + scoreTerm + commTerm - ageTerm;
  };

  // Interpolate between two RGB colours
  const lerpColor = (t) => {
    const r = Math.round(cfg.minColor[0] + t * (cfg.maxColor[0] - cfg.minColor[0]));
    const g = Math.round(cfg.minColor[1] + t * (cfg.maxColor[1] - cfg.minColor[1]));
    const b = Math.round(cfg.minColor[2] + t * (cfg.maxColor[2] - cfg.minColor[2]));
    return `rgb(${r},${g},${b})`;
  };

  // ------------------- main -------------------
  const rows = document.querySelectorAll("tr.athing");
  const results = [];

  rows.forEach((row) => {
    const pos = parseInt(row.querySelector(".rank")?.textContent, 10);
    if (isNaN(pos)) return;

    const sub = row.nextElementSibling?.querySelector(".subtext");
    if (!sub) return;

    const score = parseInt(sub.querySelector(".score")?.textContent) || 0;
    const comm = parseInt(sub.textContent.match(/(\d+)\s+comment/)?.[1]) || 0;
    const ageSec = parseAge(sub.querySelector(".age")?.textContent.trim() || "");

    const R = computeR(pos, score, comm, ageSec);
    results.push({ row, R });
  });

  // add header for the new column
  const header = document.querySelector("tr:nth-child(1) th.title");
  if (header) {
    const th = document.createElement("th");
    th.textContent = "Fresh‑ELO";
    th.style.textAlign = "right";
    header.parentNode.appendChild(th);
  }

  // determine min/max R to scale colours
  const Rvalues = results.map((r) => r.R);
  const Rmin = Math.min(...Rvalues);
  const Rmax = Math.max(...Rvalues);
  const range = Rmax - Rmin || 1; // avoid division by zero

  // insert cells with coloured background
  results.forEach(({ row, R }) => {
    const td = document.createElement("td");
    td.style.textAlign = "right";
    td.textContent = R.toFixed(2);

    // normalise R to 0‑1 and pick colour
    const t = (R - Rmin) / range; // 0 = low, 1 = high
    td.style.backgroundColor = lerpColor(t);
    td.style.transition = "background-color 0.2s";
    row.appendChild(td);
  });

  // ----- optional: re‑order by Fresh‑ELO (highest first) -----
  const reorderRows = () => {
    const tbody = document.querySelector("tbody");
    const sorted = [...results].sort((a, b) => b.R - a.R);
    sorted.forEach((it) => tbody.appendChild(it.row));
  };
  // Uncomment to enable automatic re‑ordering:
  // reorderRows();
})();

Conclusion

Userscripts have been with us for decades now, the ever increasing complexity of the web and the search for personalization drives us towards ever more customization, LLMs give us some horsepower to even the odds.

Updated on 20260703: added youtube and hackernews example screenshot.