InstaSynchP Logger

Log information with different levels

目前为 2015-05-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InstaSynchP Logger
  3. // @namespace InstaSynchP
  4. // @description Log information with different levels
  5.  
  6. // @version 1.0.3
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-Logger
  9. // @license MIT
  10.  
  11. // @include *://instasync.com/r/*
  12. // @include *://*.instasync.com/r/*
  13. // @grant none
  14. // @run-at document-start
  15.  
  16. // @require https://greasyfork.org/scripts/8159-log4javascript/code/log4javascript.js?version=37575
  17. // @require https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
  18. // ==/UserScript==
  19.  
  20. function Logger(version) {
  21. "use strict";
  22. this.version = version;
  23. this.name = 'InstaSynchP Logger';
  24. this.log = undefined;
  25. this.inPageAppender = undefined;
  26. }
  27.  
  28. Logger.prototype.executeOnceCore = function () {
  29. "use strict";
  30. var th = this, oldError;
  31. log4javascript.setDocumentReady();
  32. th.log = log4javascript.getDefaultLogger();
  33. th.log.removeAllAppenders();
  34. th.inPageAppender = new log4javascript.InPageAppender(undefined, false, true, true, "100%", "300px");
  35. th.inPageAppender.setShowCommandLine(false);
  36. th.inPageAppender.setShowHideButton(true);
  37. th.inPageAppender.setScrollToLatestMessage(false);
  38. th.log.addAppender(th.inPageAppender);
  39.  
  40. oldError = th.log.error;
  41. //add a message to chat on an error
  42. th.log.error = function () {
  43. oldError.apply(th.log, arguments);
  44. var message = '<b>An error has occured in the script. ' +
  45. 'Please open the <a href="#" onclick="$(\'#log_btn\').trigger(\'click\')">log</a> ' +
  46. 'and make a <a href="http://pastebin.com/" target="_blank">pastebin</a> ' +
  47. 'of everything in there and send it to ' +
  48. '<a href="https://greasyfork.org/en/scripts/5653-instasynchp-core/feedback" target="_blank">me</a>.</b>';
  49. addErrorMessage(message);
  50. };
  51.  
  52. //add button
  53. $('#tabs_chat_settings_content').append(
  54. $('<button>', {
  55. 'class': 'btn btn-xs btn-primary',
  56. 'id': 'log_btn'
  57. }).text('Log').click(function () {
  58. if (th.inPageAppender.isVisible()) {
  59. th.inPageAppender.hide();
  60. } else {
  61. th.inPageAppender.show();
  62. }
  63. })
  64. );
  65. };
  66.  
  67. window.plugins = window.plugins || {};
  68. window.plugins.logger = new Logger('1.0.3');