Advertisement
Guest User

Untitled

a guest
Mar 14th, 2025
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.06 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Hide Posts from Specific Users on QBN Topics
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.3
  5. // @description  Automatically hide posts from specific users on qbn.com topics
  6. // @author       You
  7. // @match        https://www.qbn.com/topics/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     // List of users to ignore
  15.     const ignoredUsers = ['user1', 'user2', 'user3'];  // Add more users here as needed
  16.  
  17.     // Function to hide posts from ignored users
  18.     function hidePosts() {
  19.         console.log("Running hidePosts...");  // Debugging output
  20.         document.querySelectorAll('.reply').forEach((post) => {
  21.             const usernameElement = post.querySelector('.user');
  22.             if (usernameElement) {
  23.                 const username = usernameElement.textContent.trim();
  24.                 if (ignoredUsers.includes(username)) {
  25.                     // Hide the post if the user is in the ignored list
  26.                     console.log("Hiding post from user:", username); // Debugging output
  27.                     post.style.display = 'none';
  28.                 }
  29.             }
  30.         });
  31.     }
  32.  
  33.     // Use MutationObserver to watch for dynamically added posts
  34.     const observer = new MutationObserver((mutationsList, observer) => {
  35.         for (let mutation of mutationsList) {
  36.             if (mutation.type === 'childList') {
  37.                 hidePosts(); // Re-run hidePosts whenever new posts are added
  38.             }
  39.         }
  40.     });
  41.  
  42.     // Configure the observer to watch for changes in the reply section
  43.     const config = { childList: true, subtree: true };
  44.     const replyContainer = document.querySelector('.replies'); // Adjust if necessary
  45.  
  46.     if (replyContainer) {
  47.         console.log("Reply container found. Setting up MutationObserver...");
  48.         observer.observe(replyContainer, config);
  49.     } else {
  50.         console.log("Reply container not found!"); // Debugging output
  51.     }
  52.  
  53.     // Also run the function on initial page load
  54.     hidePosts();
  55. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement