Expand All Hidden Replies in a 4chan Thread with Keyboard Shortcut

Shows all replies in thread with a keyboard shortcut (press 'a'), excluding typing in textarea

目前为 2024-04-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         Expand All Hidden Replies in a 4chan Thread with Keyboard Shortcut
// @version      0.2
// @description  Shows all replies in thread with a keyboard shortcut (press 'a'), excluding typing in textarea
// @author       Anon
// @match        https://boards.4chan.org/*
// @grant        none
// @license      MIT
// @namespace https://greasyfork.org/users/1165708
// ==/UserScript==

(function() {
    'use strict';

    // Function to show all reply buttons
    function showAllReplyButtons() {
        // Select all reply buttons
        var replyButtons = document.querySelectorAll('.stub .show-reply-button');

        // Loop through each reply button
        replyButtons.forEach(function(button) {
            // Click the button
            button.click();
        });
    }

    // Function to handle keydown event
    function handleKeyDown(event) {
        // Check if the pressed key is 'a' and the event target is not a textarea
        if (event.key === 'a' && event.target.tagName.toLowerCase() !== 'textarea') {
            // Show all reply buttons
            showAllReplyButtons();

            // Prevent the default action of the 'a' key
            event.preventDefault();
        }
    }

    // Add keydown event listener to the document
    document.addEventListener('keydown', handleKeyDown);
})();


(function() {
    'use strict';

    // Function to show all reply buttons
    function showAllReplyButtons() {
        // Select all reply buttons
        var replyButtons = document.querySelectorAll('.stub .show-reply-button');

        // Loop through each reply button
        replyButtons.forEach(function(button) {
            // Click the button
            button.click();
        });
    }

    // Function to handle keydown event
    function handleKeyDown(event) {
        // Check if the pressed key is 'a' and the event target is not a textarea
        if (event.key === 'a' && event.target.tagName.toLowerCase() !== 'textarea') {
            // Show all reply buttons
            showAllReplyButtons();

            // Prevent the default action of the 'a' key
            event.preventDefault();
        }
    }

    // Add keydown event listener to the document
    document.addEventListener('keydown', handleKeyDown);
})();