Greasy Fork is available in English.

CreateLogger

Logs stuff

Tätä skriptiä ei tulisi asentaa suoraan. Se on kirjasto muita skriptejä varten sisällytettäväksi metadirektiivillä // @require https://update.greatest.deepsurf.us/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. }