BR | Mobile Walker (Fixed & Clean)

Исправленная версия. Заходит в темы, ставит лайк и выходит.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         BR | Mobile Walker (Fixed & Clean)
// @namespace    https://forum.blackrussia.online
// @version      6.1
// @description  Исправленная версия. Заходит в темы, ставит лайк и выходит.
// @author       Gemini & Nuserik
// @match        https://forum.blackrussia.online/whats-new/*
// @match        https://forum.blackrussia.online/threads/*
// @match        https://forum.blackrussia.online/posts/*
// @grant        none
// @run-at       document-idle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // --- НАСТРОЙКИ ---
    const CONFIG = {
        FEED_URL: 'https://forum.blackrussia.online/whats-new/posts/?skip=1',
        DELAY_WAIT: 2000, // Ждать 2 сек перед действием
    };

    const DB_KEY = 'br_walker_history_v6';

    // --- ИНТЕРФЕЙС ---
    function hud(msg) {
        let el = document.getElementById('walker-hud');
        if (!el) {
            el = document.createElement('div');
            el.id = 'walker-hud';
            el.style.cssText = "position:fixed;top:0;left:0;right:0;background:black;color:lime;padding:10px;text-align:center;z-index:9999;font-family:monospace;border-bottom:2px solid lime;";
            document.body.appendChild(el);
        }
        el.innerText = "STATUS: " + msg;
    }

    // --- ИСТОРИЯ (Чтобы не заходить дважды) ---
    function checkHistory(link) {
        let db = JSON.parse(localStorage.getItem(DB_KEY) || '[]');
        return db.includes(link);
    }

    function saveHistory(link) {
        let db = JSON.parse(localStorage.getItem(DB_KEY) || '[]');
        if (!db.includes(link)) {
            db.push(link);
            if (db.length > 200) db.shift();
            localStorage.setItem(DB_KEY, JSON.stringify(db));
        }
    }

    // --- ЛОГИКА РАБОТЫ ---
    function run() {
        const url = window.location.href;

        // 1. ЕСЛИ МЫ В ЛЕНТЕ
        if (url.includes('whats-new')) {
            hud("ИЩУ ТЕМУ...");
            
            let links = document.querySelectorAll('.structItem-title a');
            let target = null;

            for (let i = 0; i < links.length; i++) {
                let href = links[i].href;
                // Убираем лишнее из ссылки
                if (href.indexOf('/unread') > -1) {
                    href = href.split('/unread')[0];
                }
                
                if (!checkHistory(href) && href.includes('threads/')) {
                    target = href;
                    break;
                }
            }

            if (target) {
                hud("ЗАХОЖУ: " + target);
                saveHistory(target);
                setTimeout(function() {
                    window.location.href = target;
                }, 1000);
            } else {
                hud("НЕТ НОВЫХ ТЕМ. ОБНОВЛЕНИЕ...");
                setTimeout(function() {
                    window.location.href = CONFIG.FEED_URL;
                }, 2000);
            }
        } 
        
        // 2. ЕСЛИ МЫ ВНУТРИ ТЕМЫ
        else if (url.includes('threads/') || url.includes('posts/')) {
            hud("Я В ТЕМЕ. ЖДУ...");

            setTimeout(function() {
                let btn = document.querySelector('.reaction:not(.reaction--reacted)');
                
                if (btn) {
                    hud("ЛАЙК!");
                    btn.scrollIntoView({behavior: "smooth", block: "center"});
                    
                    setTimeout(function() {
                        btn.click();
                        // Уходим обратно через 1 сек
                        setTimeout(function() {
                            window.location.href = CONFIG.FEED_URL;
                        }, 1000);
                    }, 500);
                } else {
                    hud("КНОПОК НЕТ. УХОЖУ.");
                    window.location.href = CONFIG.FEED_URL;
                }
            }, CONFIG.DELAY_WAIT);
        }
        
        // 3. ЕСЛИ ЗАБЛУДИЛИСЬ
        else {
            setTimeout(function() {
                if (!url.includes('login')) {
                    window.location.href = CONFIG.FEED_URL;
                }
            }, 3000);
        }
    }

    // ЗАПУСК
    if (document.readyState === 'complete') {
        run();
    } else {
        window.addEventListener('load', run);
    }

})();