Startpage Auto Retry or Refresh

Automatically clicks "Click here" or refreshes page if no results found on Startpage

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Startpage Auto Retry or Refresh
// @namespace    http://tampermonkey.net/
// @version      1.3
// @description  Automatically clicks "Click here" or refreshes page if no results found on Startpage
// @author       Rishabh
// @match        https://www.startpage.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const observer = new MutationObserver(() => {
        const bodyText = document.body.innerText.toLowerCase();
        if (bodyText.includes("no search results were found for") && bodyText.includes("click here")) {
            const retryElement = document.querySelector('a[href*="do/search?query"]');
            if (retryElement && retryElement.offsetParent !== null) {
                console.log("Auto-clicking 'Click here'...");
                setTimeout(() => {
                    retryElement.click();
                    observer.disconnect();
                }, 1000);
            } else {
                console.warn("Retry element not found or not clickable. Refreshing page...");
                setTimeout(() => {
                    location.reload();
                    observer.disconnect();
                }, 1500);
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();