SpamCop Captcha Fix

Автоматически исправляет баг с неработающей капчей на сайте SpamCop.net

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         SpamCop Captcha Fix
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Автоматически исправляет баг с неработающей капчей на сайте SpamCop.net
// @author       toch
// @match        *://*.spamcop.net/*
// @match        *://spamcop.net/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=spamcop.net
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // Проверяем, есть ли на текущей странице элементы капчи
    const captchaImg = document.getElementById("captcha_img");
    const tokenInput = document.getElementById("token");
    const oldBtn = document.getElementById("getcaptcha-button");

    // Если элементов нет, значит это другая страница SpamCop, завершаем работу
    if (!captchaImg || !tokenInput || !oldBtn) {
        return; 
    }

    function loadFixedCaptcha() {
        const xhr = new XMLHttpRequest();
        xhr.open('GET', '/mcgi?action=captcha');
        
        // Исправленные заголовки без бага с датой
        xhr.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        xhr.setRequestHeader("Last-Modified", new Date(0).toUTCString());
        xhr.setRequestHeader("If-Modified-Since", new Date(0).toUTCString());
        xhr.responseType = 'json';
        
        xhr.onload = function() {
            if (xhr.response && xhr.response.image) {
                document.getElementById("captcha_img").src = xhr.response.image;
                document.getElementById("token").value = xhr.response.token;
                
                const currentBtn = document.getElementById("getcaptcha-button");
                if (currentBtn) {
                    currentBtn.disabled = false;
                    currentBtn.style.opacity = "1";
                    currentBtn.style.cursor = "pointer";
                }
                console.log("[SpamCop Fix] Капча успешно загружена!");
            } else {
                console.error("[SpamCop Fix] Ошибка получения капчи", xhr.response);
            }
        };
        xhr.send();
    }

    // Запускаем первую загрузку
    loadFixedCaptcha();

    // Пересоздаем кнопку обновления, чтобы отключить сломанный скрипт самого сайта
    const newBtn = oldBtn.cloneNode(true);
    oldBtn.parentNode.replaceChild(newBtn, oldBtn);

    // Вешаем свой исправленный обработчик клика по кнопке
    newBtn.onclick = function(e) {
        e.preventDefault();
        document.getElementById("captcha_img").src = "images/indicator.gif";
        loadFixedCaptcha();
    };

})();