Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Initiate TC WSS manually
- // @namespace http://tampermonkey.net/
- // @version 2024-01-27
- // @description try to take over the world!
- // @author You
- // @match https://tinychat.com/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=tinychat.com
- // @grant none
- // ==/UserScript==
- (function() {
- "use strict";
- // Create a function to append logs to a console div
- function appendToConsole(message) {
- const consoleDiv = document.getElementById("console");
- if (consoleDiv) {
- consoleDiv.innerHTML += message + "<br>";
- }
- }
- // Override WebSocket constructor to intercept WebSocket creation
- const originalWebSocket = window.WebSocket;
- window.WebSocket = function(url, protocol) {
- appendToConsole(`WebSocket connection created: ${url}`);
- const ws = new originalWebSocket(url, protocol);
- ws.addEventListener("open", () => {
- appendToConsole("WebSocket connection opened");
- });
- ws.addEventListener("close", (event) => {
- appendToConsole(`WebSocket connection closed: ${event.code} ${event.reason}`);
- });
- ws.addEventListener("message", (event) => {
- appendToConsole(`Received message: ${event.data}`);
- });
- return ws;
- };
- // Method to connect and initialize the console div
- function connectConsole() {
- const consoleDiv = document.createElement("div");
- consoleDiv.id = "console";
- consoleDiv.style.border = "1px solid #ccc";
- consoleDiv.style.overflow = "auto";
- consoleDiv.style.maxHeight = "200px";
- document.body.appendChild(consoleDiv);
- }
- connectConsole();
- })();
Add Comment
Please, Sign In to add comment