Website Analyser

 Outputs capturable elements to console.log.

As of 2025-01-24. See the latest version.

// ==UserScript==
// @name         Website Analyser
// @name:en      Website Analyser
// @name:ja      サイト分析
// @namespace    http://tampermonkey.net/
// @version      2024-01-25
// @description   Outputs capturable elements to console.log.
// @description:en Outputs capturable elements to console.log
// @description:ja キャプチャ可能な要素をconsole.logに出力する
// @author       ぐらんぴ
// @match        http*://*/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-start
// @license      MIT
// ==/UserScript==

let settings = {
    defineProperty: GM_getValue('defineProperty', false),
    fetch: GM_getValue('fetch', false),
    webSocket: GM_getValue('webSocket', false),
    event: GM_getValue('event', false),
    appendChild: GM_getValue('appendChild', false),
};

const toggleSetting = (key) => {
    settings[key] = !settings[key];
    GM_setValue(key, settings[key]);
    console.log(`${key} is now ${settings[key]}`);
};

const registerCommands = () => {
    for (let key in settings) {
        GM_registerMenuCommand(`${key}: ${settings[key] ? 'ON' : 'OFF'}`, () => toggleSetting(key));
    }
};

registerCommands();

console.log('analysing');

if(settings.defineProperty){
    const origObjDefineProperty = Object.defineProperty;
    Object.defineProperty = (...args)=>{
        console.log("defineProperty:", args);
        return origObjDefineProperty(...args);
    };
}
if(settings.fetch){
    const origFetch = unsafeWindow.fetch;
    unsafeWindow.fetch = async (...args) => {
        console.log("fetch:", args);

        const res = await origFetch(...args);
        return res;
    };

}
if(settings.webSocket){
    const origWb = unsafeWindow.WebSocket;
    unsafeWindow.WebSocket = function (...args) {
        const ws = new origWb(...args);
        ws.addEventListener("message", e => {
            const data = JSON.parse(e.data);
            console.log("webSocket:", data);
        });
        return ws;
    };
}
if(settings.event){
    const origAddEventListener = EventTarget.prototype.addEventListener;
    EventTarget.prototype.addEventListener = function(type, listener, options) {
        console.log("event:", type);
        return origAddEventListener.call(this, type, listener, options);
    };
}
if(settings.appendChild){
    const origAppendChild = Element.prototype.appendChild;
    Element.prototype.appendChild = function(...args) {
        console.log("appendChild:", args);
        return origAppendChild.apply(this, args);
    };
}