Advertisement
MeKLiN2

Untitled

Dec 29th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 KB | None | 0 0
  1. // ==UserScript==
  2. // @name MSS
  3. // @namespace http://tampermonkey.net/
  4. // @version 2023-12-29
  5. // @description Meklin Shutdownchat Script
  6. // @author MeKLiN
  7. // @match https://www.shutdown.chat/rooms/downtown
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=shutdown.chat
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. // Get the ignore list from the storage, or use an empty array as the default value
  16. var blocked_uuids = GM_getValue("ignore_list", []);
  17.  
  18. // Get the chatbox element
  19. var chatbox = document.querySelector(".chatbox");
  20.  
  21. // Create a mutation observer to monitor changes in the chatbox
  22. var observer = new MutationObserver(function(mutations) {
  23. // Loop through the added nodes
  24. mutations.forEach(function(mutation) {
  25. for (var i = 0; i < mutation.addedNodes.length; i++) {
  26. var node = mutation.addedNodes[i];
  27. // Check if the node is a chat message
  28. if (node.nodeName === "P" && node.dataset.t === "c") {
  29. // Get the uuid of the user who sent the message
  30. var uuid = node.querySelector(".nm.fcuser").dataset.uuid;
  31. // Check if the uuid is in the blocked list
  32. if (blocked_uuids.includes(uuid)) {
  33. // Hide the message
  34. node.style.display = "none";
  35. }
  36. }
  37. }
  38. });
  39. });
  40.  
  41. // Start observing the chatbox
  42. observer.observe(chatbox, {childList: true});
  43.  
  44. // Add a user's uuid to the ignore list, and store it in the storage
  45. function addToIgnoreList(uuid) {
  46. // Check if the uuid is already in the ignore list
  47. if (!blocked_uuids.includes(uuid)) {
  48. // Add the uuid to the ignore list
  49. blocked_uuids.push(uuid);
  50. // Store the ignore list in the storage
  51. GM_setValue("ignore_list", blocked_uuids);
  52. }
  53. }
  54.  
  55. // Create a button element for each user in the user list, and set its data-uuid attribute and click event listener
  56. function createIgnoreButton(user) {
  57. // Create a button element
  58. var button = document.createElement("button");
  59. // Set the button text
  60. button.textContent = "Ignore";
  61. // Set the button data-uuid attribute to the same value as the user element
  62. button.dataset.uuid = user.dataset.uuid;
  63. // Set the button click event listener
  64. button.addEventListener("click", function() {
  65. // Get the uuid from the button data-uuid attribute
  66. var uuid = this.dataset.uuid;
  67. // Add the uuid to the ignore list
  68. addToIgnoreList(uuid);
  69. // Hide the user element
  70. user.style.display = "none";
  71. // Hide the user's messages
  72. hideUserMessages(uuid);
  73. });
  74. // Return the button element
  75. return button;
  76. }
  77.  
  78. // Hide the user's messages by uuid
  79. function hideUserMessages(uuid) {
  80. // Get all the chat messages
  81. var chatMessages = chatbox.querySelectorAll("p[data-t='c']");
  82. // Loop through the chat messages
  83. for (var i = 0; i < chatMessages.length; i++) {
  84. var message = chatMessages[i];
  85. // Get the uuid of the user who sent the message
  86. var messageUuid = message.querySelector(".nm.fcuser").dataset.uuid;
  87. // Check if the uuid matches the one to hide
  88. if (messageUuid === uuid) {
  89. // Hide the message
  90. message.style.display = "none";
  91. }
  92. }
  93. }
  94.  
  95. // Create a mutation observer to monitor changes in the user menu
  96. var userMenuObserver = new MutationObserver(function(mutations) {
  97. // Loop through the mutations
  98. mutations.forEach(function(mutation) {
  99. // Check if the user menu is visible
  100. if (mutation.target.style.display !== 'none') {
  101. // Get the user element
  102. var user = mutation.target.querySelector("h1");
  103. // Create the button element
  104. var button = createIgnoreButton(user);
  105. // Set the button z-index to 1
  106. button.style.zIndex = "1";
  107. // Set the button style to make it bigger
  108. button.style.fontSize = "20px";
  109. button.style.padding = "10px";
  110. // Append the button element to the user menu
  111. mutation.target.appendChild(button);
  112. }
  113. });
  114. });
  115.  
  116. // Get the user menu element
  117. var userMenu = document.querySelector(".usermenu");
  118.  
  119. // Start observing the user menu
  120. userMenuObserver.observe(userMenu, {attributes: true, attributeFilter: ['style']});
  121.  
  122. // Create a symbol element that can show the ignore list
  123. function createIgnoreSymbol() {
  124. // Create a symbol element
  125. var symbol = document.createElement("span");
  126. // Set the symbol text to an eye with a slash icon
  127. symbol.textContent = "🙈";
  128. // Set the symbol title to "Show ignore list"
  129. symbol.title = "Show ignore list";
  130. // Set the symbol style
  131. symbol.style.cursor = "pointer";
  132. symbol.style.marginLeft = "0.5em";
  133. // Set the symbol click event listener
  134. symbol.addEventListener("click", function() {
  135. // Toggle the visibility of the ignore list
  136. toggleIgnoreList();
  137. });
  138. // Return the symbol element
  139. return symbol;
  140. }
  141.  
  142. // Create a div element that can display the ignore list
  143. function createIgnoreList() {
  144. // Create a div element
  145. var list = document.createElement("div");
  146. // Set the list id to "ignore-list"
  147. list.id = "ignore-list";
  148. // Set the list style
  149. list.style.position = "fixed";
  150. list.style.top = "0";
  151. list.style.right = "0";
  152. list.style.width = "300px";
  153. list.style.height = "100%";
  154. list.style.backgroundColor = "white";
  155. list.style.borderLeft = "1px solid black";
  156. list.style.overflowY = "auto";
  157. list.style.zIndex = "9999";
  158. list.style.display = "none";
  159. // Set the list content
  160. list.innerHTML = "<h3>Ignore List</h3><ul></ul>";
  161. // Return the list element
  162. return list;
  163. }
  164.  
  165. // Toggle the visibility of the ignore list
  166. function toggleIgnoreList() {
  167. // Get the ignore list element
  168. var list = document.getElementById("ignore-list");
  169. // Check if the list is hidden
  170. if (list.style.display === "none") {
  171. // Show the list
  172. list.style.display = "block";
  173. // Update the list content
  174. updateIgnoreList();
  175. } else {
  176. // Hide the list
  177. list.style.display = "none";
  178. }
  179. }
  180.  
  181. // Update the list content with the ignore list
  182. function updateIgnoreList() {
  183. // Get the ignore list element
  184. var list = document.getElementById("ignore-list");
  185. // Get the list ul element
  186. var ul = list.querySelector("ul");
  187. // Clear the ul content
  188. ul.innerHTML = "";
  189. // Loop through the ignore list
  190. for (var i = 0; i < blocked_uuids.length; i++) {
  191. var uuid = blocked_uuids[i];
  192. // Create a li element
  193. var li = document.createElement("li");
  194. // Set the li text to the uuid
  195. li.textContent = uuid;
  196. // Append the li element to the ul element
  197. ul.appendChild(li);
  198. }
  199. }
  200.  
  201. // Call the function when the page loads
  202. window.addEventListener('load', addIgnoreButtons);
  203.  
  204. // Append the symbol element and the list element to the document body
  205. document.body.appendChild(createIgnoreSymbol());
  206. document.body.appendChild(createIgnoreList());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement