Whisper Filter

Lets you hide every message except the whispers between you and another user

  1. // ==UserScript==
  2. // @name Whisper Filter
  3. // @namespace com.resterman
  4. // @version 0.3.0
  5. // @description Lets you hide every message except the whispers between you and another user
  6. // @author resterman
  7. // @match http://www.kongregate.com/games/*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /* jshint esnext: true */
  12.  
  13. (function() {
  14. 'use strict';
  15. checkHolodeck();
  16. })();
  17.  
  18. function checkHolodeck() {
  19. if (typeof holodeck !== "undefined" && holodeck.ready) init();
  20. else setTimeout(checkHolodeck, 100);
  21. }
  22.  
  23. function init() {
  24. 'use strict';
  25. Holodeck.prototype.showConversationWith = function (user) {
  26. if (this.whisperFilter && this.whisperFilter.user == user) this.showAllMessages();
  27. else this.showWhispersOnly(user);
  28. };
  29.  
  30. Holodeck.prototype.showAllMessages = function () {
  31. var w = this.activeDialogue()._message_window_node;
  32. var prop = this.whisperFilter;
  33. w.select('.chat-message')
  34. .map(x => x.show())
  35. .reduce(() => [1])
  36. .map(x => w.scrollTop = prop.scrollTop);
  37. this.whisperFilter = null;
  38. };
  39.  
  40. Holodeck.prototype.showWhispersOnly = function (user) {
  41. var w = this.activeDialogue()._message_window_node;
  42. this.whisperFilter = {
  43. [user?'user':'mostrandoTodosLosWhispers']: user?user:true,
  44. scrollTop: w.scrollTop
  45. };
  46.  
  47. w.select('.chat-message')
  48. .map(x => x.hide())
  49. .filter(x => x.select('.whisper').length > 0)
  50. .filter(x => {
  51. var u = x.select('.username');
  52. return u.length > 0 && (!user||new RegExp(user, 'i').test(u[0].readAttribute('username')));
  53. })
  54. .map(x => x.show());
  55. };
  56.  
  57. Holodeck.prototype.getWhisperUsers = function () {
  58. var users = this.activeDialogue()._message_window_node.select('.chat-message')
  59. .filter(x => x.select('.whisper').length > 0)
  60. .map(x => x.select('.username')[0].readAttribute('username').toLowerCase());
  61.  
  62. return new Set(users);
  63. };
  64.  
  65. ChatDialogue.MESSAGE_TEMPLATE.evaluateAntesDeWF=ChatDialogue.MESSAGE_TEMPLATE.evaluate;
  66.  
  67. ChatDialogue.MESSAGE_TEMPLATE.evaluate=function(a){
  68. const regExp=/(<a.*onclick=")(.*(\('.{4,16}'\));return.*)/i;
  69. if(a.message) a.message=a.message.replace(regExp, '$1if(event.ctrlKey) holodeck.showConversationWith$3; else $2');
  70. return ChatDialogue.MESSAGE_TEMPLATE.evaluateAntesDeWF(a);
  71. };
  72.  
  73. ChatDialogue.prototype.sendPrivateMessageAntesDeWF=ChatDialogue.prototype.sendPrivateMessage;
  74.  
  75. ChatDialogue.prototype.sendPrivateMessage=function(a, b){
  76. this.sendPrivateMessageAntesDeWF(a, b);
  77. for(var room in this._holodeck._chat_window._rooms._object){
  78. if(this._holodeck._chat_window._rooms._object[room]._chat_dialogue!=this){
  79. this._holodeck._chat_window._rooms._object[room]._chat_dialogue.displayMessage(a, b, {"class": "whisper sent_whisper"}, {"private": !0});
  80. }
  81. }
  82. };
  83.  
  84. holodeck.whisperFilter=null;
  85.  
  86. holodeck.addChatCommand('wf', function (a, b) {
  87. var args = b.split(' ');
  88. if (args.length >= 2) {
  89. var username = null;
  90. for (var user of holodeck.getWhisperUsers()) {
  91. if (new RegExp('^' + args[1].toLowerCase(), 'i').test(user)) {
  92. username = user;
  93. break;
  94. }
  95. }
  96.  
  97. if (username) {
  98. holodeck.showConversationWith(username.toLowerCase());
  99. } else {
  100. holodeck.activeDialogue().displayMessage(
  101. "Whisper Filter",
  102. "You have no whispers with " + args[1],
  103. {"class": "whisper received_whisper"},
  104. {non_user: !0}
  105. );
  106. }
  107. }
  108. else if(holodeck.whisperFilter && (holodeck.whisperFilter.user || holodeck.whisperFilter.mostrandoTodosLosWhispers)) holodeck.showAllMessages();
  109. else if(!holodeck.getWhisperUsers().size) holodeck.activeDialogue().displayMessage(
  110. "Whisper Filter",
  111. "You have no whispers",
  112. {"class": "whisper received_whisper"},
  113. {non_user: !0}
  114. );
  115. else holodeck.showConversationWith();
  116.  
  117. return !1;
  118. });
  119. }