Greasy Fork

ExplicitMessage_Inject

[DEBUG] 信息显式化(注入版)

目前为 2022-08-13 提交的版本。查看 最新版本

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

/**
 * ExplicitMessage_Inject
 * @file [DEBUG] 信息显式化(注入版)
 * @version 1.5.0.20220813
 * @author Laster2800
 */

(function() {
  'use strict'

  let updateAlerted = false
  const injectVersion = 20220813
  const win = typeof unsafeWindow === 'object' ? unsafeWindow : window
  const m = win[Symbol.for('ExplicitMessage')]
  for (const n of ['log', 'debug', 'info', 'warn', 'error']) {
    const log = console[n]
    console[n] = (...args) => {
      if (m?.fn?.wrappedLog) {
        if (injectVersion !== m.injectUpdate) {
          if (!updateAlerted) {
            updateAlerted = true
            m.fn.updateCheck?.(GM_info.script.name, injectVersion > m.injectUpdate)
          }
          console[n] = log
        } else {
          console[n] = m.fn.wrappedLog(console, log, n.toUpperCase(), GM_info.script.name)
        }
        Reflect.apply(console[n], console, args)
      } else {
        Reflect.apply(log, console, args)
      }
    }
  }
})()