Remove ?tl= from Reddit links on Google

Removes the ?tl= parameter from Reddit search result links on Google

// ==UserScript==
// @name         Remove ?tl= from Reddit links on Google
// @namespace    https://github.com/Mythos
// @version      1.1
// @description  Removes the ?tl= parameter from Reddit search result links on Google
// @author       Mythos
// @license      MIT
// @match        https://www.google.com/search*
// @match        https://www.google.*/*
// @grant        none
// @run-at       document-end
// @homepageURL  https://github.com/Mythos/userscripts
// @supportURL   https://github.com/Mythos/userscripts/issues
// ==/UserScript==

(function () {
    'use strict';
    const parameterName = 'tl';
    function cleanLinks() {
        document.querySelectorAll('a[href*="reddit.com"]').forEach(a => {
            try {
                let url = new URL(a.href);
                if (url.searchParams.has(parameterName)) {
                    url.searchParams.delete(parameterName);
                    a.href = url.toString();
                }
            } catch (e) {
            }
        });
    }

    cleanLinks();

    // Observe dynamically loaded search results
    const observer = new MutationObserver(cleanLinks);
    observer.observe(document.body, { childList: true, subtree: true });
})();