MeKLiN2

Intercept3 by meklin

Jan 28th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Intercept3
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-01-28
  5. // @description Intercept WebSocket messages on StumbleChat and display them
  6. // @author You
  7. // @match https://stumblechat.com/room/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=stumblechat.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create a function to display WebSocket messages
  16. function displayWebSocketMessage(message) {
  17. const webSocketMessagesDiv = document.getElementById("webSocketMessages");
  18. if (webSocketMessagesDiv) {
  19. webSocketMessagesDiv.innerHTML += message + "<br>";
  20. webSocketMessagesDiv.scrollTop = webSocketMessagesDiv.scrollHeight;
  21. }
  22. }
  23.  
  24. // Override WebSocket constructor to intercept WebSocket creation
  25. const originalWebSocket = window.WebSocket;
  26. window.WebSocket = function(url, protocols) {
  27. console.log('WebSocket URL:', url);
  28.  
  29. // Call original WebSocket constructor
  30. const ws = new originalWebSocket(url, protocols);
  31.  
  32. // Event listener for receiving messages
  33. ws.addEventListener('message', event => {
  34. displayWebSocketMessage(event.data);
  35. });
  36.  
  37. return ws;
  38. };
  39.  
  40. // Method to create the div for displaying WebSocket messages
  41. function createWebSocketMessagesDiv() {
  42. const div = document.createElement("div");
  43. div.id = "webSocketMessages";
  44. div.style.position = "relative";
  45. div.style.height = "100%";
  46. div.style.paddingLeft = "2px";
  47. div.style.willChange = "transform";
  48. div.style.boxSizing = "border-box";
  49. div.style.overflowX = "hidden";
  50. div.style.overflowY = "auto";
  51. div.style.color = "#ffffff"; // Set font color to white
  52. div.style.padding = "10px"; // Example padding
  53. div.style.zIndex = "2"; // Set a higher z-index value
  54.  
  55. // Additional styles for specific scenarios
  56. div.style.display = "flex";
  57. div.style.flexDirection = "column";
  58. div.style.justifyContent = "flex-end";
  59. div.style.fontSize = "12px";
  60.  
  61. div.style.whiteSpace = "normal"; // Allow text to wrap within the container
  62. div.style.wordWrap = "break-word"; // Allow long words to break and wrap
  63.  
  64. // Locate and append custom div the chat-position div
  65. const chatPositionDiv = document.getElementById("chat-position");
  66. if (chatPositionDiv) {
  67. chatPositionDiv.appendChild(div);
  68. } else {
  69. // If chat-position div not found, append to document body
  70. document.body.appendChild(div);
  71. }
  72. }
  73. // Call the function to create the WebSocket messages div
  74. createWebSocketMessagesDiv();
  75. })();
Add Comment
Please, Sign In to add comment