InstaSynchP UserSpy

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

当前为 2014-12-30 提交的版本,查看 最新版本

  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.5
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-UserSpy
  9. // @license MIT
  10.  
  11. // @include http://*.instasynch.com/*
  12. // @include http://instasynch.com/*
  13. // @include http://*.instasync.com/*
  14. // @include http://instasync.com/*
  15. // @grant none
  16. // @run-at document-start
  17.  
  18. // @require https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js
  19. // ==/UserScript==
  20. function UserSpy(version) {
  21. "use strict";
  22. this.version = version;
  23. this.name = 'InstaSynchP UserSpy';
  24. this.settings = [{
  25. 'label': 'Login/off',
  26. 'id': 'login-off-log',
  27. 'type': 'checkbox',
  28. 'default': true,
  29. 'section': ['Chat', 'UserSpy']
  30. }, {
  31. 'label': 'Login/off greynames',
  32. 'id': 'login-off-greynames-log',
  33. 'type': 'checkbox',
  34. 'default': true,
  35. 'section': ['Chat', 'UserSpy']
  36. }, {
  37. 'label': 'Rename',
  38. 'id': 'rename-log',
  39. 'type': 'checkbox',
  40. 'default': true,
  41. 'section': ['Chat', 'UserSpy']
  42. }, {
  43. 'label': 'Add video',
  44. 'id': 'add-video-log',
  45. 'type': 'checkbox',
  46. 'default': true,
  47. 'section': ['Chat', 'UserSpy']
  48. }];
  49. }
  50.  
  51. UserSpy.prototype.executeOnce = function () {
  52. "use strict";
  53. var th = this;
  54. events.on(th, 'RenameUser', function (ignore1, ignore2, user) {
  55. if (gmc.get('rename-log')) {
  56. addSystemMessage('{0} renamed to {1}'.format(user.ip, user.username));
  57. }
  58. });
  59. };
  60.  
  61. UserSpy.prototype.postConnect = function () {
  62. "use strict";
  63. var th = this;
  64. //add events after we connected so it doesn't spam the chat for every user/video
  65. events.on(th, 'AddUser', th.userLoggedOn);
  66. events.on(th, 'RemoveUser', th.userLoggedOff);
  67. events.on(th, 'AddVideo', th.videoAdded);
  68. };
  69.  
  70. UserSpy.prototype.videoAdded = function (video) {
  71. if (!gmc.get('add-video-log')) {
  72. return;
  73. }
  74. var url = urlParser.create({videoInfo: video.info, format: 'long'}),
  75. len = 240 + url.length,
  76. message = '{0}</a>'.format('{0} added <a href="{1}">{2}'.format(
  77. video.addedby,
  78. url,
  79. video.title).substr(0, len));
  80. addSystemMessage(message);
  81. };
  82.  
  83. UserSpy.prototype.resetVariables = function () {
  84. "use strict";
  85. var th = this;
  86. //remove events when disconnecting/changing room and readd at postConnect
  87. events.unbind('AddUser', th.userLoggedOn);
  88. events.unbind('RemoveUser', th.userLoggedOff);
  89. events.unbind('RenameUser', th.userRenamed);
  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.5');