Meklin Shutdownchat Script

Modified Shutdownchat, unmatched scripts, brace to be thunderstruck

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

  1. // ==UserScript==
  2. // @name Meklin Shutdownchat Script
  3. // @version 1.5
  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. console.log("MSS 1.1 STARTED");
  18. debugger;
  19.  
  20. // Function to create a button to clear the JSON local saved cache
  21. function createClearCacheButton() {
  22. console.log("createClearCacheButton function is called");
  23.  
  24. var clearCacheButton = document.createElement("button");
  25. clearCacheButton.innerText = "clr";
  26. clearCacheButton.style.position = "fixed";
  27. clearCacheButton.style.top = "50px";
  28. clearCacheButton.style.left = "10px";
  29. clearCacheButton.addEventListener("click", function () {
  30. // Clear the JSON local saved cache
  31. localStorage.removeItem('blocked_uuids');
  32. showNotification("Cache cleared. Please refresh the page.");
  33. });
  34.  
  35. // Check if the body is available
  36. if (document.body) {
  37. // Append the clearCacheButton to the body
  38. document.body.appendChild(clearCacheButton);
  39. } else {
  40. // If the body is not available, wait for DOMContentLoaded event
  41. document.addEventListener("DOMContentLoaded", function () {
  42. // Append the clearCacheButton to the body
  43. document.body.appendChild(clearCacheButton);
  44. });
  45. }
  46. }
  47.  
  48. // Call the function to create the clear cache button
  49. createClearCacheButton();
  50.  
  51. // Function to create a button to collapse the view
  52. function createCollapseButton() {
  53. console.log("createCollapseButton function is called");
  54. var collapseButton = document.createElement("button");
  55.  
  56. // Set the inner HTML with an SVG and additional text
  57. collapseButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
  58. <path fill="none" d="M0 0h24v24H0z"/>
  59. <path d="M8 4v5l-2.5-1.5L3 9V4l5-2zm8 0l5 2v5l-2.5-1.5L16 9V4zM3 11l3.5-1.5L8 11V9L3 7zm13 0l3.5-1.5L21 11V9l-5-2z"/>
  60. </svg>min`;
  61.  
  62. // Adjust the font size of the text
  63. collapseButton.style.fontSize = "12px"; // Adjust the font size as needed
  64.  
  65. collapseButton.style.position = "fixed";
  66. collapseButton.style.top = "90px";
  67. collapseButton.style.left = "10px";
  68.  
  69. // Function to append the button to the body
  70. function appendButtonToBody() {
  71. document.body.appendChild(collapseButton);
  72. }
  73.  
  74. // Check if the body is available
  75. if (document.body) {
  76. // Append the collapseButton to the body
  77. appendButtonToBody();
  78. } else {
  79. // If the body is not available, wait for DOMContentLoaded event
  80. document.addEventListener("DOMContentLoaded", appendButtonToBody);
  81. }
  82.  
  83. collapseButton.addEventListener("click", function () {
  84. // Toggle visibility of the chatbox
  85. var chatbox = document.querySelector('.chatbox');
  86. chatbox.style.display = (chatbox.style.display === 'none' || chatbox.style.display === '') ? 'block' : 'none';
  87. });
  88.  
  89. // Get the chatbox element after creating the button
  90. var chatbox = document.querySelector('.chatbox');
  91.  
  92. // Check if the chatbox element is found
  93. if (chatbox) {
  94. // Initialize the observer if not already initialized
  95. if (!observer) {
  96. observer = new MutationObserver(function (mutations) {
  97. // Handle mutations
  98. console.log("Mutations:", mutations);
  99. // You can add your logic to handle mutations here
  100. });
  101. }
  102.  
  103. // Start observing the chatbox
  104. observer.observe(chatbox, { childList: true });
  105. } else {
  106. console.error("Chatbox element not found. Cannot add event listener.");
  107. }
  108. }
  109.  
  110. // Call the function to create the collapse button
  111. createCollapseButton();
  112.  
  113. var blocked_uuids = JSON.parse(localStorage.getItem('blocked_uuids')) || [];
  114.  
  115. function getNickname(fcuserSpan) {
  116. if (!fcuserSpan) return;
  117.  
  118. // Check if fcuserSpan is a direct child of p
  119. var isDirectChild = fcuserSpan.parentNode.nodeName === "P";
  120. var nickname;
  121.  
  122. if (isDirectChild) {
  123. nickname = fcuserSpan.innerText.replace(/[:\-]/g, '').trim();
  124. } else {
  125. // If not a direct child, assume it's under an anchor tag (a) in the user list
  126. nickname = fcuserSpan.parentNode.querySelector('.fcuser').innerText.replace(/[:\-]/g, '').trim();
  127. }
  128.  
  129. return nickname;
  130. }
  131.  
  132. // Function to handle the new chat messages
  133. function handleNewChatMessages() {
  134. // Get the chatbox element
  135. var chatbox = document.querySelector('.chatbox');
  136.  
  137. if (!chatbox) {
  138. console.error("Chatbox element not found. Cannot add event listener.");
  139. return;
  140. }
  141.  
  142. // Continue with handling new chat messages
  143. var chatboxElems = chatbox.getElementsByTagName('p');
  144. for (var i = 0; i < chatboxElems.length; i++) {
  145. var chatElem = chatboxElems[i];
  146. if (!chatElem.handled) {
  147. chatElem.handled = true;
  148.  
  149.  
  150.  
  151. // Remove text containing 'roll'
  152. if (chatElem.textContent.toLowerCase().includes('roll')) {
  153. chatElem.style.display = 'none'; // hide the message
  154. }
  155.  
  156. // Alter messages of the type .fs_3
  157. if (chatElem.classList.contains('fs_3')) {
  158. chatElem.style.fontSize = '12px';
  159. chatElem.style.color = 'white';
  160. }
  161.  
  162. // Check if the user is ignored
  163. var fcuserSpan = chatElem.querySelector('.nm.fcuser, .nm.fcmod, .user');
  164. var uuid = fcuserSpan ? fcuserSpan.dataset.uuid : null;
  165. console.log("fcuserSpan:", fcuserSpan); // Add this line to log fcuserSpan
  166. console.log("uuid:", uuid); // Add this line to log uuid
  167.  
  168. if (uuid) {
  169. // Check if the user is ignored
  170. var isIgnored = blocked_uuids.includes(uuid);
  171.  
  172. // Modify the appearance based on whether the user is ignored or not
  173. if (isIgnored) {
  174. chatElem.style.display = 'none'; // hide the message
  175. } else {
  176. // Add an "ignore" button to the user menu
  177. addIgnoreButtonToUserMenu(uuid);
  178. }
  179. }
  180. }
  181. }
  182. }
  183.  
  184. // Function to add an "ignore" button to the user menu
  185. function addIgnoreButtonToUserMenu(chatElem) {
  186. // Check if the user menu exists
  187. var userMenu = document.querySelector('.usermenu');
  188.  
  189. if (userMenu && chatElem && chatElem.querySelector) {
  190. // Check if the user is already ignored
  191. var uuid = chatElem.querySelector('.nm.fcuser, .nm.fcmod')?.dataset.uuid;
  192. var isIgnored = blocked_uuids.includes(uuid);
  193.  
  194. // Create a button for either ignoring or unignoring the user
  195. var ignoreButton = document.createElement('button');
  196. ignoreButton.textContent = isIgnored ? 'Unignore' : 'Ignore';
  197.  
  198. // Add an event listener to handle ignoring/unignoring the user
  199. ignoreButton.addEventListener('click', function () {
  200. if (isIgnored) {
  201. // Unignore the user
  202. unignoreUser(uuid);
  203. } else {
  204. // Ignore the user
  205. ignoreUser(uuid);
  206. }
  207. });
  208.  
  209. // Append the button to the user menu
  210. userMenu.appendChild(ignoreButton);
  211. } else {
  212. console.error("Invalid userMenu, chatElem, or querySelector is not supported. Conditions: userMenu=" + userMenu + ", chatElem=" + chatElem + ", chatElem.querySelector=" + (chatElem ? chatElem.querySelector : null));
  213. }
  214. }
  215.  
  216. // Function to observe mutations in the chatbox
  217. function observeChatboxMutations() {
  218. var chatbox = document.querySelector('.chatbox');
  219.  
  220. if (chatbox instanceof Node) {
  221. // Create a mutation observer to monitor changes in the chatbox
  222. var observer = new MutationObserver(function (mutations) {
  223. mutations.forEach(function (mutation) {
  224. mutation.addedNodes.forEach(function (node) {
  225. if (node.nodeName === "P" && node.dataset.t === "c") {
  226. // Your logic for handling new chat messages goes here
  227. }
  228. });
  229. });
  230. });
  231.  
  232. // Start observing the chatbox
  233. observer.observe(chatbox, { childList: true });
  234. } else {
  235. console.error("Chatbox element not found or is not a valid Node. Cannot add event listener.");
  236. }
  237. }
  238.  
  239. // Wait for the DOM to be fully loaded before setting up the MutationObserver
  240. document.addEventListener('DOMContentLoaded', function () {
  241. // Call the initial function to start handling new chat messages
  242. handleNewChatMessages();
  243.  
  244. // Call the function to observe mutations in the chatbox
  245. observeChatboxMutations();
  246. });
  247.  
  248.  
  249. // Function to ignore a user
  250. function ignoreUser(uuid) {
  251. // Add your logic here to handle ignoring a user
  252. // For example, you can add the user's UUID to the blocked_uuids array
  253. blocked_uuids.push(uuid);
  254.  
  255. // Save the updated blocked_uuids to localStorage
  256. localStorage.setItem('blocked_uuids', JSON.stringify(blocked_uuids));
  257.  
  258. // You can also add additional logic as needed
  259. console.log("Ignoring user with UUID:", uuid);
  260. }
  261.  
  262. // Function to unignore a user
  263. function unignoreUser(uuid) {
  264. blocked_uuids = blocked_uuids.filter(function (blockedUuid) {
  265. return blockedUuid !== uuid;
  266. });
  267. // Add additional logic as needed
  268. console.log("Unignoring user with UUID:", uuid);
  269. }
  270.  
  271. // Call the initial function to start handling new chat messages
  272. handleNewChatMessages();
  273.  
  274. // Get the chatbox element
  275. var chatbox = document.querySelector(".chatbox");
  276.  
  277. // Log the chatbox element to the console
  278. console.log("Chatbox element:", chatbox);
  279.  
  280. // Check if the chatbox element is found
  281. if (chatbox instanceof Node) {
  282. // Check if the chatbox element is found
  283. if (!observer) {
  284. observer = new MutationObserver(function (mutations) {
  285. // Handle mutations
  286. console.log("Mutations:", mutations);
  287. // You can add your logic to handle mutations here
  288. });
  289. }
  290.  
  291. // Start observing the chatbox
  292. observer.observe(chatbox, { childList: true });
  293. } else {
  294. console.error("Chatbox element not found or is not a valid Node. Cannot add event listener.");
  295. }
  296.  
  297. // Function to get the user UUID from a chat message
  298. function getUserUUIDFromChatMessage(messageNode) {
  299. var uuidElement = messageNode.querySelector('.nm.fcuser, .nm.fcmod');
  300. if (uuidElement) {
  301. return uuidElement.dataset.uuid;
  302. } else {
  303. console.error("UUID element not found in the chat message:", messageNode);
  304. return null;
  305. }
  306. }
  307.  
  308. // Function to handle different types of chat messages
  309. function handleChatMessage(node) {
  310. // Check if the node is a chat message
  311. if (node.nodeName === "P" && node.dataset.t === "c") {
  312. // Get the uuid of the user who sent the message
  313. var uuid = getUserUUIDFromChatMessage(node);
  314. if (uuid) {
  315. console.log("Found message with UUID:", uuid);
  316.  
  317. // Check if the uuid is in the blocked list
  318. if (blocked_uuids.includes(uuid)) {
  319. console.log("Blocking message with UUID:", uuid);
  320. // Hide the message
  321. node.style.display = "none";
  322. } else {
  323. // Alter messages of the type .fs_3
  324. if (node.classList.contains('fs_3')) {
  325. node.style.fontSize = '12px';
  326. node.style.color = 'white';
  327. }
  328.  
  329. // Add an "ignore" button to the user menu
  330. addIgnoreButtonToUserMenu(node);
  331. }
  332. }
  333. } else if (node.nodeName === "P" && node.querySelector(".sysmsg.fcsys")) {
  334. // Handle system messages
  335. handleSystemMessage(node);
  336. }
  337. }
  338.  
  339. // Function to handle system messages
  340. function handleSystemMessage(systemNode) {
  341. // Move system messages to the bottom right in their own DIV
  342. var systemDiv = document.createElement("div");
  343. systemDiv.className = "system-message";
  344. systemDiv.style.position = "fixed";
  345. systemDiv.style.bottom = "10px";
  346. systemDiv.style.right = "10px";
  347. systemDiv.style.backgroundColor = "#f0f0f0";
  348. systemDiv.style.padding = "10px";
  349. systemDiv.appendChild(systemNode.cloneNode(true));
  350. document.body.appendChild(systemDiv);
  351. }
  352.  
  353. // Create a mutation observer to monitor changes in the chatbox
  354. var observer = new MutationObserver(function (mutations) {
  355. mutations.forEach(function (mutation) {
  356. mutation.addedNodes.forEach(function (node) {
  357. handleChatMessage(node);
  358. // Check if the node is a chat message
  359. if (node.nodeName === "P" && node.dataset.t === "c") {
  360. // Get the uuid of the user who sent the message
  361. var uuid = getUserUUIDFromChatMessage(node);
  362. if (uuid) {
  363. console.log("Found message with UUID:", uuid);
  364.  
  365. // Check if the uuid is in the blocked list
  366. if (blocked_uuids.includes(uuid)) {
  367. console.log("Blocking message with UUID:", uuid);
  368. // Hide the message
  369. node.style.display = "none";
  370. } else {
  371. // Alter messages of the type .fs_3
  372. if (node.classList.contains('fs_3')) {
  373. node.style.fontSize = '12px';
  374. node.style.color = 'white';
  375. }
  376.  
  377. // Add an "ignore" button to the user menu
  378. addIgnoreButtonToUserMenu(node);
  379. }
  380. }
  381. }
  382. });
  383. });
  384. });
  385.  
  386.  
  387. // Start observing the chatbox
  388. observer.observe(chatbox, { childList: true });
  389.  
  390.  
  391.  
  392. // Function to show a notification
  393. function showNotification(message) {
  394. var notification = document.createElement("div");
  395. notification.innerHTML = `<div style="position: fixed; bottom: 10px; left: 10px; background-color: #000000; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 12px; color: #C0FF00; opacity: 1; transition: opacity 2s ease-in-out;">${message}</div>`;
  396. document.body.appendChild(notification);
  397.  
  398. // Set a timeout to fade out the notification
  399. setTimeout(function () {
  400. notification.style.opacity = 0;
  401. }, 2000); // Adjust the timeout value as needed
  402.  
  403. // Remove the notification from the DOM after fading out
  404. setTimeout(function () {
  405. document.body.removeChild(notification);
  406. }, 3000); // Adjust the timeout value to match the fade-out duration
  407. }
  408.  
  409. // Function to block/unblock a user
  410. function blockUser(uuid) {
  411. console.log("blockUser function is called");
  412. var index = blocked_uuids.indexOf(uuid);
  413. if (index !== -1) {
  414. // User is already blocked, so unblock
  415. blocked_uuids.splice(index, 1);
  416. showNotification("User unblocked!");
  417. } else {
  418. // User is not blocked, so block
  419. blocked_uuids.push(uuid);
  420. showNotification("User blocked!");
  421. }
  422.  
  423. // Save the updated blocked_uuids to localStorage
  424. localStorage.setItem('blocked_uuids', JSON.stringify(blocked_uuids));
  425. }
  426.  
  427. // Function to create a button to view the ignore list
  428. function createIgnoreListButton() {
  429. console.log("createIgnoreListButton function is called");
  430. var ignoreListButton = document.createElement("button");
  431. 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>lst`;
  432. ignoreListButton.style.position = "fixed";
  433. ignoreListButton.style.top = "10px";
  434. ignoreListButton.style.left = "10px";
  435. ignoreListButton.addEventListener("click", function () {
  436. // Display the ignore list (you can customize this part)
  437. alert("Ignore List:\n" + blocked_uuids.join(", "));
  438. });
  439.  
  440. document.body.appendChild(ignoreListButton);
  441. }
  442.  
  443. // Call the function to create the ignore list button
  444. createIgnoreListButton();
  445.  
  446.  
  447. // Get the user list element
  448. var userlist = document.querySelector(".userlist");
  449.  
  450. // Create the block and ignore buttons and append them to each user
  451. var users = userlist.querySelectorAll(".fcuser");
  452. users.forEach(function (user) {
  453. var uuid = user.dataset.uuid;
  454.  
  455. // Create the block button
  456. var blockButton = document.createElement("button");
  457. blockButton.innerText = "Block";
  458. blockButton.addEventListener("click", function() {
  459. blockUser(uuid);
  460. });
  461.  
  462. // Create the ignore button with a unique class
  463. var ignoreButton = document.createElement("button");
  464. ignoreButton.innerText = "Ignore";
  465. ignoreButton.setAttribute("data-btntype", "ignore"); // Set a new attribute for identification
  466. 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>`;
  467. ignoreButton.style.marginLeft = "5px";
  468. ignoreButton.style.cursor = "pointer";
  469. // Add a unique class to the ignore button
  470. ignoreButton.classList.add("ignoreButtonClass");
  471.  
  472. ignoreButton.addEventListener("click", function () {
  473. // Dynamically fetch the user UUID when the "Ignore" button is clicked
  474. var clickedUserUUID = user.dataset.uuid;
  475. blockUser(clickedUserUUID);
  476. });
  477.  
  478. // Create a container div for the buttons
  479. var buttonContainer = document.createElement("div");
  480. buttonContainer.style.display = "flex";
  481. buttonContainer.style.alignItems = "center";
  482.  
  483. // Append the buttons to the container
  484. buttonContainer.appendChild(blockButton);
  485. buttonContainer.appendChild(ignoreButton);
  486.  
  487. // Append the container to the user element
  488. user.parentElement.appendChild(buttonContainer);
  489. });
  490.  
  491. // usermenu block button event listener:
  492. document.querySelector('.usermenu button[data-btntype="block"]').addEventListener('click', function() {
  493. console.log("User menu block button clicked");
  494.  
  495. // Get the parent element of the button, assuming it contains user-related data
  496. var userContainer = this.closest('.user-container');
  497.  
  498. // Assuming the user UUID is stored in a data attribute called data-uuid
  499. var userUUID = userContainer ? userContainer.dataset.uuid : null;
  500.  
  501. // Check if userUUID is not null before blocking
  502. if (userUUID) {
  503. // Now you have the user UUID, and you can proceed to block the user
  504. blockUser(userUUID);
  505. } else {
  506. console.error("User UUID not found. Unable to block user.");
  507. }
  508. });
  509.  
  510. // Function to create an ignore button in the user menu
  511. function createIgnoreButton() {
  512. console.log("createIgnoreButton function is called");
  513.  
  514. // Check if the ignore button is already created
  515. var ignoreButton = document.querySelector('.usermenu button[data-btntype="ignore"]');
  516.  
  517. if (!ignoreButton) {
  518. ignoreButton = document.createElement("button");
  519. ignoreButton.innerText = "Ignore";
  520. ignoreButton.setAttribute("data-btntype", "ignore"); // Set a new attribute for identification
  521. ignoreButton.style.display = "block";
  522. ignoreButton.style.marginTop = "5px"; // Adjust the styling as needed
  523.  
  524. // Insert the ignore button into the user menu
  525. var userMenu = document.querySelector('.usermenu');
  526. if (userMenu) {
  527. userMenu.insertBefore(ignoreButton, userMenu.firstChild);
  528.  
  529. // Add click event directly to the button
  530. ignoreButton.addEventListener("click", function () {
  531. // Log to console to check if the button click is being registered
  532. console.log("Ignore button clicked");
  533.  
  534. // Invoke the function to get the user UUID from the user list
  535. var userUUID = getUserUUIDFromUserList();
  536.  
  537. // Check if the user UUID is found
  538. if (userUUID) {
  539. blockUser(userUUID);
  540. } else {
  541. console.error("User UUID not found. Ignoring user without blocking.");
  542. }
  543. });
  544. } else {
  545. console.error("User menu not found.");
  546. }
  547. }
  548. }
  549.  
  550. // Call the function to create the ignore button in the user menu
  551. createIgnoreButton();
  552.  
  553. // Function to get the user UUID from the chat log
  554. function getUserUUIDFromChatLog() {
  555. var chatLog = document.querySelector('.chatbox');
  556. if (chatLog) {
  557. // Find the first chat message in the log
  558. var firstChatMessage = chatLog.querySelector('p[data-t="c"]');
  559. if (firstChatMessage) {
  560. // Get the UUID from the first chat message
  561. var uuidElement = firstChatMessage.querySelector('.nm.fcuser, .nm.fcmod');
  562. if (uuidElement) {
  563. return uuidElement.dataset.uuid;
  564. } else {
  565. // Handle the case where UUID element is not found
  566. console.error("UUID element not found in the first chat message:", firstChatMessage);
  567. return null;
  568. }
  569. } else {
  570. // Handle the case where no chat messages are found
  571. console.error("No chat messages found in the chat log.");
  572. return null;
  573. }
  574. } else {
  575. // Handle the case where the chatbox element is not found
  576. console.error("Chatbox element not found.");
  577. return null;
  578. }
  579. }
  580.  
  581. // Function to get the user UUID from the user list within FreeChat context
  582. function getUserUUIDFromUserList() {
  583. var userContainer = document.querySelector("#chat > div.fc > div.gridbox_list > div.userlist p.user.fcuser[data-uuid]");
  584.  
  585. if (userContainer) {
  586. return userContainer.dataset.uuid;
  587. } else {
  588. // If user container is not found, set up a MutationObserver to wait for changes
  589. var observer = new MutationObserver(function (mutations) {
  590. userContainer = document.querySelector("#chat > div.fc > div.gridbox_list > div.userlist p.user.fcuser[data-uuid]");
  591. if (userContainer) {
  592. console.log("User container found after mutation.");
  593. console.log("User UUID: ", userContainer.dataset.uuid);
  594. // Stop observing once the user container is found
  595. observer.disconnect();
  596. }
  597. });
  598.  
  599. // Start observing changes in the user list
  600. observer.observe(document.querySelector("#chat > div.fc > div.gridbox_list > div.userlist"), { childList: true, subtree: true });
  601.  
  602. console.error("User container not found in the user list within FreeChat context. Waiting for mutations...");
  603. return null;
  604. }
  605. }
  606.  
  607. // Create the ignore list div once and append the content dynamically
  608. var ignoreListDiv = document.createElement("div");
  609. ignoreListDiv.style.position = "fixed";
  610. ignoreListDiv.style.bottom = "10px"; // Move to the bottom
  611. ignoreListDiv.style.left = "10px";
  612. ignoreListDiv.style.backgroundColor = "white"; // Adjust styling as needed
  613. ignoreListDiv.style.padding = "10px";
  614. ignoreListDiv.style.border = "1px solid black"; // Add border for visibility
  615. ignoreListDiv.style.fontSize = "12px"; // Set font size to 12px
  616.  
  617.  
  618. // Create a heading for the ignore list
  619. var ignoreListHeading = document.createElement("h3");
  620. ignoreListHeading.innerText = "Ignore List";
  621. ignoreListDiv.appendChild(ignoreListHeading);
  622.  
  623. // Create a list to display ignored users
  624. var ignoreList = document.createElement("ul");
  625. ignoreList.style.listStyleType = "none"; // Remove default list styling
  626. ignoreListDiv.appendChild(ignoreList);
  627.  
  628. // Append the ignore list div to the body
  629. document.body.appendChild(ignoreListDiv);
  630.  
  631. // Function to create a list item with the ignore list entry and remove button
  632. function createIgnoreListItem(uuid, username) {
  633. var listItem = document.createElement("li");
  634. listItem.innerText = `${username} (${uuid})`;
  635.  
  636. // Create a remove button for each entry
  637. var removeButton = document.createElement("button");
  638. removeButton.innerText = "Remove";
  639. removeButton.addEventListener("click", function () {
  640. // Remove the entry when the button is clicked
  641. removeIgnoreEntry(uuid);
  642. });
  643.  
  644. // Append the remove button to the list item
  645. listItem.appendChild(removeButton);
  646.  
  647. // Append the list item to the ignore list
  648. ignoreList.appendChild(listItem);
  649. }
  650.  
  651.  
  652. // Function to refresh the ignore list display
  653. function refreshIgnoreList() {
  654. // Clear the existing content
  655. ignoreList.innerHTML = "";
  656.  
  657. // Populate the ignore list with entries and remove buttons
  658. blocked_uuids.forEach(function (uuid) {
  659. createIgnoreListItem(uuid);
  660. });
  661. }
  662.  
  663. // Populate the ignore list with entries and remove buttons
  664. blocked_uuids.forEach(function (uuid) {
  665. createIgnoreListItem(uuid);
  666. });
  667.  
  668. // Function to handle removing an entry from the ignore list
  669. function removeIgnoreEntry(uuid) {
  670. var index = blocked_uuids.indexOf(uuid);
  671. if (index !== -1) {
  672. // Remove the entry from the ignore list
  673. blocked_uuids.splice(index, 1);
  674. // Refresh the ignore list display after removal
  675. refreshIgnoreList();
  676. }
  677. }
  678.  
  679.  
  680. // Function to save blocked_uuids to a text file
  681. function saveToTextFile() {
  682. var textToSave = blocked_uuids.join('\n');
  683. var blob = new Blob([textToSave], { type: 'text/plain' });
  684. var link = document.createElement('a');
  685. link.download = 'ignore_list.txt';
  686. link.href = window.URL.createObjectURL(blob);
  687. link.onclick = function () {
  688. document.body.removeChild(link);
  689. };
  690. link.style.display = 'none';
  691. document.body.appendChild(link);
  692. link.click();
  693. }
  694.  
  695. // Function to load blocked_uuids from a text file
  696. function loadFromTextFile() {
  697. var input = document.createElement('input');
  698. input.type = 'file';
  699. input.accept = '.txt';
  700. input.onchange = function (event) {
  701. var file = event.target.files[0];
  702. if (file) {
  703. var reader = new FileReader();
  704. reader.onload = function (e) {
  705. // Parse the content of the file and update blocked_uuids
  706. blocked_uuids = e.target.result.split('\n').map(function (uuid) {
  707. return uuid.trim();
  708. });
  709. // Update the ignore list display
  710. refreshIgnoreList();
  711. };
  712. reader.readAsText(file);
  713. }
  714. };
  715. input.click();
  716. }
  717.  
  718. // Function to create a button to save and load ignore list
  719. function createSaveLoadButtons() {
  720. var saveButton = document.createElement("button");
  721. saveButton.innerText = "Save to Text File";
  722. saveButton.addEventListener("click", function () {
  723. saveToTextFile();
  724. });
  725.  
  726. var loadButton = document.createElement("button");
  727. loadButton.innerText = "Load from Text File";
  728. loadButton.addEventListener("click", function () {
  729. loadFromTextFile();
  730. });
  731.  
  732. var buttonContainer = document.createElement("div");
  733. buttonContainer.style.marginTop = "10px";
  734. buttonContainer.appendChild(saveButton);
  735. buttonContainer.appendChild(loadButton);
  736.  
  737. // Append the button container to the ignore list div
  738. ignoreListDiv.appendChild(buttonContainer);
  739. }
  740.  
  741. // Call the function to create the save and load buttons
  742. createSaveLoadButtons();