InstaSynchP UserSpy

Log user actions into the chat (login/off, video add)

当前为 2015-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InstaSynchP UserSpy
  3. // @namespace InstaSynchP
  4. // @description Log user actions into the chat (login/off, video add)
  5.  
  6. // @version 1.0.8
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-UserSpy
  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/5647-instasynchp-library/code/InstaSynchP%20Library.js?version=37716
  17. // ==/UserScript==
  18. function UserSpy(version) {
  19. "use strict";
  20. this.version = version;
  21. this.name = 'InstaSynchP UserSpy';
  22. this.settings = [{
  23. 'label': 'Login/off',
  24. 'id': 'login-off-log',
  25. 'type': 'checkbox',
  26. 'default': true,
  27. 'section': ['Chat', 'UserSpy']
  28. }, {
  29. 'label': 'Login/off greynames',
  30. 'id': 'login-off-greynames-log',
  31. 'type': 'checkbox',
  32. 'default': true,
  33. 'section': ['Chat', 'UserSpy']
  34. }, {
  35. 'label': 'Rename',
  36. 'id': 'rename-log',
  37. 'type': 'checkbox',
  38. 'default': true,
  39. 'section': ['Chat', 'UserSpy']
  40. }, {
  41. 'label': 'Add video',
  42. 'id': 'add-video-log',
  43. 'type': 'checkbox',
  44. 'default': true,
  45. 'section': ['Chat', 'UserSpy']
  46. }];
  47. }
  48.  
  49. UserSpy.prototype.executeOnce = function () {
  50. "use strict";
  51. var th = this;
  52. events.on(th, 'RenameUser', function (ignore1, ignore2, user) {
  53. if (gmc.get('rename-log')) {
  54. addSystemMessage('{0} renamed to {1}'.format(user.ip, user.username));
  55. }
  56. });
  57. };
  58.  
  59. UserSpy.prototype.postConnect = function () {
  60. "use strict";
  61. var th = this;
  62. //add events after we connected so it doesn't spam the chat for every user/video
  63. events.on(th, 'AddUser', th.userLoggedOn);
  64. events.on(th, 'RemoveUser', th.userLoggedOff);
  65. events.on(th, 'AddVideo', th.videoAdded);
  66. };
  67.  
  68. UserSpy.prototype.videoAdded = function (video) {
  69. if (!gmc.get('add-video-log')) {
  70. return;
  71. }
  72. var url = urlParser.create({
  73. videoInfo: video.info,
  74. format: 'long'
  75. }),
  76. len = 240 + url.length,
  77. message = '{0}</a>'.format('{0} added <a target="_blank" href="{1}">{2}'.format(
  78. video.addedby,
  79. url,
  80. video.title).substr(0, len));
  81. addSystemMessage(message);
  82. };
  83.  
  84. UserSpy.prototype.resetVariables = function () {
  85. "use strict";
  86. var th = this;
  87. //remove events when disconnecting/changing room and readd at postConnect
  88. events.unbind('AddUser', th.userLoggedOn);
  89. events.unbind('RemoveUser', th.userLoggedOff);
  90. events.unbind('AddVideo', th.videoAdded);
  91. };
  92.  
  93. UserSpy.prototype.userLoggedOn = function (user) {
  94. "use strict";
  95. if (!user.loggedin && !gmc.get('login-off-greynames-log')) {
  96. return;
  97. }
  98. if (gmc.get('login-off-log')) {
  99. addSystemMessage('{0}({1}) logged on.'.format(user.username, user.ip));
  100. }
  101. };
  102.  
  103. UserSpy.prototype.userLoggedOff = function (id, user) {
  104. "use strict";
  105. if (!user.loggedin && !gmc.get('login-off-greynames-log')) {
  106. return;
  107. }
  108. if (gmc.get('login-off-log')) {
  109. addSystemMessage('{0}({1}) logged off.'.format(user.username, user.ip));
  110. }
  111. };
  112.  
  113. window.plugins = window.plugins || {};
  114. window.plugins.userSpy = new UserSpy('1.0.8');