InstaSynchP UserSpy

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

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

  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.1.0
  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: 'Show user logs in or off',
  24. id: 'login-off-log',
  25. type: 'checkbox',
  26. 'default': true,
  27. section: ['UserSpy']
  28. }, {
  29. label: 'Show when a greyname logs in or off',
  30. id: 'login-off-greynames-log',
  31. type: 'checkbox',
  32. 'default': true,
  33. section: ['UserSpy']
  34. }, {
  35. label: 'Show when a greyname renames himself',
  36. id: 'rename-log',
  37. type: 'checkbox',
  38. 'default': true,
  39. section: ['UserSpy']
  40. }, {
  41. label: 'Show when someone adds a video',
  42. title: 'Includes the title',
  43. id: 'add-video-log',
  44. type: 'checkbox',
  45. 'default': true,
  46. section: ['UserSpy']
  47. }];
  48. }
  49.  
  50. UserSpy.prototype.getAddVideoMessage = function (video) {
  51. 'use strict';
  52. //user added <a href="url">title</a>
  53. return ''.concat(
  54. video.addedby,
  55. ' added ',
  56. '<a target="_blank" href="',
  57. urlParser.create({
  58. videoInfo: video.info,
  59. format: 'long'
  60. }),
  61. '">',
  62. video.title.substr(0, 240),
  63. '</a>'
  64. );
  65. };
  66.  
  67. UserSpy.prototype.getRenameMessage = function (user) {
  68. 'use strict';
  69. //ip renamed to username
  70. return ''.concat(
  71. user.ip,
  72. ' renamed to ',
  73. user.username
  74. );
  75. };
  76.  
  77. UserSpy.prototype.getLogOnMessage = function (user) {
  78. 'use strict';
  79. //user(ip) logged on
  80. return ''.concat(
  81. user.username,
  82. '(',
  83. user.ip,
  84. ') logged on'
  85. );
  86. };
  87.  
  88. UserSpy.prototype.getLogOffMessage = function (user) {
  89. 'use strict';
  90. //user(ip) logged off
  91. return ''.concat(
  92. user.username,
  93. '(',
  94. user.ip,
  95. ') logged off'
  96. );
  97. };
  98.  
  99. UserSpy.prototype.executeOnce = function () {
  100. 'use strict';
  101. var _this = this;
  102. events.on(_this, 'RenameUser', function (ignore1, ignore2, user) {
  103. if (gmc.get('rename-log')) {
  104. addSystemMessage(_this.getRenameMessage(user));
  105. }
  106. });
  107. };
  108.  
  109. UserSpy.prototype.postConnect = function () {
  110. 'use strict';
  111. var _this = this;
  112. //add events after we connected so it doesn't spam the chat for every user/video
  113. events.on(_this, 'AddUser', _this.userLoggedOn);
  114. events.on(_this, 'RemoveUser', _this.userLoggedOff);
  115. events.on(_this, 'AddVideo', _this.videoAdded);
  116. };
  117.  
  118. UserSpy.prototype.videoAdded = function (video) {
  119. 'use strict';
  120. var _this = this;
  121. if (gmc.get('add-video-log')) {
  122. addSystemMessage(_this.getAddVideoMessage(video));
  123. }
  124. };
  125.  
  126. UserSpy.prototype.resetVariables = function () {
  127. 'use strict';
  128. var _this = this;
  129. //remove events when disconnecting/changing room and readd at postConnect
  130. events.unbind('AddUser', _this.userLoggedOn);
  131. events.unbind('RemoveUser', _this.userLoggedOff);
  132. events.unbind('AddVideo', _this.videoAdded);
  133. };
  134.  
  135. UserSpy.prototype.isUserLogged = function (user) {
  136. 'use strict';
  137. return gmc.get('login-off-log') &&
  138. (user.loggedin || gmc.get('login-off-greynames-log'));
  139. };
  140.  
  141. UserSpy.prototype.userLoggedOn = function (user) {
  142. 'use strict';
  143. var _this = this;
  144. if (_this.isUserLogged(user)) {
  145. addSystemMessage(_this.getLogOnMessage(user));
  146. }
  147. };
  148.  
  149. UserSpy.prototype.userLoggedOff = function (ignore, user) {
  150. 'use strict';
  151. var _this = this;
  152. if (_this.isUserLogged(user)) {
  153. addSystemMessage(_this.getLogOffMessage(user));
  154. }
  155. };
  156.  
  157. window.plugins = window.plugins || {};
  158. window.plugins.userSpy = new UserSpy('1.1.0');