Rllmukzen Threadshitter

Really ignore ignored users

目前为 2019-02-25 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Rllmukzen Threadshitter
  3. // @description Really ignore ignored users
  4. // @namespace https://github.com/insin/greasemonkey/
  5. // @version 3
  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 which quote ignored users
  26. function processQuotes(quotes) {
  27. quotes.forEach(el => {
  28. if (!ignoredUserIds.includes(el.dataset.ipsquoteUserid)) return
  29. let comment = el.closest('article.ipsComment')
  30. if (comment.style.display == 'none') return
  31. comment.style.display = 'none'
  32. })
  33. }
  34.  
  35. function processPage() {
  36. processQuotes(document.querySelectorAll('[data-ipsquote-userid]'))
  37. }
  38.  
  39. // Process initial posts
  40. processPage()
  41.  
  42. // Watch for posts being replaced when paging
  43. new MutationObserver(mutations =>
  44. mutations.forEach(mutation => {
  45. if (mutation.oldValue == 'true') {
  46. processPage()
  47. }
  48. })
  49. ).observe(document.querySelector('div.cTopic'), {
  50. attributes: true,
  51. attributeFilter: ['animating'],
  52. attributeOldValue: true,
  53. })
  54.  
  55. // Watch for new posts being loaded into the current page
  56. new MutationObserver(mutations =>
  57. mutations.forEach(mutation => {
  58. mutation.addedNodes.forEach(post => {
  59. processQuotes(post.querySelectorAll('[data-ipsquote-userid]'))
  60. })
  61. })
  62. ).observe(document.querySelector('#elPostFeed > form'), {
  63. childList: true,
  64. })
  65. }
  66.  
  67. function IgnoredUsersPage() {
  68. // Sync ignored user ids
  69. localStorage.ignoredUserIds = JSON.stringify(
  70. Array.from(document.querySelectorAll('[data-ignoreuserid]')).map(el => el.dataset.ignoreuserid)
  71. )
  72. }
  73.  
  74. let page
  75. if (location.href.includes('index.php?/topic/')) {
  76. page = TopicPage
  77. } else if (location.href.includes('index.php?/ignore/')) {
  78. page = IgnoredUsersPage
  79. }
  80.  
  81. if (page) {
  82. page()
  83. }