Meklin Shutdownchat Script

Modified Shutdownchat, unmatched scripts, brace to be thunderstruck

当前为 2023-12-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Meklin Shutdownchat Script
  3. // @version 1.1
  4. // @description Modified Shutdownchat, unmatched scripts, brace to be thunderstruck
  5. // @author MeKLiN
  6. // @namespace https://greasyfork.org/en/scripts/483405-meklin-shutdownchat-script
  7. // @match https://www.shutdown.chat/rooms*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=shutdown.chat
  9. // @license MIT
  10. // @grant none
  11. // @exclude https://www.shutdown.chat/profiles*
  12. // @exclude https://www.shutdown.chat/manage*
  13. // @run-at document-start
  14. // @require https://cdnjs.cloudflare.com/ajax/libs/jshint/2.9.7/jshint.js
  15. // @require https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-shim.min.js
  16. // ==/UserScript==
  17. // ˚    ✦   .  .   ˚ .      . ✦     ˚     . ★⋆. ࿐࿔    .     ˚     *     ✦   .  .   ✦ ˚      ˚ .˚    ✦   .  .   ˚ .             ੈ✧̣̇˳·˖✶ ✦ ˚    ✦   .  .   ˚ .      . ✦     ˚     . ★⋆. ࿐࿔    .     ˚     *     ✦   .  .   ✦ ˚      ˚ .˚    ✦   .  .   ˚ .
  18. // 608972616881592", "473915865480751", "755327001444987" one of these is wally
  19. //
  20. // 956020454044026 sheets alt,
  21. // 648106985166944 reckful
  22. // 625401812235506 snail
  23. // 497479872276396 beema
  24. // 755327001444987 blurr
  25. // 200600422645641 woman
  26. // Add the uuids of the users you want to block here
  27. debugger;
  28. // alert("Hello from MeKLiN!");
  29.  
  30. // document.addEventListener('DOMContentLoaded', function() {
  31.  
  32. var blocked_uuids = JSON.parse(localStorage.getItem('blocked_uuids')) || [];
  33.  
  34. function getNickname(fcuserSpan) {
  35. if (!fcuserSpan) return;
  36.  
  37. // Check if fcuserSpan is a direct child of p
  38. var isDirectChild = fcuserSpan.parentNode.nodeName === "P";
  39. var nickname;
  40.  
  41. if (isDirectChild) {
  42. nickname = fcuserSpan.innerText.replace(/[:\-]/g, '').trim();
  43. } else {
  44. // If not a direct child, assume it's under an anchor tag (a) in the user list
  45. nickname = fcuserSpan.parentNode.querySelector('.fcuser').innerText.replace(/[:\-]/g, '').trim();
  46. }
  47.  
  48. return nickname;
  49. }
  50.  
  51. // Function to handle the new chat messages
  52. function handleNewChatMessages() {
  53. var chatboxElems = document.querySelector('.chatbox').getElementsByTagName('p');
  54. for (var i = 0; i < chatboxElems.length; i++) {
  55. var chatElem = chatboxElems[i];
  56. if (!chatElem.handled) {
  57. chatElem.handled = true;
  58. var fcuserSpan = chatElem.querySelector('.nm.fcuser');
  59. var uuid = fcuserSpan.dataset.uuid;
  60. if (blocked_uuids.includes(uuid)) {
  61. chatElem.style.display = 'none'; // hide the message
  62. }
  63. }
  64. }
  65. }
  66.  
  67. // Call the handleNewChatMessages function on page load and whenever the chatbox is updated
  68. handleNewChatMessages();
  69. document.querySelector('.chatbox').addEventListener('DOMNodeInserted', handleNewChatMessages);
  70.  
  71.  
  72. // Get the chatbox element
  73. var chatbox = document.querySelector(".chatbox");
  74.  
  75. // Create a mutation observer to monitor changes in the chatbox
  76. var observer = new MutationObserver(function(mutations) {
  77. // Loop through the added nodes
  78. mutations.forEach(function(mutation) {
  79. for (var i = 0; i < mutation.addedNodes.length; i++) {
  80. var node = mutation.addedNodes[i];
  81. // Check if the node is a chat message
  82. if (node.nodeName === "P" && node.dataset.t === "c") {
  83. // Get the uuid of the user who sent the message
  84. var uuid = node.querySelector(".nm.fcuser").dataset.uuid;
  85. // Check if the uuid is in the blocked list
  86. if (blocked_uuids.includes(uuid)) {
  87. // Hide the message
  88. node.style.display = "none";
  89. }
  90. }
  91. }
  92. });
  93. });
  94.  
  95. // Start observing the chatbox
  96. observer.observe(chatbox, {childList: true});
  97.  
  98. // Function to block/unblock a user
  99. function blockUser(uuid) {
  100. console.log("blockUser function is called");
  101. var index = blocked_uuids.indexOf(uuid);
  102. if (index !== -1) {
  103. // User is already blocked, so unblock
  104. blocked_uuids.splice(index, 1);
  105. alert("User unblocked!");
  106. } else {
  107. // User is not blocked, so block
  108. blocked_uuids.push(uuid);
  109. alert("User blocked!");
  110. }
  111.  
  112. // Save the updated blocked_uuids to localStorage
  113. localStorage.setItem('blocked_uuids', JSON.stringify(blocked_uuids));
  114. }
  115.  
  116. // Function to create a button to view the ignore list
  117. function createIgnoreListButton() {
  118. console.log("createIgnoreListButton function is called");
  119. var ignoreListButton = document.createElement("button");
  120. ignoreListButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="none" d="M0 0h24v24H0z"/><path d="M20 18V8a6 6 0 0 0-12 0v10h12zM12 2C6.48 2 2 6.48 2 12v10h2V12a5.978 5.978 0 0 1 5.985-6H12V2zm8.293 2.293a1 1 0 0 1 1.414 0l1.414 1.414a1 1 0 0 1 0 1.414L19.414 10l3.707 3.707a1 1 0 0 1 0 1.414l-1.414 1.414a1 1 0 0 1-1.414 0L18 13.414l-3.707 3.707a1 1 0 0 1-1.414 0l-1.414-1.414a1 1 0 0 1 0-1.414L14.586 12 10.88 8.293a1 1 0 0 1 0-1.414L12.294 5.465a1 1 0 0 1 1.414 0z"/></svg> View Ignore List`;
  121. ignoreListButton.style.position = "fixed";
  122. ignoreListButton.style.top = "10px";
  123. ignoreListButton.style.left = "10px";
  124. ignoreListButton.addEventListener("click", function () {
  125. // Display the ignore list (you can customize this part)
  126. alert("Ignore List:\n" + blocked_uuids.join(", "));
  127. });
  128.  
  129. document.body.appendChild(ignoreListButton);
  130. }
  131.  
  132. // Call the function to create the ignore list button
  133. createIgnoreListButton();
  134.  
  135.  
  136. // Get the user list element
  137. var userlist = document.querySelector(".userlist");
  138.  
  139. // Create the block and ignore buttons and append them to each user
  140. var users = userlist.querySelectorAll(".fcuser");
  141. users.forEach(function (user) {
  142. var uuid = user.dataset.uuid;
  143.  
  144. // Create the block button
  145. var blockButton = document.createElement("button");
  146. blockButton.innerText = "Block";
  147. blockButton.addEventListener("click", function() {
  148. blockUser(uuid);
  149. });
  150.  
  151. // Create the ignore button with a unique class
  152. var ignoreButton = document.createElement("button");
  153. ignoreButton.innerText = "Ignore";
  154. ignoreButton.setAttribute("data-btntype", "ignore"); // Set a new attribute for identification
  155. ignoreButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="16" height="16"><path fill="none" d="M0 0h24v24H0z"/><path d="M20 18V8a6 6 0 0 0-12 0v10h12zM12 2C6.48 2 2 6.48 2 12v10h2V12a5.978 5.978 0 0 1 5.985-6H12V2zm8.293 2.293a1 1 0 0 1 1.414 0l1.414 1.414a1 1 0 0 1 0 1.414L19.414 10l3.707 3.707a1 1 0 0 1 0 1.414l-1.414 1.414a1 1 0 0 1-1.414 0L18 13.414l-3.707 3.707a1 1 0 0 1-1.414 0l-1.414-1.414a1 1 0 0 1 0-1.414L14.586 12 10.88 8.293a1 1 0 0 1 0-1.414L12.294 5.465a1 1 0 0 1 1.414 0z"/></svg>`;
  156. ignoreButton.style.marginLeft = "5px";
  157. ignoreButton.style.cursor = "pointer";
  158. // Add a unique class to the ignore button
  159. ignoreButton.classList.add("ignoreButtonClass");
  160.  
  161. ignoreButton.addEventListener("click", function () {
  162. // Dynamically fetch the user UUID when the "Ignore" button is clicked
  163. var clickedUserUUID = user.dataset.uuid;
  164. blockUser(clickedUserUUID);
  165. });
  166.  
  167. // Create a container div for the buttons
  168. var buttonContainer = document.createElement("div");
  169. buttonContainer.style.display = "flex";
  170. buttonContainer.style.alignItems = "center";
  171.  
  172. // Append the buttons to the container
  173. buttonContainer.appendChild(blockButton);
  174. buttonContainer.appendChild(ignoreButton);
  175.  
  176. // Append the container to the user element
  177. user.parentElement.appendChild(buttonContainer);
  178. });
  179.  
  180. // usermenu block button event listener:
  181. document.querySelector('.usermenu button[data-btntype="block"]').addEventListener('click', function() {
  182. console.log("User menu block button clicked");
  183.  
  184. // Get the parent element of the button, assuming it contains user-related data
  185. var userContainer = this.closest('.user-container');
  186.  
  187. // Assuming the user UUID is stored in a data attribute called data-uuid
  188. var userUUID = userContainer.dataset.uuid;
  189.  
  190. // Now you have the user UUID, and you can proceed to block the user
  191. blockUser(userUUID);
  192. });
  193.  
  194. // Function to create an ignore button in the user menu
  195. function createIgnoreButton() {
  196. console.log("createIgnoreButton function is called");
  197.  
  198. var ignoreButton = document.createElement("button");
  199. ignoreButton.innerText = "Ignore";
  200. ignoreButton.setAttribute("data-btntype", "ignore"); // Set a new attribute for identification
  201. ignoreButton.style.display = "block";
  202. ignoreButton.style.marginTop = "5px"; // Adjust the styling as needed
  203.  
  204. // Insert the ignore button into the user menu
  205. var userMenu = document.querySelector('.usermenu');
  206. if (userMenu) {
  207. userMenu.insertBefore(ignoreButton, userMenu.firstChild);
  208.  
  209. // Add click event directly to the button
  210. ignoreButton.addEventListener("click", function () {
  211. // Log to console to check if the button click is being registered
  212. console.log("Ignore button clicked");
  213.  
  214. // Traverse the DOM to find the user UUID dynamically within FreeChat context
  215. var userUUID = getUserUUIDFromUserList();
  216.  
  217. // Check if the user UUID is found
  218. if (userUUID) {
  219. blockUser(userUUID);
  220. } else {
  221. console.error("User UUID not found. Ignoring user without blocking.");
  222. }
  223. });
  224. } else {
  225. console.error("User menu not found.");
  226. }
  227. }
  228.  
  229. // Function to get the user UUID from the user list within FreeChat context
  230. function getUserUUIDFromUserList() {
  231. var userContainer = document.querySelector("#chat > div.fc > div.gridbox_list > div.userlist p.user.fcuser[data-uuid]");
  232.  
  233. if (userContainer) {
  234. return userContainer.dataset.uuid;
  235. } else {
  236. // If user container is not found, set up a MutationObserver to wait for changes
  237. var observer = new MutationObserver(function (mutations) {
  238. userContainer = document.querySelector("#chat > div.fc > div.gridbox_list > div.userlist p.user.fcuser[data-uuid]");
  239. if (userContainer) {
  240. console.log("User container found after mutation.");
  241. console.log("User UUID: ", userContainer.dataset.uuid);
  242. // Stop observing once the user container is found
  243. observer.disconnect();
  244. }
  245. });
  246.  
  247. // Start observing changes in the user list
  248. observer.observe(document.querySelector("#chat > div.fc > div.gridbox_list > div.userlist"), { childList: true, subtree: true });
  249.  
  250. console.error("User container not found in the user list within FreeChat context. Waiting for mutations...");
  251. return null;
  252. }
  253. }
  254.  
  255. // Call the function to create the ignore button in the user menu
  256. createIgnoreButton();
  257.  
  258. // Create the ignore list div once and append the content dynamically
  259. var ignoreListDiv = document.createElement("div");
  260. ignoreListDiv.style.position = "fixed";
  261. ignoreListDiv.style.top = "10px";
  262. ignoreListDiv.style.left = "10px";
  263. ignoreListDiv.style.backgroundColor = "white"; // Adjust styling as needed
  264. ignoreListDiv.style.padding = "10px";
  265. ignoreListDiv.style.border = "1px solid black"; // Add border for visibility
  266.  
  267. // Create a heading for the ignore list
  268. var ignoreListHeading = document.createElement("h3");
  269. ignoreListHeading.innerText = "Ignore List";
  270. ignoreListDiv.appendChild(ignoreListHeading);
  271.  
  272. // Create a list to display ignored users
  273. var ignoreList = document.createElement("ul");
  274. ignoreList.style.listStyleType = "none"; // Remove default list styling
  275. ignoreListDiv.appendChild(ignoreList);
  276.  
  277. // Append the ignore list div to the body
  278. document.body.appendChild(ignoreListDiv);
  279.  
  280. // Function to create a list item with the ignore list entry and remove button
  281. function createIgnoreListItem(uuid) {
  282. var listItem = document.createElement("li");
  283. listItem.innerText = uuid;
  284.  
  285. // Create a remove button for each entry
  286. var removeButton = document.createElement("button");
  287. removeButton.innerText = "Remove";
  288. removeButton.addEventListener("click", function () {
  289. // Remove the entry when the button is clicked
  290. removeIgnoreEntry(uuid);
  291. });
  292.  
  293. // Append the remove button to the list item
  294. listItem.appendChild(removeButton);
  295.  
  296. // Append the list item to the ignore list
  297. ignoreList.appendChild(listItem);
  298. }
  299.  
  300. // Populate the ignore list with entries and remove buttons
  301. blocked_uuids.forEach(function (uuid) {
  302. var listItem = document.createElement("li");
  303. listItem.innerText = uuid;
  304.  
  305. // Create a remove button for each entry
  306. var removeButton = document.createElement("button");
  307. removeButton.innerText = "Remove";
  308. removeButton.addEventListener("click", function () {
  309. // Remove the entry when the button is clicked
  310. removeIgnoreEntry(uuid);
  311. });
  312.  
  313. // Append the remove button to the list item
  314. listItem.appendChild(removeButton);
  315.  
  316. // Append the list item to the ignore list
  317. ignoreList.appendChild(listItem);
  318. });
  319.  
  320. // Function to refresh the ignore list display
  321. function refreshIgnoreList() {
  322. // Clear the existing content
  323. ignoreList.innerHTML = "";
  324.  
  325. // Populate the ignore list with entries and remove buttons
  326. blocked_uuids.forEach(function (uuid) {
  327. createIgnoreListItem(uuid);
  328. });
  329. }
  330.  
  331. // Function to handle removing an entry from the ignore list
  332. function removeIgnoreEntry(uuid) {
  333. var index = blocked_uuids.indexOf(uuid);
  334. if (index !== -1) {
  335. // Remove the entry from the ignore list
  336. blocked_uuids.splice(index, 1);
  337. // Refresh the ignore list display after removal
  338. refreshIgnoreList();
  339. }
  340. }
  341.  
  342. // Function to save blocked_uuids to a text file
  343. function saveToTextFile() {
  344. var textToSave = blocked_uuids.join('\n');
  345. var blob = new Blob([textToSave], { type: 'text/plain' });
  346. var link = document.createElement('a');
  347. link.download = 'ignore_list.txt';
  348. link.href = window.URL.createObjectURL(blob);
  349. link.onclick = function () {
  350. document.body.removeChild(link);
  351. };
  352. link.style.display = 'none';
  353. document.body.appendChild(link);
  354. link.click();
  355. }
  356.  
  357. // Function to load blocked_uuids from a text file
  358. function loadFromTextFile() {
  359. var input = document.createElement('input');
  360. input.type = 'file';
  361. input.accept = '.txt';
  362. input.onchange = function (event) {
  363. var file = event.target.files[0];
  364. if (file) {
  365. var reader = new FileReader();
  366. reader.onload = function (e) {
  367. // Parse the content of the file and update blocked_uuids
  368. blocked_uuids = e.target.result.split('\n').map(function (uuid) {
  369. return uuid.trim();
  370. });
  371. // Update the ignore list display
  372. refreshIgnoreList();
  373. };
  374. reader.readAsText(file);
  375. }
  376. };
  377. input.click();
  378. }
  379.  
  380. // ... (rest of your code)
  381.  
  382. // Function to create a button to save and load ignore list
  383. function createSaveLoadButtons() {
  384. var saveButton = document.createElement("button");
  385. saveButton.innerText = "Save to Text File";
  386. saveButton.addEventListener("click", function () {
  387. saveToTextFile();
  388. });
  389.  
  390. var loadButton = document.createElement("button");
  391. loadButton.innerText = "Load from Text File";
  392. loadButton.addEventListener("click", function () {
  393. loadFromTextFile();
  394. });
  395.  
  396. var buttonContainer = document.createElement("div");
  397. buttonContainer.style.marginTop = "10px";
  398. buttonContainer.appendChild(saveButton);
  399. buttonContainer.appendChild(loadButton);
  400.  
  401. // Append the button container to the ignore list div
  402. ignoreListDiv.appendChild(buttonContainer);
  403. }
  404.  
  405. // Call the function to create the save and load buttons
  406. createSaveLoadButtons();