hostloc 自动屏蔽黑名单用户

自动获取 hostloc 的黑名单,并屏蔽相应帖子

  1. // ==UserScript==
  2. // @name hostloc 自动屏蔽黑名单用户
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2.1
  5. // @description 自动获取 hostloc 的黑名单,并屏蔽相应帖子
  6. // @author susc
  7. // @match http*://*.hostloc.com/*
  8. // @grant unsafeWindow
  9. // @license GPL
  10. // ==/UserScript==
  11.  
  12. (async function () {
  13. 'use strict';
  14. // 脚本内部使用,在此处修改无效
  15. var CONFIG = {
  16. blockList: [],
  17. blockedPIDs: [],
  18. blockedCount: 0
  19. }
  20. // 根据页数获取黑名单
  21. async function getBlackListByPage(page) {
  22. let response
  23. try {
  24. response = await fetch(`/home.php?mod=space&do=friend&view=blacklist&page=${page}`)
  25. } catch (e) {
  26. console.log('获取黑名单失败')
  27. console.log(e)
  28. return []
  29. }
  30. let html = await response.text()
  31. let regList = html.match(/<a\shref="space-uid-.+html">([^<].+)<\/a>/g)
  32. if (!regList) {
  33. return []
  34. }
  35. let blacklist = regList.map(i => i.replace(/<.+?>/g, ''))
  36. console.log(`获取第${page}页黑名单成功: ${blacklist}`)
  37. return blacklist
  38. }
  39. // 获取黑名单
  40. let currentPage = 1
  41. let finish = false
  42. while (!finish) {
  43. console.log(`获取第${currentPage}页黑名单`)
  44. let blacklist = await getBlackListByPage(currentPage)
  45. if (blacklist.length === 0) {
  46. finish = true
  47. }
  48. else {
  49. CONFIG.blockList = CONFIG.blockList.concat(blacklist)
  50. currentPage++
  51. }
  52. }
  53.  
  54. // 帖子列表页面
  55. var authorNodes = document.querySelectorAll('th + .by cite a')
  56. authorNodes.forEach(function (item) {
  57. if (CONFIG.blockList.includes(item.innerText.trim())) {
  58. var $wrapper = item.parentElement.parentElement.parentElement.parentElement
  59. var $list = $wrapper.parentElement
  60. $list.removeChild($wrapper)
  61. CONFIG.blockedCount++
  62. }
  63. })
  64.  
  65. // 帖子列表点击下一页
  66. var $postList = document.querySelector('#threadlisttableid')
  67. if ($postList) {
  68. var post_mo = new MutationObserver(function (mList) {
  69. authorNodes = document.querySelectorAll('th + .by cite a')
  70. authorNodes.forEach(function (item) {
  71. if (CONFIG.blockList.includes(item.innerText.trim())) {
  72. var $wrapper = item.parentElement.parentElement.parentElement.parentElement
  73. var $list = $wrapper.parentElement
  74. $list.removeChild($wrapper)
  75. CONFIG.blockedCount++
  76. console.log('Blocked: ' + CONFIG.blockedCount)
  77. }
  78. })
  79. })
  80. post_mo.observe($postList, {
  81. childList: true
  82. })
  83. }
  84.  
  85. // 帖子详情页面
  86. authorNodes = document.querySelectorAll('.authi a.xw1');
  87. authorNodes.forEach(function (item) {
  88. if (CONFIG.blockList.includes(item.innerText.trim())) {
  89. var $wrapper = item.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement
  90. var id = Number(item.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id.replace('pid', ''))
  91. CONFIG.blockedPIDs.push(id)
  92. var $list = $wrapper.parentElement
  93. $list.removeChild($wrapper)
  94. CONFIG.blockedCount++
  95. }
  96. })
  97.  
  98. // 针对隐藏楼层
  99. if (unsafeWindow.blockedPIDs) {
  100. CONFIG.blockedPIDs.forEach(function (id) {
  101. for (var i = 0; i < unsafeWindow.blockedPIDs.length; i++) {
  102. if (unsafeWindow.blockedPIDs[i] === id) {
  103. unsafeWindow.blockedPIDs.splice(i, 1)
  104. CONFIG.blockedCount++
  105. }
  106. }
  107. })
  108. if (!unsafeWindow.blockedPIDs.length) {
  109. document.querySelector('#hiddenpoststip').style.display = 'none'
  110. }
  111. }
  112.  
  113. // 针对点评
  114. let $specialComments = document.querySelectorAll('.pstl')
  115. $specialComments.forEach(function (item) {
  116. let $author = item.querySelector('.psta .xi2')
  117. if ($author && CONFIG.blockList.includes($author.innerText.trim())) {
  118. let commentId = item.parentElement.id
  119. item.parentElement.removeChild(item)
  120. // 若点评列表无内容,则隐藏点评列表
  121. if (document.querySelectorAll(`#${commentId} .pstl`).length === 0) {
  122. document.querySelector(`#${commentId}`).style.display = 'none'
  123. }
  124. CONFIG.blockedCount++
  125. }
  126. })
  127. console.log('Blocked: ' + CONFIG.blockedCount)
  128. })();

QingJ © 2025

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