Poe.com Checkbox Selector

Automatically selects all messages on poe.com, useful for sharing long conversations.

目前为 2024-07-10 提交的版本。查看 最新版本

// ==UserScript==
// @name         Poe.com Checkbox Selector
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license MIT
// @description  Automatically selects all messages on poe.com, useful for sharing long conversations.
// @match        https://poe.com/*
// @grant        GM_log
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    let isRunning = false;
    let observer;

    GM_log('Script started');

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

    async function selectCheckboxes() {
        if (!isRunning) return;

        GM_log('Starting selectCheckboxes function');
        const labels = document.querySelectorAll('label[class*="checkbox-and-radio_label__"][class*="ChatMessage_checkbox__"]');
        GM_log('Checkbox labels found: ' + labels.length);

        for (let i = 0; i < labels.length; i++) {
            if (!isRunning) return;

            const label = labels[i];
            const checkbox = label.querySelector('input[type="checkbox"]');
            
            GM_log(`Processing checkbox ${i + 1}`);
            GM_log('Initial state: ' + (checkbox.checked ? 'checked' : 'unchecked'));

            if (!checkbox.checked) {
                try {
                    label.click();
                    await sleep(100);
                    GM_log('State after click: ' + (checkbox.checked ? 'checked' : 'unchecked'));
                } catch (error) {
                    GM_log('Error trying to check checkbox: ' + error.message);
                }
            } else {
                GM_log('Checkbox was already checked');
            }

            await sleep(200);
        }
    }

    function toggleScript() {
        isRunning = !isRunning;
        updateButtonStyle();
        if (isRunning) {
            GM_log('Script activated');
            selectCheckboxes();
            startObserver();
        } else {
            GM_log('Script deactivated');
            stopObserver();
        }
    }

    function updateButtonStyle() {
        const button = document.getElementById('toggleButton');
        if (button) {
            const checkboxAscii = isRunning ? '☑' : '☐';
            button.innerHTML = `${checkboxAscii} ${isRunning ? 'On' : 'Off'}`;
            button.style.backgroundColor = isRunning ? '#4CAF50' : '#ff4d4d';
        }
    }

    function addButton() {
        GM_log('Adding button');
        const button = document.createElement('button');
        button.id = 'toggleButton';
        button.style.cssText = `
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 9999;
            padding: 5px 10px;
            border: none;
            cursor: pointer;
            border-radius: 5px;
            font-weight: bold;
            font-size: 14px;
            opacity: 0.7;
            transition: opacity 0.3s, background-color 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
        `;
        button.addEventListener('click', toggleScript);
        button.addEventListener('mouseover', () => button.style.opacity = '1');
        button.addEventListener('mouseout', () => button.style.opacity = '0.7');
        document.body.appendChild(button);
        updateButtonStyle();
    }

    function startObserver() {
        observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
                    GM_log('Changes detected in DOM, executing selectCheckboxes');
                    selectCheckboxes();
                }
            });
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }

    function stopObserver() {
        if (observer) {
            observer.disconnect();
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', addButton);
    } else {
        addButton();
    }
})();

QingJ © 2025

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