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.2
  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.postConnect = function () {
  52. "use strict";
  53. var th = this;
  54. //add events after we connected so it doesn't spam the chat for every user/video
  55. events.on(th, 'AddUser', th.userLoggedOn);
  56. events.on(th, 'RemoveUser', th.userLoggedOff);
  57. events.on(th, 'RenameUser', function (ignore1, ignore2, user) {
  58. if (gmc.get('rename-log')) {
  59. addSystemMessage('{0} renamed to {1}'.format(user.ip, user.username));
  60. }
  61. });
  62. events.on(th, 'AddVideo', th.videoAdded);
  63. };
  64. UserSpy.prototype.videoAdded = function (video) {
  65. if (!gmc.get('add-video-log')) {
  66. return;
  67. }
  68. var url = urlParser.create(video.info),
  69. len = 240 + url.length,
  70. message = '{0}</a>'.format('{0} added <a href="{1}">{2}'.format(
  71. video.addedby,
  72. url,
  73. video.title).substr(0, len));
  74. addSystemMessage(message);
  75. };
  76.  
  77. UserSpy.prototype.resetVariables = function () {
  78. "use strict";
  79. var th = this;
  80. //remove events when disconnecting/changing room and readd at postConnect
  81. events.unbind('AddUser', th.userLoggedOn);
  82. events.unbind('RemoveUser', th.userLoggedOff);
  83. events.unbind('AddVideo', th.videoAdded);
  84. };
  85.  
  86. UserSpy.prototype.userLoggedOn = function (user) {
  87. "use strict";
  88. if(!user.loggedin && !gmc.get('login-off-greynames-log')){
  89. return;
  90. }
  91. if (gmc.get('login-off-log')) {
  92. addSystemMessage('{0}({1}) logged on.'.format(user.username, user.ip));
  93. }
  94. };
  95.  
  96. UserSpy.prototype.userLoggedOff = function (id, user) {
  97. "use strict";
  98. if(!user.loggedin && !gmc.get('login-off-greynames-log')){
  99. return;
  100. }
  101. if (gmc.get('login-off-log')) {
  102. addSystemMessage('{0}({1}) logged off.'.format(user.username, user.ip));
  103. }
  104. };
  105.  
  106. window.plugins = window.plugins || {};
  107. window.plugins.userSpy = new UserSpy('1.0.2');