// ==UserScript==
// @name        AIM Enhanced
// @description Improves posting on AIM. Adds partial markdown support and other fun stuff.
// @namespace   notareal@em.ail
// @include     http://aimgames.forummotion.com/post
// @include     http://aimgames.forummotion.com/post*
// @version     0.4
// @grant       GM_addStyle
// @license     MIT License (Expat); opensource.org/licenses/MIT
// ==/UserScript==

'use strict';

// custom code styles
const style = `<style type="text/css">
pre {
    max-height: 200px;
    overflow: auto;
    /**/
    color: #ff6913;
    font-family: Courier,"Courier New","Source Code Pro",monospace;
    font-size: 11px;
    /* box */
    background-color: #000;
    border: solid 1px #1c1c1c;
    margin: 0;
    /* possibly? */
    margin-left: 60px;
}
/* inline code, shit that isnt deprecated in html5 */
samp {
    color: #ff6913;
    font-family: Courier,"Courier New","Source Code Pro",monospace;
}
</style>`;

const styleMin = style
  .replace(/^\s+/gm, '') // remove whitespace
  .replace(/(\r\n|\n)/g, '') // remove newlines
  .replace(/\/\*([^]+?)\*\//g, ''); // remove comments

// add style to the beginning of every post
const textArea = document.getElementById('text_editor_textarea');
if (textArea) {
  textArea.value = styleMin + '\n' + textArea.value;
}

$(document).on('keydown', function(e) {
  if (e.which == 13) { // key is 'enter'
    textArea.value = textArea.value
      .replace(/\[cd\]([^]+?)\[\/cd\]/g, '<pre>$1</pre>')
      .replace(/`([^]+?)`/g, '<samp>$1</samp>');
  }
});

@@ -293,9 +293,9 @@
   0.
-4
+5
 %0A// 
@@ -1298,17 +1298,29 @@
 lue;%0A%7D%0A%0A
-$
+window.jQuery
 (documen

fix jQuery