PTH hide forum posts

Add ability to hide forum posts

  1. // ==UserScript==
  2. // @name PTH hide forum posts
  3. // @version 0.4
  4. // @description Add ability to hide forum posts
  5. // @author Chameleon
  6. // @include http*://redacted.ch/*
  7. // @grant none
  8. // @namespace https://gf.qytechs.cn/users/87476
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var script=document.createElement('script');
  14. script.src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js';
  15. document.body.appendChild(script);
  16.  
  17. var hiddenPosts=getHiddenPosts();
  18. var forumHeads=document.getElementsByClassName('colhead_dark');
  19. for(var i=0; i<forumHeads.length; i++)
  20. {
  21. var f=forumHeads[i];
  22. var post_id=f.getElementsByTagName('a')[0].textContent;
  23. if(hiddenPosts.indexOf(post_id) != -1)
  24. {
  25. f.nextElementSibling.style.display='none';
  26. f.nextElementSibling.setAttribute('stayHidden', 'true');
  27. }
  28. f.addEventListener('click', toggleHide.bind(undefined, f), false);
  29. }
  30. })();
  31.  
  32. function toggleHide(f, event)
  33. {
  34. if(event.srcElement !== f.firstElementChild && event.target !== f.firstElementChild)
  35. return;
  36. var post_id=f.getElementsByTagName('a')[0].textContent;
  37. var hideable=f.nextElementSibling;
  38. if(hideable.style.display=='none')
  39. {
  40. removeHiddenPost(post_id);
  41. $(hideable).show("blind", { direction: "up" }, "slow");
  42. hideable.setAttribute('stayHidden', 'false');
  43. }
  44. else
  45. {
  46. addHiddenPost(post_id);
  47. $(hideable).hide("blind", { direction: "up" }, "slow");
  48. hideable.setAttribute('stayHidden', 'true');
  49. }
  50. }
  51.  
  52. function getHiddenPosts()
  53. {
  54. var h=window.localStorage.hiddenPosts;
  55. if(!h)
  56. h=[];
  57. else
  58. h=JSON.parse(h);
  59.  
  60. return h;
  61. }
  62.  
  63. function addHiddenPost(post_id)
  64. {
  65. var h=getHiddenPosts();
  66. h.push(post_id);
  67. window.localStorage.hiddenPosts=JSON.stringify(h);
  68. }
  69.  
  70. function removeHiddenPost(post_id)
  71. {
  72. var h=getHiddenPosts();
  73. var index=h.indexOf(post_id);
  74. if(index != -1)
  75. h.splice(index, 1);
  76. window.localStorage.hiddenPosts=JSON.stringify(h);
  77. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址