Me-command *OLD*

Gives a "/me" command

当前为 2016-03-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Me-command *OLD*
  3. // @namespace http://www.kongregate.com/games/*
  4. // @description Gives a "/me" command
  5. // @include http://www.kongregate.com/games/*
  6. // @version 0.0.1.20160330193305
  7. // ==/UserScript==
  8.  
  9. // Rewritten by the awesome Ventero for compatibility with his scripts.
  10.  
  11. var loaded = false;
  12.  
  13. function init(){
  14. if(this.holodeck && this.ChatDialogue){
  15. loaded = true;
  16. var _holodeck = this.holodeck,
  17. styleColor = GM_getValue("kong_slashMeColor", "\#660099");
  18. GM_registerMenuCommand("Change \/me command text color", function(e) {
  19. var color = prompt("Please enter the color code in the form \#HHHHHH (default \#660099)");
  20. if (z=color.match(/(\#[0-9a-fA-F]{6})/)){
  21. styleColor=z[1]
  22. sheet = document.styleSheets[1];
  23. for (var i=0;i<sheet.cssRules.length;i++){
  24. if(sheet.cssRules[i].selectorText == "#kong_game_ui .chat_message_window .slashMe"){
  25. sheet.cssRules[i].style.color = styleColor;
  26. window.setTimeout(function(){GM_setValue("kong_slashMeColor", styleColor);}, 0);
  27. alert("Changed color to " + styleColor);
  28. }
  29. }
  30. }else{alert("Invalid format!");};
  31. });
  32.  
  33. this.ChatDialogue.prototype.oldInsertFunction1234 = this.ChatDialogue.prototype.insert;
  34.  
  35. this.ChatDialogue.prototype.insert = function (content) {
  36. var l = content.indexOf('</span>:');
  37. var c = content.indexOf('"', content.indexOf('<p class="') + 10);
  38. var k = content.indexOf('<span', c);
  39. var u = content.indexOf('username="')+10;
  40. var un = content.lastIndexOf(content.substring(u, content.indexOf('"', u)), l);
  41.  
  42. if (content.indexOf('\u200B')!=-1 && content.indexOf('\ufeff') != -1) {
  43. content = content.substring(0,c) + ' slashMe' + content.substring(c, k) + '* ' + content.substring(k, un) +
  44.  
  45. '</span>' + content.substring(l+9);
  46.  
  47. } else if(content.indexOf('\u200B')!=-1){
  48.  
  49. content = content.substring(0, c) + ' slashMe' + content.substring(c, k) + '* ' + content.substring(k, l) +
  50.  
  51. '</span>' + content.substring(l+8);
  52.  
  53. } else if (content.indexOf('\ufeff') != -1) {
  54. content = content.substring(0, c) + ' slashMe' + content.substring(c, un) + '</span>' + content.substring
  55.  
  56. (l+9);
  57. }
  58.  
  59. this.oldInsertFunction1234(content);
  60. }
  61. this.holodeck.addChatCommand("me", function(l,n) {
  62. l.chatWindow().activeRoom().sendRoomMessage('\u200B' + n.substring(n.indexOf('\/me ') + 4));
  63. return false;
  64. });
  65. this.holodeck.addChatCommand("nouser", function(l,n) {
  66. l.chatWindow().activeRoom().sendRoomMessage('\ufeff' + n.substring(n.indexOf('\/nouser ') + 8));
  67. return false;
  68. });
  69. sheet = document.styleSheets[1];
  70. sheet.insertRule('#kong_game_ui .chat_message_window .slashMe { color:'+styleColor+';}',sheet.cssRules.length);
  71. } else {
  72. setTimeout(init, 1000);
  73. }
  74. };
  75.  
  76. if (!loaded) {
  77. setTimeout(init, 1500);
  78. };