Guest User

Untitled

a guest
Mar 10th, 2025
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.45 KB | Fixit | 0 0
  1. // ==UserScript==
  2. // @name DDR Blocker
  3. // @namespace http://tampermonkey.net/
  4. // @version 1
  5. // @description Completely removes comments from specific users on dodiri.cz with no visible trace and adds quick block buttons
  6. // @author You
  7. // @match *://dodiri.cz/*
  8. // @match *://*.dodiri.cz/*
  9. // @grant GM_addStyle
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Add CSS for the popup, toggle button, and new quick block buttons
  18. const css = `
  19. #comment-blocker-toggle {
  20. position: fixed;
  21. bottom: 20px;
  22. right: 20px;
  23. background-color: #4CAF50;
  24. color: white;
  25. padding: 10px 15px;
  26. border-radius: 5px;
  27. cursor: pointer;
  28. z-index: 9998;
  29. box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  30. font-family: Arial, sans-serif;
  31. }
  32.  
  33. #comment-blocker-popup {
  34. position: fixed;
  35. bottom: 70px;
  36. right: 20px;
  37. width: 300px;
  38. background-color: white;
  39. border-radius: 5px;
  40. box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  41. z-index: 9999;
  42. font-family: Arial, sans-serif;
  43. display: none;
  44. }
  45.  
  46. #comment-blocker-popup.visible {
  47. display: block;
  48. }
  49.  
  50. #comment-blocker-header {
  51. padding: 10px 15px;
  52. background-color: #f2f2f2;
  53. border-top-left-radius: 5px;
  54. border-top-right-radius: 5px;
  55. font-weight: bold;
  56. border-bottom: 1px solid #ddd;
  57. }
  58.  
  59. #comment-blocker-content {
  60. padding: 15px;
  61. max-height: 300px;
  62. overflow-y: auto;
  63. }
  64.  
  65. .blocked-user-row {
  66. display: flex;
  67. justify-content: space-between;
  68. align-items: center;
  69. margin-bottom: 10px;
  70. padding-bottom: 10px;
  71. border-bottom: 1px solid #eee;
  72. }
  73.  
  74. .blocked-user-row:last-child {
  75. margin-bottom: 0;
  76. padding-bottom: 0;
  77. border-bottom: none;
  78. }
  79.  
  80. #add-user-form {
  81. display: flex;
  82. margin-top: 15px;
  83. border-top: 1px solid #eee;
  84. padding-top: 15px;
  85. }
  86.  
  87. #new-user-input {
  88. flex-grow: 1;
  89. padding: 5px 10px;
  90. border: 1px solid #ddd;
  91. border-radius: 3px;
  92. margin-right: 10px;
  93. }
  94.  
  95. #add-user-button {
  96. background-color: #4CAF50;
  97. color: white;
  98. border: none;
  99. padding: 5px 10px;
  100. border-radius: 3px;
  101. cursor: pointer;
  102. }
  103.  
  104. .remove-user {
  105. background-color: #f44336;
  106. color: white;
  107. border: none;
  108. padding: 3px 8px;
  109. border-radius: 3px;
  110. cursor: pointer;
  111. }
  112.  
  113. #run-blocker-button {
  114. background-color: #2196F3;
  115. color: white;
  116. border: none;
  117. padding: 8px 12px;
  118. border-radius: 3px;
  119. cursor: pointer;
  120. margin-top: 15px;
  121. width: 100%;
  122. }
  123.  
  124. .quick-block-btn {
  125. display: inline-block;
  126. margin-left: 5px;
  127. color: #f44336;
  128. cursor: pointer;
  129. font-weight: bold;
  130. font-size: 12px;
  131. padding: 0 5px;
  132. border-radius: 3px;
  133. opacity: 0.6;
  134. transition: opacity 0.2s;
  135. }
  136.  
  137. .quick-block-btn:hover {
  138. opacity: 1;
  139. background-color: #ffeeee;
  140. }
  141. `;
  142.  
  143. // Add the styles to the document
  144. document.head.appendChild(document.createElement('style')).textContent = css;
  145.  
  146. // Initial list of blocked users
  147. let blockedUsers = [
  148. 'zakrslejbuzik', 'ututyt', 'megafrajer', 'heslo', 'petr-metr',
  149. 'kral-dd-a-ndr', 'dodirikral', 'realfešák', 'velmimoudrymuz', 'velvysranec', ];
  150.  
  151. // Create toggle button
  152. const toggleButton = document.createElement('div');
  153. toggleButton.id = 'comment-blocker-toggle';
  154. toggleButton.textContent = '';
  155. document.body.appendChild(toggleButton);
  156.  
  157. // Create popup
  158. const popup = document.createElement('div');
  159. popup.id = 'comment-blocker-popup';
  160. popup.innerHTML = `
  161. <div id="comment-blocker-header">Blocked Users</div>
  162. <div id="comment-blocker-content">
  163. <div id="blocked-users-list"></div>
  164. <form id="add-user-form">
  165. <input type="text" id="new-user-input" placeholder="Username to block">
  166. <button type="submit" id="add-user-button">Add</button>
  167. </form>
  168. <button id="run-blocker-button">Apply Changes</button>
  169. </div>
  170. `;
  171. document.body.appendChild(popup);
  172.  
  173. // Toggle popup visibility
  174. toggleButton.addEventListener('click', () => {
  175. popup.classList.toggle('visible');
  176. });
  177.  
  178. // Populate blocked users list
  179. function updateBlockedUsersList() {
  180. const blockedUsersList = document.getElementById('blocked-users-list');
  181. blockedUsersList.innerHTML = '';
  182.  
  183. blockedUsers.forEach(user => {
  184. const userRow = document.createElement('div');
  185. userRow.className = 'blocked-user-row';
  186. userRow.innerHTML = `
  187. <span>${user}</span>
  188. <button class="remove-user" data-user="${user}">Remove</button>
  189. `;
  190. blockedUsersList.appendChild(userRow);
  191. });
  192.  
  193. // Add event listeners to remove buttons
  194. document.querySelectorAll('.remove-user').forEach(button => {
  195. button.addEventListener('click', (e) => {
  196. const userToRemove = e.target.getAttribute('data-user');
  197. blockedUsers = blockedUsers.filter(user => user !== userToRemove);
  198. updateBlockedUsersList();
  199. });
  200. });
  201. }
  202.  
  203. // Add new user form submission
  204. document.getElementById('add-user-form').addEventListener('submit', (e) => {
  205. e.preventDefault();
  206. const newUserInput = document.getElementById('new-user-input');
  207. const newUser = newUserInput.value.trim();
  208.  
  209. if (newUser && !blockedUsers.includes(newUser)) {
  210. blockedUsers.push(newUser);
  211. updateBlockedUsersList();
  212. newUserInput.value = '';
  213. }
  214. });
  215.  
  216. // Apply changes button
  217. document.getElementById('run-blocker-button').addEventListener('click', () => {
  218. blockComments();
  219. popup.classList.remove('visible');
  220. });
  221.  
  222. // Function to block comments from specified users
  223. function blockComments() {
  224. let blockedCount = 0;
  225.  
  226. // Find the comments section
  227. const commentsSection = document.getElementById('comments-wp');
  228. if (!commentsSection) return;
  229.  
  230. // Find the comment list
  231. const commentList = commentsSection.querySelector('.comment-list');
  232. if (!commentList) return;
  233.  
  234. // Process each blocked user
  235. blockedUsers.forEach(username => {
  236. // Find all comment elements from the blocked user
  237. // Format: .depth-1.thread-even.even.comment-author-zakrslejbuzik.byuser.comment
  238. const commentElements = commentList.querySelectorAll(`.comment-author-${username}.byuser.comment`);
  239.  
  240. commentElements.forEach(commentElement => {
  241. // Check if this element is visible before hiding it
  242. if (commentElement.style.display !== 'none') {
  243. // Store original display style for potential restoration
  244. commentElement.setAttribute('data-original-display', commentElement.style.display || 'block');
  245.  
  246. // Completely hide the comment
  247. commentElement.style.display = 'none';
  248.  
  249. blockedCount++;
  250. }
  251. });
  252. });
  253.  
  254. // Show notification only if comments were blocked
  255. if (blockedCount > 0) {
  256. const notification = document.createElement('div');
  257. notification.textContent = `${blockedCount} ${blockedCount !== 1 ? 's' : ''} `;
  258. 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;';
  259.  
  260. document.body.appendChild(notification);
  261.  
  262. // Remove notification after 5 seconds
  263. setTimeout(() => {
  264. if (notification.parentNode) {
  265. notification.parentNode.removeChild(notification);
  266. }
  267. }, 5000);
  268. }
  269. }
  270.  
  271. // Function to add quick block buttons to each username in comments
  272. function addQuickBlockButtons() {
  273. // Find the comments section
  274. const commentsSection = document.getElementById('comments-wp');
  275. if (!commentsSection) return;
  276.  
  277. // Find all comment author elements
  278. const authorElements = commentsSection.querySelectorAll('.comment-author');
  279.  
  280. authorElements.forEach(authorElement => {
  281. // Skip if we already added a button to this author
  282. if (authorElement.querySelector('.quick-block-btn')) return;
  283.  
  284. // Find the author name element (typically an <a> tag or similar)
  285. const authorLink = authorElement.querySelector('a, cite');
  286. if (!authorLink) return;
  287.  
  288. // Extract the username
  289. let username = '';
  290.  
  291. // Check if the comment has a class that indicates the author
  292. const commentElement = authorElement.closest('.comment');
  293. if (commentElement) {
  294. const classes = commentElement.className.split(' ');
  295. for (const className of classes) {
  296. if (className.startsWith('comment-author-')) {
  297. username = className.replace('comment-author-', '');
  298. break;
  299. }
  300. }
  301. }
  302.  
  303. // If we couldn't find username from class, try to extract from the text
  304. if (!username) {
  305. username = authorLink.textContent.trim().toLowerCase().replace(/\s+/g, '-');
  306. }
  307.  
  308. // Skip if username is empty or if we already have a block button
  309. if (!username || authorLink.nextElementSibling?.classList.contains('quick-block-btn')) return;
  310.  
  311. // Create the X button for quick blocking
  312. const blockButton = document.createElement('span');
  313. blockButton.className = 'quick-block-btn';
  314. blockButton.textContent = '';
  315. blockButton.title = `Block ${username}`;
  316. blockButton.setAttribute('data-username', username);
  317.  
  318. // Add click event to block the user
  319. blockButton.addEventListener('click', (e) => {
  320. e.preventDefault();
  321. e.stopPropagation();
  322.  
  323. const usernameToBlock = e.target.getAttribute('data-username');
  324.  
  325. // Add user to block list if not already there
  326. if (!blockedUsers.includes(usernameToBlock)) {
  327. blockedUsers.push(usernameToBlock);
  328. updateBlockedUsersList();
  329. blockComments();
  330.  
  331. // Show notification
  332. const notification = document.createElement('div');
  333. notification.textContent = `User "${usernameToBlock}" added to block list`;
  334. 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;';
  335.  
  336. document.body.appendChild(notification);
  337.  
  338. // Remove notification after 3 seconds
  339. setTimeout(() => {
  340. if (notification.parentNode) {
  341. notification.parentNode.removeChild(notification);
  342. }
  343. }, 3000);
  344. }
  345. });
  346.  
  347. // Insert the button after the author name
  348. authorLink.parentNode.insertBefore(blockButton, authorLink.nextSibling);
  349. });
  350. }
  351.  
  352. // Initialize the blocked users list
  353. updateBlockedUsersList();
  354.  
  355. // Run when the page loads
  356. window.addEventListener('load', () => {
  357. blockComments();
  358. addQuickBlockButtons();
  359. });
  360.  
  361. // Also run for dynamic content loading (if the site uses AJAX)
  362. const observer = new MutationObserver((mutations) => {
  363. for (const mutation of mutations) {
  364. if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
  365. // Check if any new comments were added
  366. setTimeout(() => {
  367. blockComments();
  368. addQuickBlockButtons();
  369. }, 500); // Small delay to ensure dynamic content is fully loaded
  370. break;
  371. }
  372. }
  373. });
  374.  
  375. // Start observing the body for changes
  376. observer.observe(document.body, { childList: true, subtree: true });
  377. })();
Tags: ddr block
Advertisement
Add Comment
Please, Sign In to add comment