ISCUT HELPER

Automatically extracts a domain from ISCUT pages and opens a Google site: search after a 3-second countdown.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ISCUT HELPER
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Automatically extracts a domain from ISCUT pages and opens a Google site: search after a 3-second countdown.
// @author       Mrtznx
// @match        https://iscut.eu/i/*
// @grant        GM_openInTab
// ==/UserScript==

(function() {
    'use strict';

    // 1. Find a domain in the page text
    const text = document.body.innerText;
    const match = text.match(/site:\s*((?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})/i);
    if (!match) return;   // nothing found

    const domain = match[1];
    const searchUrl = `https://www.google.com/search?q=site:${encodeURIComponent(domain)}`;

    // 2. Create a small notification box with countdown
    const box = document.createElement('div');
    box.style.cssText = `
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: #222;
        color: #fff;
        padding: 12px 18px;
        border-radius: 8px;
        font-family: sans-serif;
        font-size: 14px;
        z-index: 9999;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        display: flex;
        align-items: center;
        gap: 12px;
        opacity: 0.9;
        border: 1px solid #555;
    `;
    box.innerHTML = `
        <span>🔍 Opening search for <strong>${domain}</strong> in <span id="timerDisplay">3</span>s</span>
        <button id="cancelTimer" style="background:#d32f2f;color:#fff;border:none;padding:4px 10px;border-radius:4px;cursor:pointer;">Cancel</button>
    `;
    document.body.appendChild(box);

    const timerSpan = document.getElementById('timerDisplay');
    const cancelBtn = document.getElementById('cancelTimer');
    let countdown = 3;
    let timerId = null;

    // 3. Countdown logic
    function startCountdown() {
        timerId = setInterval(() => {
            countdown -= 1;
            if (countdown <= 0) {
                clearInterval(timerId);
                box.remove();               // remove notification
                GM_openInTab(searchUrl, { active: false });  // open in background
            } else {
                timerSpan.textContent = countdown;
            }
        }, 1000);
    }

    // 4. Cancel button: clear timer and remove box
    cancelBtn.addEventListener('click', () => {
        clearInterval(timerId);
        box.remove();
    });

    // 5. Start the timer
    startCountdown();
})();