script_by_Knyaz

Suggestions for improving the script write here ---> https://vk.com/mr_khvan

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

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

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==UserScript==
// @name   script_by_Knyaz
// @name:ru Answers
// @description  Suggestions for improving the script write here ---> https://vk.com/mr_khvan
// @description:ru Предложения по улучшению скрипта и информацию о багах писать сюда ---> https://vk.com/mr_khvan
// @version 1.9
// @namespace https://forum.blackrussia.online
// @match        https://forum.blackrussia.online/threads/*
// @include      https://forum.blackrussia.online/threads/
// @grant        none
// @license   MIT
// @supportURL https://vk.com/id723242613 | K. Darkness | VOLOGDA
// @icon https://emoji.gg/assets/emoji/9372-blurple-boost-level-9.png
// @require https://code.jquery.com/jquery-3.6.0.min.js
// ==/UserScript==

(function () {
    'use strict';
    const UNACCСEPT_PREFIX = 4;
    const ACCСEPT_PREFIX = 8;
    const RESHENO_PREFIX = 6;
    const PINN_PREFIX = 2;
    const GA_PREFIX = 12;
    const COMMAND_PREFIX = 10;
    const WATCHED_PREFIX = 9;
    const CLOSE_PREFIX = 7;
    const SPECY_PREFIX = 11;
    const TEXY_PREFIX = 13;
    const OTKAZBIO_PREFIX = 4;
    const ODOBRENOBIO_PREFIX = 8;
    const NARASSMOTRENIIBIO_PREFIX = 2;
    const OTKAZRP_PREFIX = 4;
    const ODOBRENORP_PREFIX = 8;
    const NARASSMOTRENIIRP_PREFIX = 2;
    const OTKAZORG_PREFIX = 4;
    const ODOBRENOORG_PREFIX = 8;
    const NARASSMOTRENIIORG_PREFIX = 2;

    const buttons = [
        // Раздел Жалобы на администрацию
        {
            title: 'ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ                                ᅠ⠀             ⠀ ⠀⠀ᅠ   👨‍💻 Жалобы на администрацию 👨‍💻    ᅠᅠ ᅠᅠ          ⠀        ⠀    ⠀      ⠀ᅠ     ᅠ ᅠ     ᅠ ᅠ ᅠ ',
            dpstyle: 'oswald: 3px;     color: #fff; background: #212428; box-shadow: 0 0 2px 0 rgba(0,0,0,0.14),0 2px 2px 0 rgba(0,0,0,0.12),0 1px 3px 0 rgba(0,0,0,0.2); border: 1px solid #BF40BF; width: 96%',
        },
        {
            title: 'На рассмотрении',
            content: "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/JzzrkT4p/IMG-7328.png[/img][/url][/CENTER]<br><br>" +
                '[Color=rgb(222, 143, 255)][FONT=Georgia][CENTER][I]{{greeting}}, уважаемый {{user.plainName}}.[/color][/CENTER]<br><br>' +
                "[CENTER][FONT=georgia][I][B]Ваша жалоба взята на рассмотрение, убедительная просьба не создавать идентичных жалоб и ожидать ответа в данной теме.[/FONT][/I][/B][/CENTER]<br><br> " +
                "[CENTER][B][COLOR=rgb(255, 255, 0)][SIZE=4][FONT=times new roman]「На рассмотрении」 [/FONT][/SIZE][/COLOR][/B][/CENTER]<br><br>" +
                "[CENTER][B][Color=rgb(178, 34, 34)]❖ ───── ✦ ─────『✙』───── ✦ ───── ❖[/B][/CENTER][/color]",
            prefix: PINN_PREFIX,
            status: true,
        },

        // Раздел RP Биографии
        {
            title: 'ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ                                ᅠ⠀             ⠀ ⠀⠀ᅠ   📝 RP Биографии 📝    ᅠᅠ ᅠᅠ          ⠀        ⠀    ⠀      ⠀ᅠ     ᅠ ᅠ     ᅠ ᅠ ᅠ ',
            dpstyle: 'oswald: 3px;     color: #fff; background: #212428; box-shadow: 0 0 2px 0 rgba(0,0,0,0.14),0 2px 2px 0 rgba(0,0,0,0.12),0 1px 3px 0 rgba(0,0,0,0.2); border: 1px solid #FFD700; width: 96%',
        },
        {
            title: 'Доработка',
            content: "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/JzzrkT4p/IMG-7328.png[/img][/url][/CENTER]<br><br>" +
                '[CENTER][FONT=Georgia][SIZE=4][I]{{greeting}}, уважаемый {{user.plainName}}.[/I][/SIZE][/FONT][/CENTER]<br><br>' +
                "[CENTER][FONT=Georgia][SIZE=4]Ваша RP биография нуждается в [B][COLOR=rgb(255, 255, 0)]Доработке[/COLOR][/B].[/SIZE][/FONT][/CENTER]<br>" +
                "[CENTER][FONT=Georgia][SIZE=4]Внимательно ознакомьтесь с [URL='https://forum.blackrussia.online/threads/vologda-%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F-roleplay-%D0%B1%D0%B8%D0%BE%D0%B3%D1%80%D0%B0%D1%84%D0%B8%D0%B8.10434179/'][B][COLOR=rgb(255, 0, 0)]Правилами Создания RP биографии[/COLOR][/B][/URL].[/SIZE][/FONT][/CENTER]<br>" +
                "[CENTER][FONT=Georgia][SIZE=4]Тема будет открыта на 24 часа, для доработки, писать дополнительные сообщения не нужно.[/SIZE][/FONT][/CENTER]<br><br>" +
                "[CENTER][B][COLOR=rgb(255, 255, 0)][SIZE=4][FONT=times new roman]「Доработка」 [/FONT][/SIZE][/COLOR][/B][/CENTER]<br><br>" +
                "[CENTER][B][Color=rgb(178, 34, 34)]❖ ───── ✦ ─────『✙』───── ✦ ───── ❖[/B][/CENTER]",
            prefix: PINN_PREFIX,
            status: true,
        },
        {
            title: 'Одобрено',
            content: "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/JzzrkT4p/IMG-7328.png[/img][/url][/CENTER]<br><br>" +
                '[CENTER][FONT=Georgia][SIZE=4][I]{{greeting}}, уважаемый {{user.plainName}}.[/I][/SIZE][/FONT][/CENTER]<br><br>' +
                "[CENTER][FONT=Georgia][SIZE=4]Ваша RP Биография получает статус [B][COLOR=rgb(0, 255, 0)]Одобрено[/COLOR][/B].[/SIZE][/FONT][/CENTER]<br>" +
                "[CENTER][FONT=Georgia][SIZE=4] Приятной Игры на сервере [B][COLOR=rgb(255, 0, 0)]VOLOGDA[/COLOR][/B].[/SIZE][/FONT][/CENTER]<br><br>" +
                "[CENTER][B][COLOR=rgb(0, 255, 0)][SIZE=4][FONT=times new roman]「Одобрено」 [/FONT][/SIZE][/COLOR][/B][/CENTER]<br><br>" +
                "[CENTER][B][Color=rgb(178, 34, 34)]❖ ───── ✦ ─────『✙』───── ✦ ───── ❖[/B][/CENTER]",
            prefix: ACCСEPT_PREFIX,
            status: true,
        },
 {
            title: 'Отказано',
            content: "[CENTER][url=https://postimages.org/][img]https://i.postimg.cc/JzzrkT4p/IMG-7328.png[/img][/url][/CENTER]<br><br>" +
                '[CENTER][FONT=Georgia][SIZE=4][I]{{greeting}}, уважаемый {{user.plainName}}.[/I][/SIZE][/FONT][/CENTER]<br><br>' +
                "[CENTER][FONT=Georgia][SIZE=4]Ваша RP Биография получает статус [B][COLOR=rgb(255, 0, 0)]Отказано[/COLOR][/B].[/SIZE][/FONT][/CENTER]<br>" +
               "[CENTER][FONT=Georgia][SIZE=4]Внимательно ознакомьтесь с [URL='https://forum.blackrussia.online/threads/vologda-%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D1%8F-roleplay-%D0%B1%D0%B8%D0%BE%D0%B3%D1%80%D0%B0%D1%84%D0%B8%D0%B8.10434179/'][B][COLOR=rgb(255, 0, 0)]Правилами Создания RP биографии[/COLOR][/B][/URL].[/SIZE][/FONT][/CENTER]<br><br>" +
                "[CENTER][B][COLOR=rgb(255, 0, 0)][SIZE=4][FONT=times new roman]「Отказано」 [/FONT][/SIZE][/COLOR][/B][/CENTER]<br><br>" +
                "[CENTER][B][Color=rgb(178, 34, 34)]❖ ───── ✦ ─────『✙』───── ✦ ───── ❖[/B][/CENTER]",
            prefix: ACCСEPT_PREFIX,
            status: true,
        }
    ];

    $(document).ready(() => {
        $('body').append('<script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script>');
        addButton('Answers', 'selectAnswer');

        const threadData = getThreadData();
        console.log('Thread Data:', threadData);

        $('button#pin').click(() => editThreadData(PINN_PREFIX, true));
        $('button#Ga').click(() => editThreadData(GA_PREFIX, true));
        $('button#Spec').click(() => editThreadData(SPECY_PREFIX, true));
        $('button#teamProject').click(() => editThreadData(COMMAND_PREFIX, true));
        $('button#accepted').click(() => editThreadData(ACCСEPT_PREFIX, true));

        $(`button#selectAnswer`).click(() => {
            XF.alert(buttonsMarkup(buttons), null, 'Выберите ответ:');
            buttons.forEach((btn, id) => {
                // Все кнопки кроме заголовков (id 0 и 3) будут отправлять ответ
                if (id !== 0 && id !== 3) {
                    $(`button#answers-${id}`).click(() => pasteContent(id, threadData, true));
                } else {
                    $(`button#answers-${id}`).click(() => pasteContent(id, threadData, false));
                }
            });
        });
    });

    function addButton(name, id) {
        $('.button--icon--reply').before(
            `<button type="button" class="button rippleButton" id="${id}" style="border-radius: 13px; margin-right: 5px; border: 2px solid #BF40BF;">${name}</button>`,
        );
    }

    function buttonsMarkup(buttons) {
        return `<div class="select_answer">${buttons
            .map(
                (btn, i) =>
                `<button id="answers-${i}" class="button--primary button ` +
                `rippleButton" style="margin:4px; ${btn.dpstyle}"><span class="button-text">${btn.title}</span></button>`,
            )
            .join('')}</div>`;
    }

    function pasteContent(id, data = {}, send = false) {
        const btn = buttons[id];

        // Заголовки (id 0 и 3) не имеют content
        if (!btn.content) return;

        const template = Handlebars.compile(btn.content);
        if ($('.fr-element.fr-view p').text() === '') $('.fr-element.fr-view p').empty();

        $('span.fr-placeholder').empty();
        $('div.fr-element.fr-view p').append(template(data));
        $('a.overlay-titleCloser').trigger('click');

        if (send == true) {
            editThreadData(btn.prefix, btn.status);
            $('.button--icon.button--icon--reply.rippleButton').trigger('click');
        }
    }

    function getThreadData() {
        let authorName = '';
        let authorID = '';

        const firstMessage = $('.message').first();
        if (firstMessage.length > 0) {
            const usernameEl = firstMessage.find('.username');
            if (usernameEl.length > 0) {
                authorName = usernameEl.text().trim();
                authorID = usernameEl.attr('data-user-id');
            }
        }

        if (!authorName) {
            const userBlock = $('.message-userContent .username');
            if (userBlock.length > 0) {
                authorName = userBlock.first().text().trim();
                authorID = userBlock.first().attr('data-user-id');
            }
        }

        const hours = new Date().getHours();

        return {
            user: {
                id: authorID || '0',
                name: authorName || 'Автор',
                mention: authorID ? `[USER=${authorID}]${authorName}[/USER]` : authorName,
                plainName: authorName || 'Автор'
            },
            greeting: () =>
                4 < hours && hours <= 11 ?
                'Доброе утро' :
                11 < hours && hours <= 15 ?
                'Добрый день' :
                15 < hours && hours <= 21 ?
                'Добрый вечер' :
                'Доброй ночи',
        };
    }

    function editThreadData(prefix, pin = false) {
        const threadTitle = $('.p-title-value')[0].lastChild.textContent;

        if (pin == false) {
            fetch(`${document.URL}edit`, {
                method: 'POST',
                body: getFormData({
                    prefix_id: prefix,
                    title: threadTitle,
                    _xfToken: XF.config.csrf,
                    _xfRequestUri: document.URL.split(XF.config.url.fullBase)[1],
                    _xfWithData: 1,
                    _xfResponseType: 'json',
                }),
            }).then(() => location.reload());
        } else {
            fetch(`${document.URL}edit`, {
                method: 'POST',
                body: getFormData({
                    prefix_id: prefix,
                    title: threadTitle,
                    pin: 1,
                    sticky: 1,
                    _xfToken: XF.config.csrf,
                    _xfRequestUri: document.URL.split(XF.config.url.fullBase)[1],
                    _xfWithData: 1,
                    _xfResponseType: 'json',
                }),
            }).then(() => location.reload());
        }
    }

    function getFormData(data) {
        const formData = new FormData();
        Object.entries(data).forEach(i => formData.append(i[0], i[1]));
        return formData;
    }
})();