ADblocker4DeepinBBS

block AD-like Users in DeepinBBS

  1. // ==UserScript==
  2. // @name ADblocker4DeepinBBS
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-06-26
  5. // @description block AD-like Users in DeepinBBS
  6. // @author fallingstar10
  7. // @match https://bbs.deepin.org/post/*
  8. // @match https://bbs.deepin.org/zh/post/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=deepin.org
  10. // @license MIT
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const userIds = [312791,312017,286301,312105,19468,312784,19468,260299]; // 根据需要添加用户ID
  18. let blockedPostIds = [];
  19.  
  20. function fetchUserPosts(userid) {
  21. const ngState = JSON.parse(document.querySelector('#ng-state').innerText);
  22. const userPosts = ngState['post-detail'].posts.data.filter((ele) => ele.post_user_id === userid);
  23. const postIds = userPosts.map(post => post.id);
  24. const formattedPostIds = postIds.map(id => `post_${id}`);
  25. blockedPostIds.push(...new Set([...blockedPostIds, ...formattedPostIds]));
  26. formattedPostIds.forEach(hidePosts); // 隐藏当前用户的所有帖子
  27. return formattedPostIds;
  28. }
  29.  
  30. function hidePosts() {
  31. blockedPostIds.forEach(postId => {
  32. let postContainer = document.getElementById(postId);
  33. if (postContainer) {
  34. postContainer.style.display = 'none';
  35. }
  36. });
  37. }
  38.  
  39. const observer = new MutationObserver(mutations => {
  40. mutations.forEach(mutation => {
  41. if (mutation.type === 'childList' && mutation.addedNodes.length) {
  42. mutation.addedNodes.forEach(node => {
  43. if (node.nodeType === Node.ELEMENT_NODE && node.matches('div.post_pc')) {
  44. hidePosts(); // 重新检查所有帖子
  45. }
  46. });
  47. }
  48. });
  49. });
  50.  
  51. observer.observe(document.body, {
  52. childList: true,
  53. subtree: true
  54. });
  55.  
  56. // 初始屏蔽执行
  57. window.addEventListener('load', () => {
  58. userIds.forEach(fetchUserPosts); // 预先获取所有应被屏蔽的帖子ID
  59. hidePosts(); // 首次隐藏帖子
  60. });
  61. })();

QingJ © 2025

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