SpamCop Captcha Fix

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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

})();