Auto Leave Conversations

Автоматически покидает выбранные переписки.

// ==UserScript==
// @name         Auto Leave Conversations
// @namespace    http://tampermonkey.net/
// @version      1.13
// @description  Автоматически покидает выбранные переписки.
// @author       eretly
// @match        https://zelenka.guru/conversations/*
// @match        https://lolz.guru/conversations/*
// @match        https://lolz.live/conversations/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const selectedConversations = JSON.parse(localStorage.getItem('selectedConversations')) || [];
    const leavingInProgress = localStorage.getItem('leavingInProgress') === 'true';
    let isLeaving = false;
    const selectedRadioOption = localStorage.getItem('selectedRadioOption') || 'delete';

    const leaveFormHTML = `
        <div id="leave-conversation-form" style="border: 1px solid #ccc; border-radius: 6px; padding: 20px; width: 300px; background: #272727; position: fixed; top: 50px; right: 20px; z-index: 9999; display: none;">
            <h2 class="heading h1">Покинуть переписку:</h2>
            <p>Если покинуть переписку, она исчезнет из Вашего списка.</p>

            <dl class="ctrlUnit">
                <dt><label for="delete_type_delete">Обработка новых ответов:</label></dt>
                <dd>
                    <ul>
                        <li>
                            <label for="delete_type_delete">
                                <input type="radio" name="delete_type" value="delete" id="delete_type_delete" ${selectedRadioOption === 'delete' ? 'checked' : ''}>
                                Принимать последующие сообщения
                            </label>
                            <p class="hint">Если появятся новые ответы, то переписка будет восстановлена у Вас во входящих.</p>
                        </li>
                        <li>
                            <label for="delete_type_delete_ignore">
                                <input type="radio" name="delete_type" value="delete_ignore" id="delete_type_delete_ignore" ${selectedRadioOption === 'delete_ignore' ? 'checked' : ''}>
                                Игнорировать последующие сообщения
                            </label>
                            <p class="hint">Вы не будете получать уведомления о новых ответах, а переписка будет оставаться удалённой.</p>
                        </li>
                    </ul>
                </dd>
            </dl>

            <dl class="ctrlUnit submitUnit">
                <dt></dt>
                <dd>
                    <button id="submit-leave" class="button primary">Покинуть переписку</button>
                    <button id="cancel-leave" class="button OverlayCloser">Отмена</button>
                </dd>
            </dl>
        </div>
    `;

    document.body.insertAdjacentHTML('beforeend', leaveFormHTML);

    document.addEventListener('click', (e) => {
        if (e.ctrlKey && e.target.closest('.conversationItem')) {
            e.preventDefault();
            toggleConversationSelection(e.target.closest('.conversationItem'));
        }
    });

    document.addEventListener('keydown', (e) => {
        if (e.ctrlKey && e.key === 'Enter') {
            e.preventDefault();
            if (selectedConversations.length > 0) {
                showLeaveForm();
            } else {
                console.log("Нет выбранных переписок для покидания.");
            }
        }
    });

    document.getElementById('submit-leave').addEventListener('click', async () => {
        const selectedRadio = document.querySelector('input[name="delete_type"]:checked');
        if (selectedRadio) {
            localStorage.setItem('selectedRadioOption', selectedRadio.value); // Сохраняем выбранный вариант
            await leaveSelectedConversations();
            hideLeaveForm();
        }
    });

    document.getElementById('cancel-leave').addEventListener('click', hideLeaveForm);

    if (leavingInProgress) {
        setTimeout(() => {
            leaveSelectedConversations();
        }, 2000);
    }

    function toggleConversationSelection(conversationItem) {
        const conversationId = conversationItem.dataset.cid;

        if (selectedConversations.includes(conversationId)) {
            selectedConversations.splice(selectedConversations.indexOf(conversationId), 1);
            conversationItem.style.backgroundColor = ''; // Убираем выделение
        } else {
            selectedConversations.push(conversationId);
            conversationItem.style.backgroundColor = '#48b04cb2'; // Подсветка выделения
        }

        localStorage.setItem('selectedConversations', JSON.stringify(selectedConversations));
    }

async function leaveSelectedConversations() {
    if (isLeaving) return;
    if (selectedConversations.length === 0) {
        console.log("Нет выбранных переписок.");
        return;
    }

    isLeaving = true;
    localStorage.setItem('leavingInProgress', 'true');

    const remainingConversations = [...selectedConversations];

    for (const cid of remainingConversations) {
        const menuButton = document.querySelector('.membersAndActions .PopupControl');
        if (menuButton) {
            console.log(`Клик по меню для переписки с ID: ${cid}`);
            simulateClick(menuButton);
            await delay(200);

            const leaveLink = document.querySelector(`a[href="conversations/${cid}/leave"]`);
            if (leaveLink) {
                console.log(`Клик по ссылке выхода для переписки с ID: ${cid}`);
                simulateClick(leaveLink);
                await delay(200);

                const form = document.querySelector('form.xenForm');
                if (form) {
                    const radioOption = form.querySelector(`input[name="delete_type"][value="${localStorage.getItem('selectedRadioOption')}"]`);
                    if (radioOption) {
                        console.log(`Выбор радиокнопки: ${radioOption.value}`);
                        simulateClick(radioOption); // Кликаем на выбранный радио вариант
                    }

                    await delay(300);

                    const submitButton = form.querySelector('input[type="submit"]');
                    if (submitButton) {
                        console.log(`Клик по кнопке "Покинуть" для переписки с ID: ${cid}`);
                        simulateClick(submitButton);
                        console.log(`Покинута переписка с ID: ${cid}`);
                        selectedConversations.splice(selectedConversations.indexOf(cid), 1);
                        localStorage.setItem('selectedConversations', JSON.stringify(selectedConversations));
                        await delay(200);

                        if (selectedConversations.length > 0) {
                            window.location.href = `https://lolz.live/conversations/${selectedConversations[0]}/`;
                            await delay(200); // Ждем 200 мс перед следующим открытием
                            location.reload();
                        }
                    } else {
                        console.log(`Кнопка "Покинуть" не найдена для переписки с ID: ${cid}`);
                    }
                } else {
                    console.log(`Форма не найдена для переписки с ID: ${cid}`);
                }
            } else {
                console.log(`Ссылка выхода не найдена для переписки с ID: ${cid}`);
            }
        } else {
            console.log(`Кнопка меню не найдена для переписки с ID: ${cid}`);
        }
    }

    localStorage.removeItem('leavingInProgress');
    isLeaving = false;
}

    function showLeaveForm() {
        document.getElementById('leave-conversation-form').style.display = 'block';
    }

    function hideLeaveForm() {
        document.getElementById('leave-conversation-form').style.display = 'none';
    }

    function simulateClick(element) {
        const mouseEvent = new MouseEvent('click', {
            view: window,
            bubbles: true,
            cancelable: true
        });
        element.dispatchEvent(mouseEvent);
    }

    function delay(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址