BLoxd.io Server Capture Console Logs

Captures console logs in a bloxd.io server and stores them in local storage.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         BLoxd.io Server Capture Console Logs
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Captures console logs in a bloxd.io server and stores them in local storage.
// @author       Nomu
// @match        https://bloxd.io/*
// @grant        none
// @icon         https://www.iconsdb.com/icons/preview/black/console-xxl.png
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // Create an array to hold logs
    const logs = JSON.parse(localStorage.getItem('capturedLogs')) || [];

    // Override console.log to capture log messages
    const originalConsoleLog = console.log;

    console.log = function(...args) {
        // Create a timestamp
        const timestamp = new Date().toISOString();

        // Construct the log entry
        const logEntry = {
            timestamp: timestamp,
            message: args.join(' ')
        };

        // Push to logs array
        logs.push(logEntry);

        // Save to local storage
        localStorage.setItem('capturedLogs', JSON.stringify(logs));

        // Call the original console.log to maintain functionality
        originalConsoleLog.apply(console, args);
    };

    // Function to download logs as a file
    const downloadLogs = () => {
        const blob = new Blob([JSON.stringify(logs, null, 2)], { type: 'application/json' });
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = 'capturedLogs.json';
        a.click();
        URL.revokeObjectURL(url);
    };

    // Add a button to download logs (you can style it as needed)
    const button = document.createElement('button');
    button.textContent = 'Download Logs';
    button.style.position = 'fixed';
    button.style.top = '10px';
    button.style.right = '10px';
    button.style.zIndex = '1000';
    button.onclick = downloadLogs;
    document.body.appendChild(button);

})();