Site Measurements

Logs fetch, xhr, ws requests in console

Tính đến 05-08-2024. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Site Measurements
// @namespace    http://tampermonkey.net/
// @version      2024-08-05.5
// @license      MIT
// @description  Logs fetch, xhr, ws requests in console
// @author       Grosmar
// @match        https://*.livejasmin.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=livejasmin.com
// @grant        none
// @run-at document-start
// ==/UserScript==

(function() {
    'use strict';
    console.log("MEASUREMENT");

    const filteredWs = /jaws\./;
    const binaryWsPackageCountLimit = 3; //show only this amount of binary packages
    const wsEventFilter = { r: /onRandomAccessPoint|onMetaData/, limit: 2} // messages with this content will be shown only `limit` amount of time




    const OriglImage = window.Image; window.Image = function(...args) { const img = new OriginalImage(...args); img.addEventListener('load', function() {console.log('NETWORK_Img2', img.src);}); return img; };

     function handleNewImages(images) {
        images.forEach(img => {
            console.log('NETWORK_Img', img.src);
        });
    }

    // Create a MutationObserver to watch for added nodes
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length > 0) {
                mutation.addedNodes.forEach(node => {
                    if (node.tagName === 'IMG') {
                        handleNewImages([node]);
                    } else if (node.querySelectorAll) {
                        // Check for images within added containers
                        const imgs = node.querySelectorAll('img');
                        if (imgs.length > 0) {
                            handleNewImages(imgs);
                        }
                    }
                });
            }
        });
    });

    // Start observing the document body for changes
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });



    const origFetch = fetch; window.fetch = (...args) => { console.warn("NETWORK_Fetch", ...args); return origFetch(...args); }
    const origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function (...args) { console.warn("NETWORK_Xhr", ...args); return origOpen.apply(this, args); }
    const origWsSend = WebSocket.prototype.send; WebSocket.prototype.send = function(...args) { if (args[0] != 3 && !filteredWs.test(this.url)) console.warn("NETWORK_Ws_Send", ...args); return origWsSend.apply(this, args); }

    const OrigWs = window.WebSocket;
    window.WebSocket = function (url, protocols)
    {
        let ws = new OrigWs(url, protocols);
        if (!filteredWs.test(url)) {
            let binaryCount = 0;
            let filteredMsgCount = 0;
            console.warn("NETWORK_Ws_Conn", url, protocols);
            ws.addEventListener("open", (event) => { console.warn("NETWORK_Ws_Open", url); });
            ws.addEventListener("close", (event) => { console.warn("NETWORK_Ws_Close", url); });

            ws.addEventListener("message", (event) =>
                {
                    const isBinary = event.data instanceof ArrayBuffer;
                    const eventFilterTest = wsEventFilter.r.test(event.data);
                    if (event.data != 2 && ((isBinary && binaryCount++ < binaryWsPackageCountLimit) || (!isBinary && (!eventFilterTest || filteredMsgCount++ < wsEventFilter.limit))))
                    {
                        console.warn("NETWORK_Ws_Msg", url, event.data);
                    }
                }
            );
        }
        return ws;
    }
})();