Advertisement
MeKLiN2

Unlisted Stumble Script Do Not Share

Nov 8th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Schwarze Liste
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Blacklist for Stumblechat moderators
  6. // @author MeKLiN
  7. // @match https://stumblechat.com/room/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=stumblechat.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. // Store WebSocket globally
  17. let webSocket;
  18.  
  19. // Store ban list in local storage
  20. let banList = [];
  21.  
  22. // User map to keep track of users and their handles
  23. const userMap = new Map();
  24.  
  25. // Override WebSocket constructor to intercept WebSocket creation
  26. const originalWebSocket = window.WebSocket;
  27. window.WebSocket = function(url, protocols) {
  28. // Create WebSocket connection
  29. webSocket = new originalWebSocket(url, protocols);
  30.  
  31. // Event listener for receiving messages
  32. webSocket.addEventListener('message', event => {
  33. handleWebSocketMessage(event.data);
  34. });
  35.  
  36. return webSocket;
  37. };
  38.  
  39. // Function to handle WebSocket messages
  40. function handleWebSocketMessage(message) {
  41. const parsedMessage = JSON.parse(message);
  42. console.log('Received message:', parsedMessage);
  43. if (parsedMessage.stumble === "join") {
  44. const { handle, username } = parsedMessage;
  45. console.log('User joined:', username);
  46. // Add user to user map
  47. userMap.set(username, handle);
  48. // Check if the user is banned
  49. if (banList.includes(username)) {
  50. console.log('User is banned. Triggering ban...');
  51. // Trigger ban for the user
  52. triggerBan(handle);
  53. }
  54. }
  55. }
  56.  
  57. // Function to trigger ban
  58. function triggerBan(handle) {
  59. console.log(`Banning user with handle: ${handle}`);
  60. // Send ban message
  61. const banRequest = JSON.stringify({ "stumble": "ban", "handle": handle });
  62. webSocket.send(banRequest);
  63. }
  64.  
  65. // Function to send ban requests for banned users on join
  66. async function sendBanRequestsOnJoin() {
  67. console.log('Sending ban requests for banned users on join...');
  68. const userList = document.querySelectorAll('.bar .username');
  69. userList.forEach(user => {
  70. const username = user.textContent.trim();
  71. if (banList.includes(username)) {
  72. const handle = user.closest('.bar').getAttribute('user-id');
  73. if (handle) {
  74. console.log(`Banning user: ${username}`);
  75. // Trigger ban for the user
  76. triggerBan(handle);
  77. }
  78. }
  79. });
  80. }
  81.  
  82. // Function to handle the file input and extract usernames
  83. function handleFileInput(event) {
  84. const file = event.target.files[0];
  85. if (file) {
  86. const reader = new FileReader();
  87. reader.onload = function(e) {
  88. const content = e.target.result;
  89. banList = content.split('\n').map(username => username.trim());
  90. // Save updated ban list in local storage
  91. localStorage.setItem("banList", JSON.stringify(banList));
  92. console.log('Ban list loaded:', banList);
  93. };
  94. reader.readAsText(file);
  95. }
  96. }
  97.  
  98. // Function to create load file button
  99. function createLoadFileButton() {
  100. const loadFileButton = document.createElement('input');
  101. loadFileButton.type = 'file';
  102. loadFileButton.accept = '.txt';
  103. loadFileButton.style.position = 'fixed';
  104. loadFileButton.style.top = '10px';
  105. loadFileButton.style.right = '150px';
  106. loadFileButton.style.zIndex = '1000';
  107. loadFileButton.addEventListener('change', handleFileInput);
  108. document.body.appendChild(loadFileButton);
  109. }
  110.  
  111. // Function to create activate button
  112. function createActivateButton() {
  113. const activateButton = document.createElement('button');
  114. activateButton.textContent = 'Activate';
  115. activateButton.style.position = 'fixed';
  116. activateButton.style.top = '10px';
  117. activateButton.style.right = '10px';
  118. activateButton.style.zIndex = '1000';
  119. activateButton.addEventListener('click', () => {
  120. // Send ban requests for banned users on join
  121. sendBanRequestsOnJoin();
  122. // Hide the activate button after clicking
  123. activateButton.style.display = 'none';
  124. });
  125. document.body.appendChild(activateButton);
  126. }
  127.  
  128. // Load ban list from local storage
  129. const storedBanList = localStorage.getItem("banList");
  130. if (storedBanList) {
  131. banList = JSON.parse(storedBanList);
  132. console.log('Ban list loaded from local storage:', banList);
  133. }
  134.  
  135. // Create load file button and activate button
  136. createLoadFileButton();
  137. createActivateButton();
  138.  
  139. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement