SpamCop Captcha Fix

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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();
    };

})();