CreateLogger

Logs stuff

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

  1. // ==UserScript==
  2. // @name CreateLogger
  3. // @version 1.0
  4. // @description Logs stuff
  5. // @author Toonidy
  6. // @match *://*.nitrotype.com/race
  7. // @match *://*.nitrotype.com/race/*
  8. // @license MIT
  9. // ==/UserScript==
  10.  
  11. // Credit to Toonidy
  12. function createLogger(namespace) {
  13. const logPrefix = (prefix = "") => {
  14. const formatMessage = `%c[${namespace}]${prefix ? `%c[${prefix}]` : ""}`;
  15. let args = [
  16. console,
  17. `${formatMessage}%c`,
  18. "background-color: #4285f4; color: #fff; font-weight: bold",
  19. ];
  20. if (prefix) {
  21. args = args.concat(
  22. "background-color: #4f505e; color: #fff; font-weight: bold"
  23. );
  24. }
  25. return args.concat("color: unset");
  26. };
  27.  
  28. const bindLog = (logFn, prefix) =>
  29. Function.prototype.bind.apply(logFn, logPrefix(prefix));
  30.  
  31. return {
  32. info: (prefix) => bindLog(console.info, prefix),
  33. warn: (prefix) => bindLog(console.warn, prefix),
  34. error: (prefix) => bindLog(console.error, prefix),
  35. log: (prefix) => bindLog(console.log, prefix),
  36. debug: (prefix) => bindLog(console.debug, prefix),
  37. };
  38. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址