Rllmukzen Threadshitter

Really ignore ignored users

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

  1. // ==UserScript==
  2. // @name Rllmukzen Threadshitter
  3. // @description Really ignore ignored users
  4. // @namespace https://github.com/insin/greasemonkey/
  5. // @version 2
  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. // Hide "You've chosen to ignore content by <ignored user>"
  17. addStyle(`
  18. .ipsComment_ignored {
  19. display: none;
  20. }
  21. `)
  22.  
  23. function processPage() {
  24. // Hide comments which quote ignored users
  25. let ignoredUserIds = JSON.parse(localStorage.ignoredUserIds || '[]')
  26. let quotes = document.querySelectorAll('[data-ipsquote-userid]')
  27. document.querySelectorAll('[data-ipsquote-userid]').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. // Process initial posts
  36. processPage()
  37.  
  38. // Watch for posts being replaced when paging
  39. new MutationObserver(mutations =>
  40. mutations.forEach(mutation => {
  41. if (mutation.oldValue == 'true') {
  42. processPage()
  43. }
  44. })
  45. ).observe(document.querySelector('div.cTopic'), {
  46. attributes: true,
  47. attributeFilter: ['animating'],
  48. attributeOldValue: true,
  49. })
  50. }
  51.  
  52. function IgnoredUsersPage() {
  53. // Sync ignored user ids
  54. localStorage.ignoredUserIds = JSON.stringify(
  55. Array.from(document.querySelectorAll('[data-ignoreuserid]')).map(el => el.dataset.ignoreuserid)
  56. )
  57. }
  58.  
  59. let page
  60. if (location.href.includes('index.php?/topic/')) {
  61. page = TopicPage
  62. } else if (location.href.includes('index.php?/ignore/')) {
  63. page = IgnoredUsersPage
  64. }
  65.  
  66. if (page) {
  67. page()
  68. }