InstaSynchP ModSpy

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

当前为 2014-10-25 提交的版本,查看 最新版本

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