BR | Mobile Walker (Fixed & Clean)

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

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

})();