Kongregate two-way messager

Allows for automatic whisper conversations, negating the need for having to constantly enter /w username to talk to the same person. "/2w username message" to start a conversation, "/2w" to end it. "/s" or "/speak" to send a message to the chatroom without ending the conversation.

  1. // ==UserScript==
  2. // @name Kongregate two-way messager
  3. // @namespace tag://kongregate
  4. // @description Allows for automatic whisper conversations, negating the need for having to constantly enter /w username to talk to the same person. "/2w username message" to start a conversation, "/2w" to end it. "/s" or "/speak" to send a message to the chatroom without ending the conversation.
  5. // @include http://www.kongregate.com/games/*
  6. // @author MrSpontaneous
  7. // @version 1.0
  8. // @date 02/27/2010
  9. // ==/UserScript==
  10. // You cannot modify or redistribute this script without permission.
  11.  
  12. // Written by MrSpontaneous (http://www.kongregate.com/accounts/MrSpontaneous) 02/27/2010
  13. // Special thanks to Ventero for his regex advice
  14. // Updated 08/15/2010 - Fixed unnecessary update alerts in Firefox 4 under some conditions
  15.  
  16. var dom = (typeof unsafeWindow === "undefined"?window:unsafeWindow);
  17.  
  18. function init_two_way() {
  19. var CDialogue = dom.ChatDialogue,
  20. CRoom = dom.ChatRoom;
  21. var holodeck = dom.holodeck;
  22. if (CDialogue){
  23. CDialogue.prototype = dom.CDprototype||dom.ChatDialogue.prototype;
  24. CRoom.prototype = dom.CRprototype||dom.ChatRoom.prototype;
  25. if(!holodeck.__two_way){
  26. holodeck.__two_way = true;
  27. holodeck._two_way_recipient = null;
  28. if (!CRoom.prototype.sendRoomMessage_twOld) {
  29. CRoom.prototype.sendRoomMessage_twOld = CRoom.prototype.sendRoomMessage;
  30. CRoom.prototype.sendRoomMessage = function(message, force) {
  31. if (!force && this.holodeck()._two_way_recipient){
  32. this.holodeck().activeDialogue().sendPrivateMessage(this.holodeck()._two_way_recipient, message);
  33. return;
  34. }
  35. this.sendRoomMessage_twOld(message);
  36. }
  37. }
  38. //Called with: /2w <username> [message]
  39. CDialogue.prototype.two_way = function (holodeck, input) {
  40. var active_dialogue = holodeck.activeDialogue();
  41. var m = input.match(/^\/(\S+)\s+(\S+)\s?(.+)*/);
  42. if (!m) { //no params
  43. active_dialogue.kongBotMessage("Now ending 2-way conversation with " + holodeck._two_way_recipient);
  44. holodeck._two_way_recipient = null;
  45. return false;
  46. }
  47. var username = m[2];
  48. var message = m[3];
  49. if (username) { //start 2way
  50. holodeck._two_way_recipient = username;
  51. active_dialogue.kongBotMessage("Now starting 2-way conversation with " + username);
  52. }
  53. if (username && message) { //if the user has defined a message, send it
  54. active_dialogue.sendPrivateMessage(username, message);
  55. }
  56. return false;
  57. }
  58. CDialogue.prototype.speak = function (holodeck, input) {
  59. var m = input.match(/^\/\S+\s+(.+)/);
  60. if (m) {
  61. holodeck.chatWindow().activeRoom().sendRoomMessage(m[1], true);
  62. }
  63. return false;
  64. }
  65. holodeck.addChatCommand("2w", CDialogue.prototype.two_way);
  66. holodeck.addChatCommand("2way", CDialogue.prototype.two_way);
  67. holodeck.addChatCommand("s", CDialogue.prototype.speak);
  68. holodeck.addChatCommand("speak", CDialogue.prototype.speak);
  69.  
  70. }
  71. }
  72. }
  73.  
  74. function check(){
  75. var injectScript = dom.injectScript||(document.getElementById("injectScriptDiv")?document.getElementById("injectScriptDiv").onclick():0);
  76. if(injectScript){
  77. injectScript(init_two_way, 200);
  78. } else if(!dom._promptedFramework && !/Chrome/i.test(navigator.appVersion)){
  79. if(confirm("You don't have the latest version of the framework-script!\n" +
  80. "Please install it, otherwise the scripts won't work.\n" +
  81. "Clicking ok will open a new tab where you can install the script"))
  82. window.open("http://userscripts.org/scripts/show/54245", "_blank");
  83. dom._promptedFramework = true;
  84. }
  85. }
  86.  
  87. setTimeout(check, 0);