Redirect with Keyword from Localhost (Via Browser)

Fetch keyword from local server and redirect to Google every 60s with countdown display

اعتبارا من 13-08-2025. شاهد أحدث إصدار.

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 or Violentmonkey 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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         Redirect with Keyword from Localhost (Via Browser)
// @namespace    http://yourdomain.com/
// @version      1.1
// @description  Fetch keyword from local server and redirect to Google every 60s with countdown display
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
  "use strict";

  function getRandomDelay(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }

  const delaySeconds = getRandomDelay(23, 35);
  let countdown = delaySeconds;

  // Show countdown
  const timerBox = document.createElement("div");
  timerBox.style.position = "fixed";
  timerBox.style.bottom = "10px";
  timerBox.style.right = "10px";
  timerBox.style.background = "rgba(0,0,0,0.7)";
  timerBox.style.color = "white";
  timerBox.style.padding = "6px 12px";
  timerBox.style.borderRadius = "8px";
  timerBox.style.fontSize = "16px";
  timerBox.style.zIndex = 9999;
  timerBox.textContent = `Redirect in ${countdown}s`;
  document.body.appendChild(timerBox);

  const countdownInterval = setInterval(() => {
    countdown--;
    timerBox.textContent = `Redirect in ${countdown}s`;

    if (countdown <= 0) {
      clearInterval(countdownInterval);
      fetchAndRedirect();
    }
  }, 1000);

  async function fetchAndRedirect() {
    try {
      // const response = await fetch("http://localhost:3000/keyword");
      const response = await fetch("https://bing-search.onrender.com/keyword");
      if (!response.ok) throw new Error("Fetch failed");

      const data = await response.json();
      if (!data.keyword) throw new Error("Keyword limit reached");
      const keyword = data.keyword;

      if (keyword) {
        const url = `https://www.bing.com/search?q=${encodeURIComponent(
          keyword
        )}&qs=PN&form=TSFLBL`;
        window.top.location.href = url;
      } else {
        timerBox.textContent = "No keyword found";
      }
    } catch (e) {
      timerBox.textContent = "Error: " + e.message;
    }
  }
})();