Greasy Fork is available in English.

LZTRANDOMTHREAD

Открываем случайную тему в разделе

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         LZTRANDOMTHREAD
// @namespace    https://greasyfork.org/ru/users/1142494-llimonix
// @version      0.2
// @description  Открываем случайную тему в разделе
// @author       llimonix
// @match        https://lolz.live/*
// @icon         https://cdn-icons-png.flaticon.com/512/7601/7601730.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function getRandomThreadIds(html) {
        const parser = new DOMParser();
        const doc = parser.parseFromString(html, 'text/html');
        const threadElements = doc.querySelectorAll("[id^='thread-']");

        return Array.from(threadElements).map(el => el.id.match(/\d+/)[0]);
    }

    async function openRandomThread() {
        const forumID = $('form.DiscussionListOptions').attr('action');
        if (!forumID) return;

        const lastPageText = $('.PageNav a:last').text();
        const lastPageNumber = parseInt(lastPageText) || 1;

        const randomPage = Math.floor(Math.random() * lastPageNumber) + 1;

        const url = lastPageNumber > 1 ? `${forumID}page-${randomPage}` : forumID;

        try {
            const data = await XenForo.ajax(url, {});
            const threadIds = getRandomThreadIds(data.templateHtml);

            if (threadIds.length > 0) {
                const randomThreadId = threadIds[Math.floor(Math.random() * threadIds.length)];
                window.location.href = `/threads/${randomThreadId}`;
            }
        } catch (error) {
            console.error('Ошибка загрузки темы:', error);
        }
    }

    function addRandomThreadButton() {
        const buttonAdded = $('.pageNavLinkGroup a.RandomThread')
        if (buttonAdded.lenght === 0) return;

        const targetContainer = $('.pageNavLinkGroup .btn-group');
        if (targetContainer.length === 0) return;

        const button = $('<a class="button RandomThread">Случайная тема</a>');
        button.on('click', openRandomThread);
        targetContainer.prepend(button);
    }

    XenForo.register('.pageNavLinkGroup .btn-group', function() {
        addRandomThreadButton();
    })
})();