Mini DevTools Console

Console mô phỏng DevTools

Από την 31/05/2026. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Advertisement:

// ==UserScript==
// @name         Mini DevTools Console
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Console mô phỏng DevTools
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const consoleBox = document.createElement('div');
    consoleBox.innerHTML = `
        <div id="tm-header">
            Mini Console
            <button id="tm-close">×</button>
        </div>
        <div id="tm-output"></div>
        <textarea id="tm-input" placeholder="Nhập JavaScript..."></textarea>
        <button id="tm-run">Run</button>
    `;

    Object.assign(consoleBox.style, {
        position: 'fixed',
        top: '20px',
        right: '20px',
        width: '500px',
        height: '350px',
        background: '#1e1e1e',
        color: '#fff',
        zIndex: '999999',
        border: '1px solid #555',
        fontFamily: 'monospace',
        display: 'flex',
        flexDirection: 'column'
    });

    document.body.appendChild(consoleBox);

    const output = consoleBox.querySelector('#tm-output');
    const input = consoleBox.querySelector('#tm-input');

    Object.assign(output.style, {
        flex: '1',
        overflow: 'auto',
        padding: '5px',
        borderBottom: '1px solid #444'
    });

    Object.assign(input.style, {
        height: '80px',
        background: '#252526',
        color: '#fff',
        border: 'none',
        resize: 'none'
    });

    function log(text, color = '#fff') {
        const div = document.createElement('div');
        div.style.color = color;
        div.textContent = text;
        output.appendChild(div);
        output.scrollTop = output.scrollHeight;
    }

    const originalLog = console.log;
    console.log = (...args) => {
        originalLog(...args);
        log(args.map(a =>
            typeof a === 'object'
                ? JSON.stringify(a, null, 2)
                : String(a)
        ).join(' '), '#4fc3f7');
    };

    document.getElementById('tm-run').onclick = () => {
        const code = input.value;

        try {
            const result = eval(code);
            log('> ' + String(result), '#90ee90');
        } catch (e) {
            log('Error: ' + e.message, '#ff6b6b');
        }
    };

    document.getElementById('tm-close').onclick = () => {
        consoleBox.remove();
    };

    input.addEventListener('keydown', e => {
        if (e.ctrlKey && e.key === 'Enter') {
            document.getElementById('tm-run').click();
        }
    });

})();