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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();