InstaSynchP ModSpy

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

  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.9
  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. /^Attempt: \d+$/,
  33. /^XHR TIMEOUT$/
  34. ];
  35. }
  36.  
  37. ModSpy.prototype.executeOnce = function () {
  38. "use strict";
  39. var th = this,
  40. oldLog = window.console.log,
  41. lastRemovedVideo,
  42. lastMovedVideo,
  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> via {3}'.format(
  80. match[1],
  81. bumpCheck ? 'bumped' : 'moved',
  82. urlParser.create({
  83. videoInfo: lastMovedVideo.info
  84. }),
  85. lastMovedVideo.addedby
  86. );
  87. bumpCheck = false;
  88. } else if ((match = message.match(/([^\s]+) has banned a user\./))) {
  89. lastAction = 'banned';
  90. actiontaker = match[1];
  91. } else if ((match = message.match(/([^\s]+) has kicked a user\./))) {
  92. lastAction = 'kicked';
  93. actiontaker = match[1];
  94. } else if ((match = message.match(/([^\s]+) removed a video\./))) {
  95. message = '{0} removed a <a href="{1}" target="_blank">video</a> via {2}.'.format(
  96. match[1],
  97. urlParser.create({
  98. videoInfo: lastRemovedVideo.info
  99. }),
  100. lastRemovedVideo.addedby
  101. );
  102. } else if ((match = message.match(/([^\s]+) modified the skip ratio\./))) {
  103. message = '{0} set skip ratio to {1}%'.format(match[1], lastSkipPercentage);
  104. }
  105.  
  106. //add the message to the chat if we don't have to wait for the event to happen
  107. //user removed events gets fired after the log
  108. if (!lastAction) {
  109. addSystemMessage(message);
  110. }
  111.  
  112. oldLog.apply(window.console, arguments);
  113. };
  114.  
  115. events.on(th, 'RemoveUser', function (user) {
  116. //print the kick/ban log
  117. if (lastAction && (lastAction === 'banned' || lastAction === 'kicked')) {
  118. addSystemMessage('{0} has {1} {2}({3})'.format(actiontaker, lastAction, user.username, user.ip));
  119. lastAction = undefined;
  120. actiontaker = undefined;
  121. }
  122. });
  123.  
  124. events.on(th, 'MoveVideo', function (video, position, oldPosition) {
  125. //save the vidinfo for the log
  126. lastMovedVideo = video;
  127. //check if the video got bumped
  128. if (Math.abs(activeVideoIndex() - position) <= 10 && Math.abs(oldPosition - position) > 10) { // "It's a bump ! " - Amiral Ackbar
  129. bumpCheck = true;
  130. }
  131. });
  132.  
  133. events.on(th, 'RemoveVideo', function (video) {
  134. //save the video for the log
  135. lastRemovedVideo = video;
  136. });
  137.  
  138. events.on(th, 'Skips', function (ignore1, ignore2, percent) {
  139. //save the percentage for the log
  140. lastSkipPercentage = Math.round(percent * 100) / 100;
  141. });
  142.  
  143. events.on(th, 'AddMessage', function (user, message) {
  144. if (user.username === '' &&
  145. message.match(/^User (?:kicked|(?:un)?banned)\.?$/)) {
  146. $('#chat_messages >:last-child').hide()
  147. .find('.message').toggleClass('text-info');
  148. }
  149. });
  150. };
  151.  
  152. window.plugins = window.plugins || {};
  153. window.plugins.modSpy = new ModSpy('1.0.9');