Greasy Fork

Greasemonkey | Logger

Greasemonkey development & debugging logger

目前为 2018-03-06 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.greasyfork.icu/scripts/38888/256713/Greasemonkey%20%7C%20Logger.js

// ==UserScript==
// @name            Greasemonkey | Logger
// @namespace       de.sidneys.greasemonkey
// @homepage        https://gist.githubusercontent.com/sidneys/5d44a978d18a1b91f554b2358406671d/raw/
// @version         3.0.0
// @description     Greasemonkey development & debugging logger
// @author          sidneys
// @icon            https://www.greasespot.net/favicon.ico
// @grant           none
// ==/UserScript==

/**
 * Logger
 *
 * @example
 * logger.info('message');
 *
 * @example
 * logger.error(`Errorcode: ${ERRORCODE}`);
 */
let logger = {
    debug() {
        if (!debugMode) { return; }

        const color = `rgb(255, 150, 70)`;

        console.debug.call(this, `? %c[${GM_info.script.name}] %c${Array.from(arguments).join(' ')}`, `font-weight: 600; color: ${color};`, `font-weight: 400; color: ${color};`);
    },
    info() {
        const color = `rgb(0, 200, 180)`;

        console.info.call(this, `ℹ️ %c[${GM_info.script.name}] %c${Array.from(arguments).join(' ')}`, `font-weight: 600; color: ${color};`, `font-weight: 400; color: ${color};`);
    },
    log() {
        const color = `rgb(70, 70, 70)`;

        console.log.call(this, `? %c[${GM_info.script.name}] %c${Array.from(arguments).join(' ')}`, `font-weight: 600; color: ${color};`, `font-weight: 400; color: ${color};`);
    },
    error() {
        const color = `rgb(220, 0, 30)`;

        console.error.call(this, `⚠️ %c[${GM_info.script.name}] %c${Array.from(arguments).join(' ')}`, `font-weight: 600; color: ${color};`, `font-weight: 400; color: ${color};`);
    }
};