SpamCop Captcha Fix

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

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

})();