Console Tools

function tool classes that can run on the console

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

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

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

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

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

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

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

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.

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

// ==UserScript==
// @name         Console Tools
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  function tool classes that can run on the console
// @author       jiangweiye
// @match        https://*/*
// @match        http://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=developer.mozilla.org
// @require      https://cdn.bootcdn.net/ajax/libs/moment.js/2.29.4/moment.min.js
// @grant        GM_setClipboard
// @run-at       document-body
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';
    const PREFIX = 'tools';

    class Utils {
        /**
         * @description 拷贝到剪切板
         * @param {string} content
         * @returns boolean
         */
        copyToClipboard(content) {
            try {
                GM_setClipboard(content, 'text');
                return true;
            } catch (error) {
                return false;
            }
        }
    }

    class Tools extends Utils {
        constructor() {
            super();
        }

        /**
         * @description 格式化时间
         * @param {string|Date} date
         * @param {string} fmt
         * @returns {string}
         */
        parseTime(date, fmt = 'YYYY-MM-DD HH:mm:ss') {
            const _date = date instanceof Date ? date : new Date(date);
            return moment(_date).format(fmt);
        }

        /**
         * @description 格式化对象键
         * @param {string} data
         */
        convertKey(data) {
            const key = data.replace(/[^_]+/g, v => v.toUpperCase());
            this.copyToClipboard(`${key}: '${data}',`);
        }
    }

    window[PREFIX] = new Tools();
})();