Greasy Fork 还支持 简体中文。

Rllmukzen Threadshitter

Really ignore ignored users

目前為 2019-02-27 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Rllmukzen Threadshitter
  3. // @description Really ignore ignored users
  4. // @namespace https://github.com/insin/greasemonkey/
  5. // @version 4
  6. // @match https://www.rllmukforum.com/index.php*
  7. // ==/UserScript==
  8.  
  9. function addStyle(css) {
  10. let $style = document.createElement('style')
  11. $style.appendChild(document.createTextNode(css))
  12. document.querySelector('head').appendChild($style)
  13. }
  14.  
  15. function TopicPage() {
  16. let ignoredUserIds = JSON.parse(localStorage.ignoredUserIds || '[]')
  17.  
  18. // Hide "You've chosen to ignore content by <ignored user>"
  19. addStyle(`
  20. .ipsComment_ignored {
  21. display: none;
  22. }
  23. `)
  24.  
  25. // Hide posts containing elements which have an ignored user id as a specified
  26. // data attribute.
  27. function hidePostsByDataAttribute(elements, dataAttribute) {
  28. elements.forEach(el => {
  29. if (!ignoredUserIds.includes(el.dataset[dataAttribute])) return
  30. let post = el.closest('article.ipsComment')
  31. if (post.style.display == 'none') return
  32. post.style.display = 'none'
  33. })
  34. }
  35.  
  36. // Hide posts which quote ignored users
  37. function processQuotes(context) {
  38. hidePostsByDataAttribute(
  39. context.querySelectorAll('[data-ipsquote-userid]'),
  40. 'ipsquoteUserid'
  41. )
  42. }
  43.  
  44. // Hide posts which @-mention ignored users
  45. function processMentions(context) {
  46. hidePostsByDataAttribute(
  47. context.querySelectorAll('[data-mentionid]'),
  48. 'mentionid'
  49. )
  50. }
  51.  
  52. function processPosts(context = document) {
  53. processQuotes(context)
  54. processMentions(context)
  55. }
  56.  
  57. // Process initial posts
  58. processPosts()
  59.  
  60. // Watch for posts being replaced when paging
  61. new MutationObserver(mutations =>
  62. mutations.forEach(mutation => {
  63. if (mutation.oldValue == 'true') {
  64. processPosts()
  65. }
  66. })
  67. ).observe(document.querySelector('div.cTopic'), {
  68. attributes: true,
  69. attributeFilter: ['animating'],
  70. attributeOldValue: true,
  71. })
  72.  
  73. // Watch for new posts being loaded into the current page
  74. new MutationObserver(mutations =>
  75. mutations.forEach(mutation =>
  76. mutation.addedNodes.forEach(processPosts)
  77. )
  78. ).observe(document.querySelector('#elPostFeed > form'), {
  79. childList: true,
  80. })
  81. }
  82.  
  83. function IgnoredUsersPage() {
  84. // Sync ignored user ids
  85. localStorage.ignoredUserIds = JSON.stringify(
  86. Array.from(document.querySelectorAll('[data-ignoreuserid]')).map(el =>
  87. el.dataset.ignoreuserid
  88. )
  89. )
  90. }
  91.  
  92. let page
  93. if (location.href.includes('index.php?/topic/')) {
  94. page = TopicPage
  95. } else if (location.href.includes('index.php?/ignore/')) {
  96. page = IgnoredUsersPage
  97. }
  98.  
  99. if (page) {
  100. page()
  101. }