Limit Google search results to before a certain date

Created: 2025-01-10 15:33:05 | Last updated: 2025-01-10 15:33:17 | Status: Public

Too much AI slop in your searches? This greasy fork will limit returned search results to before a certain date. In this case that date is August 31, 2023.

// ==UserScript==
// @name         Google Search Date Filter
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Limits Google search results to before 2023-08-31
// @author       ill13
// @match        https://www.google.com/search*
// @match        https://google.com/search*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Function to add date filter to URL
    function addDateFilter(url) {
        const searchParams = new URLSearchParams(url.search);

        // Only add if not already present
        if (!searchParams.get('tbs')) {
            searchParams.set('tbs', 'cdr:1,cd_max:8/31/2023');
            url.search = searchParams.toString();
            return url.toString();
        }
        return null;
    }

    // Get current URL
    const currentUrl = new URL(window.location.href);
    const newUrl = addDateFilter(currentUrl);

    // Redirect if URL was modified
    if (newUrl) {
        window.location.href = newUrl;
    }
})();