🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Console Log Styler

Styles console.log() output with customizable colors, borders, and visual effects for better debugging visibility.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Console Log Styler
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      2
// @description  Styles console.log() output with customizable colors, borders, and visual effects for better debugging visibility.
// @author       hacker09
// @match        *://*/*
// @run-at       document-start
// @icon         https://i.imgur.com/27mYVlx.png
// @grant        none
// ==/UserScript==

(function(){
  //EASY CONFIG - Change these values
  const showScriptName=true; //Set to false to hide the script name/(Page) label
  const autoColor=true; //Set to false to force white text for all logs
  const selectedBorderStyle="leftRightBorder"; //leftBorder, leftRightBorder, topBorder, fullBorder, glow, arrow, bullet
  const borderColor="#007acc"; //any hex color

  //Border styles
  const borderStyles={
    leftBorder:`border-left:3px solid ${borderColor};`,
    leftRightBorder:`border-left:3px solid ${borderColor};border-right:3px solid ${borderColor};`,
    topBorder:`border-top:2px solid ${borderColor};`,
    fullBorder:`border:2px solid ${borderColor};`,
    glow:`box-shadow:0 0 8px rgba(0,122,204,0.6);`,
    arrow:`border-left:3px solid ${borderColor};`, //add ▶ manually to logs
    bullet:`border-left:3px solid ${borderColor};padding-left:13px;` //add ● manually to logs
  };

  //Color options
  const styles={
    green:`color:#00ff00;background:#2d2d2d;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`,
    orange:`color:#ff8c00;background:#2d2d2d;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`,
    cyan:`color:#00ffff;background:#2d2d2d;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`,
    yellow:`color:#ffff00;background:#2d2d2d;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`,
    purple:`color:#ff00ff;background:#2d2d2d;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`,
    red:`color:#ff4444;background:#2d2d2d;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`,
    white:`color:#ffffff;background:#404040;padding:4px 8px;border-radius:3px;font-size:13px;${borderStyles[selectedBorderStyle]}`
  };

  const colorKeys = Object.keys(styles).filter(k => k !== 'white'); //exclude white from auto-picker

  const originalLog=console.log;
  console.log=function(...args){
    //Parse stack, default to 'Page' if no script name found
    const origin = ((new Error().stack.split('\n')[2]||'').match(/name=([^&]+)/)||['','Page'])[1].replace('.user.js','');
    const prefix = showScriptName ? `(${decodeURIComponent(origin)}): ` : '';

    //Pick color based on script name hash if enabled (and not Page), otherwise white
    let chosenStyle = styles.white;
    if(autoColor && origin !== 'Page') {
      let hash = 0;
      for (let i = 0; i < origin.length; i++) hash = origin.charCodeAt(i) + ((hash << 5) - hash);
      chosenStyle = styles[colorKeys[Math.abs(hash) % colorKeys.length]];
    }

    originalLog("%c"+prefix+args.join(" "), chosenStyle);
  };
})();