ChatLog

Downloads all messages (including private) in current chat

  1. // ==UserScript==
  2. // @name ChatLog
  3. // @namespace http://alphaoverall.com
  4. // @version 0.7
  5. // @description Downloads all messages (including private) in current chat
  6. // @author AlphaOverall
  7. // @include *://www.kongregate.com/games/*/*
  8. // ==/UserScript==
  9.  
  10. // Check for holodeck to load
  11. function check() {
  12. if (!holodeck) { setTimeout(check, 1000);}
  13. else {
  14. console.log("[ChatLog]: Holodeck loaded");
  15. start();
  16. }
  17. } check();
  18.  
  19. // Main function
  20. function start() {
  21. holodeck.addChatCommand("chatlog", function(l, msg){
  22. let z = msg.match(/^\/\S+\s+(.+)/), type = ".txt";
  23. // Allow an optional html download
  24. if (z && z[1] == "html") type = ".html";
  25. // Get active chat message window and log
  26. let element = jQuery(".chat_room_template:visible .chat_message_window")[0];
  27. let log = element.innerText;
  28. if (type === ".html") {
  29. // Add styling to html files
  30. // Just grabbed these from Kong, probably not comprehensive or all necessary
  31. log = `
  32. <style>
  33. .chat_message_window {
  34. background-color: #fff;
  35. margin-top: 3px;
  36. max-height: 500px;
  37. overflow-x: hidden;
  38. overflow-y: auto;
  39. text-align: left;
  40. font: normal 11px/15px Verdana, Arial, sans-serif;
  41. }
  42. .chat_message_window p .timestamp {
  43. color: #888;
  44. display: block;
  45. font: 10px/12px Arial, sans-serif;
  46. text-transform: uppercase;
  47. }
  48. .chat_message_window p .username {
  49. text-decoration: none;
  50. }
  51. .chat_message_window .chat_message_window_username {
  52. color: #285588;
  53. cursor: pointer;
  54. text-decoration: underline;
  55. }
  56. .chat_message_window .is_self, .chat_message_window .sent_whisper span.username {
  57. color: #900;
  58. }
  59. .chat_message_window p .message {
  60. line-height: 14px;
  61. }
  62. .hyphenate, .hyphenate * {
  63. word-wrap: break-word;
  64. -webkit-hyphens: auto;
  65. -moz-hyphens: auto;
  66. -ms-hyphens: auto;
  67. hyphens: auto;
  68. }
  69. .chat_message_window .even {
  70. background-color: #e3e3e3;
  71. }
  72. .chat_message_window p {
  73. margin: 1px 0;
  74. padding: 4px 6px 4px 5px;
  75. }
  76. .chat_message_window .whisper {
  77. background-color: #deeaf6;
  78. font-style: italic;
  79. margin: 2px 0;
  80. }
  81. </style>`;
  82. log += `<div class="chat_message_window">${element.innerHTML}</div>`;
  83. }
  84. // Create link to download document
  85. let download = document.createElement("a");
  86. download.href = "data:text/html;charset=UTF-8," + encodeURIComponent(log);
  87. download.target = "_blank";
  88. // Set a unique name
  89. download.download = "Log_" + (new Date().toLocaleString()) + type;
  90. // Add element (needed for FF)
  91. document.body.appendChild(download);
  92. // Download it
  93. download.click();
  94. // Remove element
  95. document.body.removeChild(download);
  96. // Don't send command to chat window
  97. return false;
  98. });
  99. // Add /log as an optional form of command
  100. holodeck._chat_commands.log = holodeck._chat_commands.chatlog;
  101. }