Guest User

Untitled

a guest
May 9th, 2025
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. // ==UserScript==
  2. // @name 4chan Advanced Hide replies keybind
  3. // @namespace b4k
  4. // @match *://boards.4chan.org/*
  5. // @match *://boards.4channel.org/*
  6. // @run-at document-start
  7. // ==/UserScript==
  8.  
  9. (() => {
  10. "use strict";
  11.  
  12. document.addEventListener("4chanXInitFinished", () => {
  13. let cPressed = false;
  14.  
  15. // Key press check for 'c'
  16. document.addEventListener("keydown", (event) => {
  17. if (event.key.toLowerCase() === 'c') {
  18. cPressed = true;
  19. }
  20. });
  21. document.addEventListener("keyup", (event) => {
  22. if (event.key.toLowerCase() === 'c') {
  23. cPressed = false;
  24. }
  25. });
  26.  
  27. // Apply to all existing posts in the thread
  28. document.querySelectorAll(".postContainer.replyContainer").forEach(initPost);
  29.  
  30. // Apply to all new replies
  31. document.addEventListener("ThreadUpdate", (e) => {
  32. if (e.detail[404] === true) return;
  33. if (e.detail.newPosts.length > 0) {
  34. e.detail.newPosts.forEach(uID => {
  35. const post = document.getElementById(`pc${uID.split(".").pop()}`);
  36. if (post) initPost(post);
  37. });
  38. }
  39. });
  40.  
  41. // Function to initialize each post
  42. function initPost(post) {
  43. const container = post.querySelector(".post.reply");
  44. container.addEventListener("click", function(e) {
  45. if (!cPressed) return;
  46. e.preventDefault();
  47. e.stopPropagation(); // Stop event bubbling to prevent unwanted actions
  48.  
  49. // Open the dropdown menu
  50. const menuButton = post.querySelector(".menu-button");
  51. if (menuButton) {
  52. menuButton.click();
  53.  
  54. // Wait for the menu to populate then access the Hide submenu
  55. setTimeout(() => {
  56. // Select the .hide-reply-link element
  57. const hideLink = post.querySelector(".hide-reply-link");
  58.  
  59. if (hideLink) {
  60. // Dispatch a click event on the hideLink to open the submenu
  61. hideLink.dispatchEvent(new Event('click'));
  62.  
  63. // Short delay for submenu to be visible then check and click checkboxes
  64. setTimeout(() => {
  65. // Correctly select the checkboxes within the submenu
  66. const submenu = post.querySelector(".dialog.submenu"); // Select the submenu container
  67. if (!submenu) return; // Exit if submenu not found
  68.  
  69. const thisPostCheckbox = submenu.querySelector('label:nth-child(2) input[type="checkbox"]');
  70. const repliesCheckbox = submenu.querySelector('label:nth-child(3) input[type="checkbox"]');
  71. const makeStubCheckbox = submenu.querySelector('label:nth-child(4) input[type="checkbox"]');
  72. const byIdCheckbox = submenu.querySelector('label:nth-child(5) input[type="checkbox"]');
  73.  
  74. // Function to check and click a checkbox if it's not already checked
  75. function checkAndClick(checkbox) {
  76. if (checkbox && !checkbox.checked) {
  77. checkbox.click();
  78. }
  79. }
  80. // Function to uncheck
  81. function unCheck(checkbox) {
  82. if (checkbox && checkbox.checked) {
  83. checkbox.click();
  84. }
  85. }
  86.  
  87. checkAndClick(thisPostCheckbox);
  88. checkAndClick(repliesCheckbox);
  89. checkAndClick(makeStubCheckbox); // Always check "Make stub"
  90. unCheck(byIdCheckbox); // Always uncheck "By poster id"
  91.  
  92.  
  93. // Apply the hide settings. Find the Apply button within the submenu.
  94. const applyButton = submenu.querySelector('a.entry'); // Directly find in the submenu
  95. if(applyButton) {
  96. applyButton.click();
  97. }
  98.  
  99. }, 50); // Small delay for submenu to appear
  100. }
  101. }, 50); // Small delay for menu to appear
  102. }
  103. });
  104. }
  105. }, false);
  106. })();
Advertisement
Add Comment
Please, Sign In to add comment