BR | Mobile Walker (Fixed & Clean)

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

})();