InstaSynchP UserSpy

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

  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.3
  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. label: 'Show when a video gets played',
  49. id: 'play-video-log',
  50. type: 'checkbox',
  51. 'default': true,
  52. section: ['UserSpy']
  53. }];
  54. this.lastVideo = {};
  55. }
  56.  
  57. UserSpy.prototype.getAddVideoMessage = function (video) {
  58. 'use strict';
  59. //user added <a href="url">title</a>
  60. return ''.concat(
  61. video.addedby,
  62. ' added ',
  63. '<a target="_blank" href="',
  64. urlParser.create({
  65. videoInfo: video.info,
  66. format: 'long'
  67. }),
  68. '">',
  69. video.title.substr(0, 240),
  70. '</a>'
  71. );
  72. };
  73.  
  74. UserSpy.prototype.getRenameMessage = function (user) {
  75. 'use strict';
  76. //ip renamed to username
  77. return ''.concat(
  78. user.ip,
  79. ' renamed to ',
  80. user.username
  81. );
  82. };
  83.  
  84. UserSpy.prototype.getLogOnMessage = function (user) {
  85. 'use strict';
  86. //user(ip) logged on
  87. return ''.concat(
  88. user.username,
  89. '(',
  90. user.ip,
  91. ') logged on'
  92. );
  93. };
  94.  
  95. UserSpy.prototype.getLogOffMessage = function (user) {
  96. 'use strict';
  97. //user(ip) logged off
  98. return ''.concat(
  99. user.username,
  100. '(',
  101. user.ip,
  102. ') logged off'
  103. );
  104. };
  105.  
  106. UserSpy.prototype.getPlayVideoMessage = function (video) {
  107. 'use strict';
  108. //Now playing title via user
  109. return ''.concat(
  110. 'Now playing ',
  111. '<a target="_blank" href="',
  112. urlParser.create({
  113. videoInfo: video.info,
  114. format: 'long'
  115. }),
  116. '">',
  117. video.title.substr(0, 240),
  118. '</a>',
  119. ' via ',
  120. video.addedby);
  121. };
  122.  
  123. UserSpy.prototype.executeOnce = function () {
  124. 'use strict';
  125. var _this = this;
  126. events.on(_this, 'RenameUser', function (user) {
  127. if (gmc.get('rename-log')) {
  128. addSystemMessage(_this.getRenameMessage(user));
  129. }
  130. });
  131. };
  132.  
  133. UserSpy.prototype.postConnect = function () {
  134. 'use strict';
  135. var _this = this;
  136. //add events after we connected so it doesn't spam the chat for every user/video
  137. events.on(_this, 'AddUser', _this.userLoggedOn);
  138. events.on(_this, 'RemoveUser', _this.userLoggedOff);
  139. events.on(_this, 'AddVideo', _this.videoAdded);
  140. events.on(_this, 'PlayVideo', _this.videoPlayed);
  141. };
  142.  
  143. UserSpy.prototype.resetVariables = function () {
  144. 'use strict';
  145. var _this = this;
  146. //remove events when disconnecting/changing room and readd at postConnect
  147. events.unbind('AddUser', _this.userLoggedOn);
  148. events.unbind('RemoveUser', _this.userLoggedOff);
  149. events.unbind('AddVideo', _this.videoAdded);
  150. events.unbind('PlayVideo', _this.videoPlayed);
  151. _this.lastVideo = {};
  152. };
  153.  
  154. UserSpy.prototype.videoPlayed = function (video) {
  155. 'use strict';
  156. var _this = this;
  157. if (gmc.get('play-video-log') &&
  158. !videoInfoEquals(video.info, _this.lastVideo.info)) {
  159. _this.lastVideo = video;
  160. addSystemMessage(_this.getPlayVideoMessage(video));
  161. }
  162. };
  163.  
  164. UserSpy.prototype.videoAdded = function (video) {
  165. 'use strict';
  166. var _this = this;
  167. if (gmc.get('add-video-log')) {
  168. addSystemMessage(_this.getAddVideoMessage(video));
  169. }
  170. };
  171.  
  172. UserSpy.prototype.isUserLogged = function (user) {
  173. 'use strict';
  174. return gmc.get('login-off-log') &&
  175. (user.loggedin || gmc.get('login-off-greynames-log'));
  176. };
  177.  
  178. UserSpy.prototype.userLoggedOn = function (user) {
  179. 'use strict';
  180. var _this = this;
  181. if (_this.isUserLogged(user)) {
  182. addSystemMessage(_this.getLogOnMessage(user));
  183. }
  184. };
  185.  
  186. UserSpy.prototype.wasUserForcedOff = function (user) {
  187. 'use strict';
  188. var _this = this;
  189. var reg = new RegExp('^[^\\s]+ has (?:kicked|banned) {0}\\({1}\\)$'
  190. .format(user.username, user.ip));
  191. return (!isUdef(window.plugins.modSpy) &&
  192. $('#chat_messages > :last-child').find('.username').text() === ': ' &&
  193. $('#chat_messages > :last-child').find('.message').text().match(reg));
  194. };
  195.  
  196. UserSpy.prototype.userLoggedOff = function (user) {
  197. 'use strict';
  198. var _this = this;
  199. if (_this.isUserLogged(user) && !_this.wasUserForcedOff(user)) {
  200. addSystemMessage(_this.getLogOffMessage(user));
  201. }
  202. };
  203.  
  204. window.plugins = window.plugins || {};
  205. window.plugins.userSpy = new UserSpy('1.1.3');