Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name DDR Blocker
- // @namespace http://tampermonkey.net/
- // @version 1
- // @description Completely removes comments from specific users on dodiri.cz with no visible trace and adds quick block buttons
- // @author You
- // @match *://dodiri.cz/*
- // @match *://*.dodiri.cz/*
- // @grant GM_addStyle
- // @grant GM_setValue
- // @grant GM_getValue
- // ==/UserScript==
- (function() {
- 'use strict';
- // Add CSS for the popup, toggle button, and new quick block buttons
- const css = `
- #comment-blocker-toggle {
- position: fixed;
- bottom: 20px;
- right: 20px;
- background-color: #4CAF50;
- color: white;
- padding: 10px 15px;
- border-radius: 5px;
- cursor: pointer;
- z-index: 9998;
- box-shadow: 0 2px 5px rgba(0,0,0,0.2);
- font-family: Arial, sans-serif;
- }
- #comment-blocker-popup {
- position: fixed;
- bottom: 70px;
- right: 20px;
- width: 300px;
- background-color: white;
- border-radius: 5px;
- box-shadow: 0 2px 10px rgba(0,0,0,0.3);
- z-index: 9999;
- font-family: Arial, sans-serif;
- display: none;
- }
- #comment-blocker-popup.visible {
- display: block;
- }
- #comment-blocker-header {
- padding: 10px 15px;
- background-color: #f2f2f2;
- border-top-left-radius: 5px;
- border-top-right-radius: 5px;
- font-weight: bold;
- border-bottom: 1px solid #ddd;
- }
- #comment-blocker-content {
- padding: 15px;
- max-height: 300px;
- overflow-y: auto;
- }
- .blocked-user-row {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 10px;
- padding-bottom: 10px;
- border-bottom: 1px solid #eee;
- }
- .blocked-user-row:last-child {
- margin-bottom: 0;
- padding-bottom: 0;
- border-bottom: none;
- }
- #add-user-form {
- display: flex;
- margin-top: 15px;
- border-top: 1px solid #eee;
- padding-top: 15px;
- }
- #new-user-input {
- flex-grow: 1;
- padding: 5px 10px;
- border: 1px solid #ddd;
- border-radius: 3px;
- margin-right: 10px;
- }
- #add-user-button {
- background-color: #4CAF50;
- color: white;
- border: none;
- padding: 5px 10px;
- border-radius: 3px;
- cursor: pointer;
- }
- .remove-user {
- background-color: #f44336;
- color: white;
- border: none;
- padding: 3px 8px;
- border-radius: 3px;
- cursor: pointer;
- }
- #run-blocker-button {
- background-color: #2196F3;
- color: white;
- border: none;
- padding: 8px 12px;
- border-radius: 3px;
- cursor: pointer;
- margin-top: 15px;
- width: 100%;
- }
- .quick-block-btn {
- display: inline-block;
- margin-left: 5px;
- color: #f44336;
- cursor: pointer;
- font-weight: bold;
- font-size: 12px;
- padding: 0 5px;
- border-radius: 3px;
- opacity: 0.6;
- transition: opacity 0.2s;
- }
- .quick-block-btn:hover {
- opacity: 1;
- background-color: #ffeeee;
- }
- `;
- // Add the styles to the document
- document.head.appendChild(document.createElement('style')).textContent = css;
- // Initial list of blocked users
- let blockedUsers = [
- 'zakrslejbuzik', 'ututyt', 'megafrajer', 'heslo', 'petr-metr',
- 'kral-dd-a-ndr', 'dodirikral', 'realfešák', 'velmimoudrymuz', 'velvysranec', ];
- // Create toggle button
- const toggleButton = document.createElement('div');
- toggleButton.id = 'comment-blocker-toggle';
- toggleButton.textContent = '';
- document.body.appendChild(toggleButton);
- // Create popup
- const popup = document.createElement('div');
- popup.id = 'comment-blocker-popup';
- popup.innerHTML = `
- <div id="comment-blocker-header">Blocked Users</div>
- <div id="comment-blocker-content">
- <div id="blocked-users-list"></div>
- <form id="add-user-form">
- <input type="text" id="new-user-input" placeholder="Username to block">
- <button type="submit" id="add-user-button">Add</button>
- </form>
- <button id="run-blocker-button">Apply Changes</button>
- </div>
- `;
- document.body.appendChild(popup);
- // Toggle popup visibility
- toggleButton.addEventListener('click', () => {
- popup.classList.toggle('visible');
- });
- // Populate blocked users list
- function updateBlockedUsersList() {
- const blockedUsersList = document.getElementById('blocked-users-list');
- blockedUsersList.innerHTML = '';
- blockedUsers.forEach(user => {
- const userRow = document.createElement('div');
- userRow.className = 'blocked-user-row';
- userRow.innerHTML = `
- <span>${user}</span>
- <button class="remove-user" data-user="${user}">Remove</button>
- `;
- blockedUsersList.appendChild(userRow);
- });
- // Add event listeners to remove buttons
- document.querySelectorAll('.remove-user').forEach(button => {
- button.addEventListener('click', (e) => {
- const userToRemove = e.target.getAttribute('data-user');
- blockedUsers = blockedUsers.filter(user => user !== userToRemove);
- updateBlockedUsersList();
- });
- });
- }
- // Add new user form submission
- document.getElementById('add-user-form').addEventListener('submit', (e) => {
- e.preventDefault();
- const newUserInput = document.getElementById('new-user-input');
- const newUser = newUserInput.value.trim();
- if (newUser && !blockedUsers.includes(newUser)) {
- blockedUsers.push(newUser);
- updateBlockedUsersList();
- newUserInput.value = '';
- }
- });
- // Apply changes button
- document.getElementById('run-blocker-button').addEventListener('click', () => {
- blockComments();
- popup.classList.remove('visible');
- });
- // Function to block comments from specified users
- function blockComments() {
- let blockedCount = 0;
- // Find the comments section
- const commentsSection = document.getElementById('comments-wp');
- if (!commentsSection) return;
- // Find the comment list
- const commentList = commentsSection.querySelector('.comment-list');
- if (!commentList) return;
- // Process each blocked user
- blockedUsers.forEach(username => {
- // Find all comment elements from the blocked user
- // Format: .depth-1.thread-even.even.comment-author-zakrslejbuzik.byuser.comment
- const commentElements = commentList.querySelectorAll(`.comment-author-${username}.byuser.comment`);
- commentElements.forEach(commentElement => {
- // Check if this element is visible before hiding it
- if (commentElement.style.display !== 'none') {
- // Store original display style for potential restoration
- commentElement.setAttribute('data-original-display', commentElement.style.display || 'block');
- // Completely hide the comment
- commentElement.style.display = 'none';
- blockedCount++;
- }
- });
- });
- // Show notification only if comments were blocked
- if (blockedCount > 0) {
- const notification = document.createElement('div');
- notification.textContent = `${blockedCount} ${blockedCount !== 1 ? 's' : ''} `;
- notification.style.cssText = 'position: fixed; bottom: 75px; right: 20px; background-color: #f8f8f8; color: #333; padding: 10px 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 9997; font-family: Arial, sans-serif;';
- document.body.appendChild(notification);
- // Remove notification after 5 seconds
- setTimeout(() => {
- if (notification.parentNode) {
- notification.parentNode.removeChild(notification);
- }
- }, 5000);
- }
- }
- // Function to add quick block buttons to each username in comments
- function addQuickBlockButtons() {
- // Find the comments section
- const commentsSection = document.getElementById('comments-wp');
- if (!commentsSection) return;
- // Find all comment author elements
- const authorElements = commentsSection.querySelectorAll('.comment-author');
- authorElements.forEach(authorElement => {
- // Skip if we already added a button to this author
- if (authorElement.querySelector('.quick-block-btn')) return;
- // Find the author name element (typically an <a> tag or similar)
- const authorLink = authorElement.querySelector('a, cite');
- if (!authorLink) return;
- // Extract the username
- let username = '';
- // Check if the comment has a class that indicates the author
- const commentElement = authorElement.closest('.comment');
- if (commentElement) {
- const classes = commentElement.className.split(' ');
- for (const className of classes) {
- if (className.startsWith('comment-author-')) {
- username = className.replace('comment-author-', '');
- break;
- }
- }
- }
- // If we couldn't find username from class, try to extract from the text
- if (!username) {
- username = authorLink.textContent.trim().toLowerCase().replace(/\s+/g, '-');
- }
- // Skip if username is empty or if we already have a block button
- if (!username || authorLink.nextElementSibling?.classList.contains('quick-block-btn')) return;
- // Create the X button for quick blocking
- const blockButton = document.createElement('span');
- blockButton.className = 'quick-block-btn';
- blockButton.textContent = '';
- blockButton.title = `Block ${username}`;
- blockButton.setAttribute('data-username', username);
- // Add click event to block the user
- blockButton.addEventListener('click', (e) => {
- e.preventDefault();
- e.stopPropagation();
- const usernameToBlock = e.target.getAttribute('data-username');
- // Add user to block list if not already there
- if (!blockedUsers.includes(usernameToBlock)) {
- blockedUsers.push(usernameToBlock);
- updateBlockedUsersList();
- blockComments();
- // Show notification
- const notification = document.createElement('div');
- notification.textContent = `User "${usernameToBlock}" added to block list`;
- notification.style.cssText = 'position: fixed; bottom: 75px; right: 20px; background-color: #f8f8f8; color: #333; padding: 10px 15px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 9997; font-family: Arial, sans-serif;';
- document.body.appendChild(notification);
- // Remove notification after 3 seconds
- setTimeout(() => {
- if (notification.parentNode) {
- notification.parentNode.removeChild(notification);
- }
- }, 3000);
- }
- });
- // Insert the button after the author name
- authorLink.parentNode.insertBefore(blockButton, authorLink.nextSibling);
- });
- }
- // Initialize the blocked users list
- updateBlockedUsersList();
- // Run when the page loads
- window.addEventListener('load', () => {
- blockComments();
- addQuickBlockButtons();
- });
- // Also run for dynamic content loading (if the site uses AJAX)
- const observer = new MutationObserver((mutations) => {
- for (const mutation of mutations) {
- if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
- // Check if any new comments were added
- setTimeout(() => {
- blockComments();
- addQuickBlockButtons();
- }, 500); // Small delay to ensure dynamic content is fully loaded
- break;
- }
- }
- });
- // Start observing the body for changes
- observer.observe(document.body, { childList: true, subtree: true });
- })();
Advertisement
Add Comment
Please, Sign In to add comment