Guest User

Hide Posts By Reply Count

a guest
Jan 16th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Hide Posts By Reply Count
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-01-03
  5. // @description Hide posts which have fewer than x replies
  6. // @author You
  7. // @match *.4chan.org/*/thread/*
  8. // @match *://4chan.org/*/thread/*
  9. // @match *.4channel.org/*/thread/*
  10. // @match *://4channel.org/*/thread/*
  11. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Your code here...
  19. let hideToggle = false;
  20. const style = document.createElement('style');
  21. document.addEventListener("keypress", (e) => {
  22. if (e.key == "h" && document.activeElement.tagName != "TEXTAREA") {
  23. if (!hideToggle) {
  24. let minReplyCount = prompt("Min reply count", "0");
  25. if (!isNaN(minReplyCount) && minReplyCount > 0) {
  26. hideToggle = true;
  27. document.head.appendChild(style);
  28. style.type = 'text/css';
  29. style.appendChild(document.createTextNode(".dialog > * {display: block !important;} .inline > * {display: block !important;}"));
  30. [].slice.call(document.getElementsByClassName('container')).forEach(el => {
  31. if (el.childElementCount < minReplyCount && el.parentElement.parentElement.parentElement.parentElement.className != "dialog")
  32. el.parentElement.parentElement.parentElement.style.display = "none";
  33. });
  34. } else {
  35. console.log("invalid value");
  36. }
  37. } else {
  38. hideToggle = false;
  39. style.remove();
  40. const minReplyCount = 2;
  41. [].slice.call(document.getElementsByClassName('container')).forEach(el => {
  42. el.parentElement.parentElement.parentElement.style.display = "";
  43. });
  44. }
  45. }
  46. });
  47. })();
Add Comment
Please, Sign In to add comment