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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Expand All Hidden Replies in a 4chan Thread with Keyboard Shortcut
// @version      0.4
// @description  Shows all replies in thread with a keyboard shortcut (press 'a'), excluding typing in textarea
// @author       Anon
// @match        https://boards.4chan.org/*/thread/*
// @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 active element is not an input or textarea
        if (event.key === 'a' && document.activeElement.tagName.toLowerCase() !== 'input' && document.activeElement.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);
})();