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

  1. // ==UserScript==
  2. // @name Expand All Hidden Replies in a 4chan Thread with Keyboard Shortcut
  3. // @version 0.4
  4. // @description Shows all replies in thread with a keyboard shortcut (press 'a'), excluding typing in textarea
  5. // @author Anon
  6. // @match https://boards.4chan.org/*/thread/*
  7. // @grant none
  8. // @license MIT
  9. // @namespace https://greasyfork.org/users/1165708
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to show all reply buttons
  16. function showAllReplyButtons() {
  17. // Select all reply buttons
  18. var replyButtons = document.querySelectorAll('.stub .show-reply-button');
  19.  
  20. // Loop through each reply button
  21. replyButtons.forEach(function(button) {
  22. // Click the button
  23. button.click();
  24. });
  25. }
  26.  
  27. // Function to handle keydown event
  28. function handleKeyDown(event) {
  29. // Check if the pressed key is 'a' and the active element is not an input or textarea
  30. if (event.key === 'a' && document.activeElement.tagName.toLowerCase() !== 'input' && document.activeElement.tagName.toLowerCase() !== 'textarea') {
  31. // Show all reply buttons
  32. showAllReplyButtons();
  33.  
  34. // Prevent the default action of the 'a' key
  35. event.preventDefault();
  36. }
  37. }
  38.  
  39. // Add keydown event listener to the document
  40. document.addEventListener('keydown', handleKeyDown);
  41. })();