AFK-command (for Chrome 1.x)

Adds /afk to chat as well as an afk message

  1. // ==UserScript==
  2. // @name AFK-command (for Chrome 1.x)
  3. // @namespace ventero.de
  4. // @description Adds /afk to chat as well as an afk message
  5. // @include http://www.kongregate.com/games/*
  6. // @author Ventero
  7. // @license MIT license
  8. // @version 0.0.1.20160323020800
  9. // ==/UserScript==
  10.  
  11. // Written by Ventero (http://www.kongregate.com/accounts/Ventero) 05/12/09
  12. // Copyright (c) 2009-2012 Ventero, licensed under MIT/X11 license
  13. // http://www.opensource.org/licenses/mit-license.php
  14. // Thanks to Jabor (http://www.kongregate.com/accounts/Jabor) for the idea of adding a prefix!
  15.  
  16.  
  17. function init(){
  18. if(location.href.indexOf("http://www.kongregate.com/games/")==0){
  19. holodeck.addChatCommand("afk",function (l, n) { if (l._afk == 0) { l._afk = 1; l.activeDialogue().displayMessage("Kong Bot", "You are now flagged as AFK", {class: "whisper received_whisper"}, {non_user: true}); } else {l._afk = 0; l.activeDialogue().displayMessage("Kong Bot", "You aren't flagged as AFK anymore", {class: "whisper received_whisper"}, {non_user: true}); } return false; });
  20.  
  21. holodeck.addChatCommand("afkmessage", function (l, n){ var z = n.match(/^\/\S+\s+(.+)/); if (z){a = z[1]}else{a="I am currently AFK"} l._afkmessage = a; l.activeDialogue().displayMessage("Kong Bot", "AFK-message set to: "+a, {class: "whisper received_whisper"}, {non_user: true}); return false});
  22.  
  23. holodeck.addChatCommand("afktoggle", function(l, n){ if (l._afktoggle == 0) {l._afktoggle = 1; l.activeDialogue().displayMessage("Kong Bot", "Your AFK-flag won't get removed automatically", {class: "whisper received_whisper"}, {non_user: true})} else {l._afktoggle = 0; l.activeDialogue().displayMessage("Kong Bot", "Your AFK-flag gets removed automatically", {class: "whisper received_whisper"}, {non_user: true})} return false; });
  24.  
  25. ChatDialogue.prototype.oldKeyPress = ChatDialogue.prototype.onKeyPress;
  26.  
  27. ChatDialogue.prototype.onKeyPress = function (a) { if (a.which == 13) { if(this._holodeck._afktoggle==0 && this._input_node.getValue().indexOf("/afk")!=0){this._holodeck._afk = 0}; this.sendInput(); a.stop(); } else{this.oldKeyPress(a)}};
  28.  
  29. ChatDialogue.prototype.receivedPrivateMessage = function (a) { if (a.data.success) { nL=a.data.from;this.displayUnsanitizedMessage(a.data.from, this.sanitizeIncomingMessage(a.data.message) + "&nbsp; (<a class=\"reply_link\" onclick=\"holodeck.insertPrivateMessagePrefixFor('" + a.data.from + "');return false;\" href=\"#\">reply</a>)", {class: "whisper received_whisper"});if(this._holodeck._afk && a.data.message.indexOf(this._holodeck._afkprefix)!=0){this.sendPrivateMessage(a.data.from, this._holodeck._afkprefix+this._holodeck._afkmessage)}; } else { this.displayMessage("Kong Bot", a.data.to + " can not be reached. Please try again later.", {class: "whisper received_whisper"}, {non_user: true}); } };
  30.  
  31. holodeck._afk = 0;
  32.  
  33. holodeck._afktoggle = 0;
  34.  
  35. holodeck._afkmessage = "I am currently AFK";
  36.  
  37. holodeck._afkprefix = "[AFK] ";
  38. }
  39. }
  40.  
  41. setTimeout(init, 1000);
  42.