InstaSynchP UserSpy

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

当前为 2014-11-23 提交的版本,查看 最新版本

  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.3
  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. 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(video.info),
  73. len = 240 + url.length,
  74. message = '{0}</a>'.format('{0} added <a href="{1}">{2}'.format(
  75. video.addedby,
  76. url,
  77. video.title).substr(0, len));
  78. addSystemMessage(message);
  79. };
  80.  
  81. UserSpy.prototype.resetVariables = function () {
  82. "use strict";
  83. var th = this;
  84. //remove events when disconnecting/changing room and readd at postConnect
  85. events.unbind('AddUser', th.userLoggedOn);
  86. events.unbind('RemoveUser', th.userLoggedOff);
  87. events.unbind('RenameUser', th.userRenamed);
  88. events.unbind('AddVideo', th.videoAdded);
  89. };
  90.  
  91. UserSpy.prototype.userLoggedOn = function (user) {
  92. "use strict";
  93. if (!user.loggedin && !gmc.get('login-off-greynames-log')) {
  94. return;
  95. }
  96. if (gmc.get('login-off-log')) {
  97. addSystemMessage('{0}({1}) logged on.'.format(user.username, user.ip));
  98. }
  99. };
  100.  
  101. UserSpy.prototype.userLoggedOff = function (id, user) {
  102. "use strict";
  103. if (!user.loggedin && !gmc.get('login-off-greynames-log')) {
  104. return;
  105. }
  106. if (gmc.get('login-off-log')) {
  107. addSystemMessage('{0}({1}) logged off.'.format(user.username, user.ip));
  108. }
  109. };
  110.  
  111. window.plugins = window.plugins || {};
  112. window.plugins.userSpy = new UserSpy('1.0.3');