MeKLiN2

init webrtc manually

Jan 28th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Initiate TC WSS manually
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-01-27
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://tinychat.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=tinychat.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. "use strict";
  14.  
  15. // Create a function to append logs to a console div
  16. function appendToConsole(message) {
  17. const consoleDiv = document.getElementById("console");
  18. if (consoleDiv) {
  19. consoleDiv.innerHTML += message + "<br>";
  20. }
  21. }
  22.  
  23. // Override WebSocket constructor to intercept WebSocket creation
  24. const originalWebSocket = window.WebSocket;
  25. window.WebSocket = function(url, protocol) {
  26. appendToConsole(`WebSocket connection created: ${url}`);
  27. const ws = new originalWebSocket(url, protocol);
  28.  
  29. ws.addEventListener("open", () => {
  30. appendToConsole("WebSocket connection opened");
  31. });
  32.  
  33. ws.addEventListener("close", (event) => {
  34. appendToConsole(`WebSocket connection closed: ${event.code} ${event.reason}`);
  35. });
  36.  
  37. ws.addEventListener("message", (event) => {
  38. appendToConsole(`Received message: ${event.data}`);
  39. });
  40.  
  41. return ws;
  42. };
  43.  
  44. // Method to connect and initialize the console div
  45. function connectConsole() {
  46. const consoleDiv = document.createElement("div");
  47. consoleDiv.id = "console";
  48. consoleDiv.style.border = "1px solid #ccc";
  49. consoleDiv.style.overflow = "auto";
  50. consoleDiv.style.maxHeight = "200px";
  51. document.body.appendChild(consoleDiv);
  52. }
  53.  
  54. connectConsole();
  55. })();
  56.  
Add Comment
Please, Sign In to add comment