InstaSynchP ModSpy

Log mod actions into the chat (kick, ban, remove videos, ...)

当前为 2015-02-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name InstaSynchP ModSpy
  3. // @namespace InstaSynchP
  4. // @description Log mod actions into the chat (kick, ban, remove videos, ...)
  5.  
  6. // @version 1.0.5
  7. // @author Zod-
  8. // @source https://github.com/Zod-/InstaSynchP-Modspy
  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.  
  19. function ModSpy(version) {
  20. "use strict";
  21. this.version = version;
  22. this.name = 'InstaSynchP ModSpy';
  23. this.filterList = [
  24. /^Resynch request(?:ed)? ?(?:sent)?\.?\.$/,
  25. /cleaned the playlist/,
  26. /^play(?:ing)?$/,
  27. /Using HTML5 player is not recomended\./,
  28. /^load start$/,
  29. /^paused$/,
  30. /^stalled$/,
  31. /^activate$/
  32. ];
  33. }
  34.  
  35. ModSpy.prototype.executeOnce = function () {
  36. "use strict";
  37. var th = this,
  38. oldLog = window.console.log,
  39. lastRemovedVideo,
  40. lastMovedVideo,
  41. lastSkipPercentage,
  42. actiontaker,
  43. lastAction,
  44. bumpCheck;
  45.  
  46. window.console.log = function (message) {
  47. var i,
  48. filter,
  49. match;
  50. //only check for strings
  51. if (typeof message !== 'string') {
  52. oldLog.apply(window.console, arguments);
  53. return;
  54. }
  55.  
  56. //add as error message and then return
  57. if (message.startsWith("Error:")) {
  58. addErrorMessage(message);
  59. oldLog.apply(window.console, arguments);
  60. return;
  61. }
  62.  
  63. filter = false;
  64. for (i = 0; i < th.filterList.length; i += 1) {
  65. if (message.match(th.filterList[i])) {
  66. filter = true;
  67. break;
  68. }
  69. }
  70. //return if setting is off or message is filtered
  71. if (filter) {
  72. oldLog.apply(window.console, arguments);
  73. return;
  74. }
  75. //prepare the message for each log
  76. if ((match = message.match(/([^\s]+) moved a video\./))) {
  77. message = '{0} {1} a <a href="{2}" target="_blank">video</a> via {3}'.format(
  78. match[1],
  79. bumpCheck ? 'bumped' : 'moved',
  80. urlParser.create({
  81. videoInfo: lastMovedVideo.info
  82. }),
  83. lastMovedVideo.addedby
  84. );
  85. bumpCheck = false;
  86. } else if ((match = message.match(/([^\s]+) has banned a user\./))) {
  87. lastAction = 'banned';
  88. actiontaker = match[1];
  89. } else if ((match = message.match(/([^\s]+) has kicked a user\./))) {
  90. lastAction = 'kicked';
  91. actiontaker = match[1];
  92. } else if ((match = message.match(/([^\s]+) removed a video\./))) {
  93. message = '{0} removed a <a href="{1}" target="_blank">video</a> via {2}.'.format(
  94. match[1],
  95. urlParser.create({
  96. videoInfo: lastRemovedVideo.info
  97. }),
  98. lastRemovedVideo.addedby
  99. );
  100. } else if ((match = message.match(/([^\s]+) modified skip ratio\./))) {
  101. message = '{0} set skip ratio to {1}%'.format(match[1], lastSkipPercentage);
  102. }
  103.  
  104. //add the message to the chat if we don't have to wait for the event to happen
  105. //user removed events gets fired after the log
  106. if (!lastAction) {
  107. addSystemMessage(message);
  108. }
  109.  
  110. oldLog.apply(window.console, arguments);
  111. };
  112.  
  113. events.on(th, 'RemoveUser', function (id, user) {
  114. //print the kick/ban log
  115. if (lastAction && (lastAction === 'banned' || lastAction === 'kicked')) {
  116. addSystemMessage('{0} has {1} {2}({3})'.format(actiontaker, lastAction, user.username, user.ip));
  117. lastAction = undefined;
  118. actiontaker = undefined;
  119. }
  120. });
  121.  
  122. events.on(th, 'MoveVideo', function (ignore, position, oldPosition, video) {
  123. //save the vidinfo for the log
  124. lastMovedVideo = video;
  125. //check if the video got bumped
  126. if (Math.abs(activeVideoIndex() - position) <= 10 && Math.abs(oldPosition - position) > 10) { // "It's a bump ! " - Amiral Ackbar
  127. bumpCheck = true;
  128. }
  129. });
  130.  
  131. events.on(th, 'RemoveVideo', function (ignore, video) {
  132. //save the video for the log
  133. lastRemovedVideo = video;
  134. });
  135.  
  136. events.on(th, 'Skips', function (ignore1, ignore2, percent) {
  137. //save the percentage for the log
  138. lastSkipPercentage = Math.round(percent * 100) / 100;
  139. });
  140. };
  141.  
  142. window.plugins = window.plugins || {};
  143. window.plugins.modSpy = new ModSpy('1.0.5');