//[BEGIN PREFERENCES: Edit these variables. Names explain their function] //
var advancedSearch   = false; // Broken, doesn't work
var admbutton        = false;
var disableMainStyle = false;
var linkMeForm       = true;
var pageJump         = true;
var postButtons      = true;
var quickPost        = true;
var sig              = 'http://owwww.ytmnd.com/\n<b>OWWW</b>'; // Any line returns must have a "\" before them (no quotes). Also, replace any "'"s with "\'" and any "\"s with "\\" If some characters get messed up, try encoding it with this: http://www.codehouse.com/webmaster_tools/html_encoder/
var stylesheetLink   = ''; // Same with this
var specialLinks     = true;
var noTopicStretch   = true;
var highlightNames   = Array();
var blacklistNames   = Array();
var highlightColor   = '#CCFFFF'; // or the color name (red, black, etc.)
var highlightMsgs    = true;
var highlightTpcs    = true;
var blacklistColor   = '#999999'; // or the color name (red, black, etc.)
var blacklistMsgs    = true;
var blacklistTpcs    = true;
var modAbuseBlock    = true;
var messageNumbering = true;
//[END PREFERENCES: touch anything else, don't come crying to me when it doesn't work] //

var foxlinksLastStyle;
var foxlinksSocialBoards = new Array
(
  'Social Boards',
  new Array(42, 'Life, the Universe, and Everything', 'Discussion of everything'),
  new Array(54494, 'Referral Mania', 'The land of broken dreams'),
  new Array(58, 'Serious Discussion', 'Serious discussion only, suspensions will be harsh'),
  new Array(30000, 'Flamers', 'Flaming and hate goes here. Not in LUE.'),
  new Array(51, 'Pipe Mania', 'Got drugs? Discuss them here. No illegal activity (ie, buying / selling) allowed'),
  new Array(47, 'Hacking and Cracking', 'For all you wannabe (but never will be) hackers'),
  new Array(52, 'Video Games', 'A forum to discuss video games', new Array (
      new Array(44, 'ROMs', 'For the gamer in us all')
    )
  ),
  new Array(43, 'Bittorrents', 'Post your bittorrents here', new Array (
      new Array(70, 'Requests', 'Requests go here')
    )
  ),
  new Array(48, 'Media and Entertainment', 'TV, Movies, Music', new Array (
      new Array(46, 'Anime', 'If it\'s Japanese and animated it\'s here')
    )
  ),
  new Array(69, 'Porn', 'Porn requests and contributions go here', new Array (
      new Array(55, 'Requests', 'If you\'re not posting porn, it better go here'),
      new Array(53, 'Hentai Paradise', 'For all your cartoon porn needs')
    )
  ),
  new Array(50, 'LUE Events', 'Anything interesting that happens on LUE should be posted here'),
  new Array(71, 'Homework', 'hhahahahahahhahdsfagh you guys are still in high school') // hey LlamaGuy, I'm still in high school. >:(
);
var foxlinksSiteBoards = new Array
(
  'Site Boards',
  new Array(56, 'Complaints Department', 'Post complaints about vote spamming \\ invalid tokens here'),
  new Array(1337, 'Break the boards!', 'Where anything goes'),
  new Array(45, 'Site Suggestions', 'Feel free to post any ideas you have here'),
  new Array(57, 'Suicide', 'POSTING ON THIS BOARD WILL GET YOU SUSPENDED. NOT JOKING'),
  new Array(49, 'The Daily Poll', 'Comments on whatever the poll is for the day')
);
var foxlinksCoolBoards = new Array
(
  'Cool People',
  new Array(59, 'Cool People', 'People with at least 1 token'),
  new Array(61, 'Coolest People', 'People with at least 25 tokens'),
  new Array(60, 'Cooler People', 'People with at least 10 tokens'),
  new Array(62, 'Coolest(er) People', 'People with at least 50 tokens')
);
var foxlinksSecretBoards = new Array
(
  'Secret Boards',
  new Array(-2583092, 'Flower... power?', 'LOL GURLS ONLY'),
  new Array(-2700, 'I didn\'t win!', 'Bizarbus\'s board'),
  new Array(-666, 'Shahin', 'Peacer Washington\'s board'),
  new Array(-86, 'Suspensions and Bans', 'Moderators Only'),
  new Array(-85, 'Moderator Social', 'Moderators Only'),
  new Array(-84, 'The Cheese Factory', 'Moderators Only'),
  new Array(13, 'Rocks are not Potatoes', 'Rev4n\'s board'),
  new Array(18, 'The World That I Know', 'You Kicked My Dog\'s board'),
  new Array(24, 'Counter-Terrorist Unit', 'legolasfan\'s board'),
  new Array(54, 'LUEshi', ''),
  new Array(98, 'Jawsome.', 'Frinkahedron\'s board'),
  new Array(100, 'Alexander\'s Place', 'DragoonAlexander\'s board'),
  new Array(204, 'Mostly Harmless', 'Seiru\'s board'),
  new Array(212, 'Jesus Ranch', 'Violent Azure\'s board'),
  new Array(241, 'Treasure Chest Of Lust And Mortal Sin', 'GreatOlibu731\'s board'),
  new Array(255, 'Game Over', 'Shynkz\'s board'),
  new Array(328, 'MRG Land', 'MRG\'s board'),
  new Array(333, 'S.S. MORE POWERFUL THAN SUPERMAN, BATMAN, SPIDERMAN, AND THE INCREDIBLE HULK ALL PUT TOGETHER', 'Kelladros\'s board'),
  new Array(368, '.', 'RunsWithScissors\' board'),
  new Array(524, 'without a cause\'s Lair of Unfathomable Awesomeness', 'without a cause\'s board'),
  new Array(545, 'The Board of Hopeless Fate', 'allalone05\'s board'),
  new Array(555, 'Another Castle', 'liche1\'s board'),
  new Array(662, 'IBKM', 'In Before KenMan!'),
  new Array(666, 'Diablo\'s Lair', 'DiabloNeonX\'s board'),
  new Array(777, 'Top Secret Area', 'KeithX\'s board'),
  new Array(800, 'Jelly Soup\'s ToyBox', 'Jelly Soup\'s board'),
  new Array(884, 'The Eternal Enigma', 'RedXevious\'s board'),
  new Array(1024, '*Smacks you with a Waffle Iron*', 'Fox1337\'s board'),
  new Array(1234, 'Guam', 'chris1001 the sequel\'s board'),
  new Array(1691, 'EUGWNGOPWTMDC', 'COTM\'s board'),
  new Array(1908, 'I HEART U', 'Prior22\'s board'),
  new Array(1999, 'International House of Waffled Roffles', 'redkillroy\'s board'),
  new Array(2112, 'The Bethlehem Disco', 'Dancin Jesus\' board'),
  new Array(6191, 'Use Bombs Wisely', 'Lucid Faia\'s board'),
  new Array(6496, 'Chokey Chicken', 'PureGamer\'s board'),
  new Array(6700, '6700', 'Mystikal Bomb\'s board'),
  new Array(8000, 'LUE Radio', 'Online radio created by LUEsers'),
  new Array(17074, 'AnotherGamer\'s Pit of Furry Madness', 'AnotherGamer\'s board'),
  new Array(32767, 'The Restaurant at the End of the Universe', 'junkievegeta\'s board'),
  new Array(268170, 'The Bebop', 'TheRealFolkBlues\' board'),
  new Array(604753, 'HaLUE', 'LUElink\'s Halo board'),
  new Array(8675309, 'Jenny', 'I got it! I got I got it!'),
  new Array(11111101, 'The Starlight Theater', 'Tails3\'s board')
);

document.addEventListener('load', foxlinks, false);

function foxlinks()
{
  var i, j, k, l;
  var doc = this;
  if (!document.location.host.match(/^(?:.+?\.)?luelinks\.net$/i) && !doc.location.host.match(/^(?:72\.21\.46\.234|0x48\.0x15\.0x2e\.0xea|0110\.0025\.0056\.0352|0x48152eea|1209347818)$/i)) {
    return; // This isn't LUElinks
  }
  if (doc.getElementsByTagName('link').length == 0 || doc.location.pathname == '/index.php' || doc.location.pathname == '/') {
    return; // Leave the text-only pages alone
  }
  //var prefs  = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch('foxlinks.');
  var divs           = doc.getElementsByTagName('div');
  var head           = doc.getElementsByTagName('head')[0];
  var newHTML        = (doc.body.firstChild.nodeName == '#text') ? true : false;
  var userid         = doc.cookie.match(/userid=([0-9]+)/i); // OMG I'M LOOKING AT YOUR COOKIES!!!
  var stylesheet     = doc.getElementsByTagName('link')[0];
  var globalStyles   = doc.createElement('style');
  globalStyles.type  = 'text/css';
  if (stylesheet.href.match(/\/[n]?css\.php$/)) {
    var pageBg = window.getComputedStyle(doc.body, null).getPropertyValue('background-color');
    for (i = 0; i < divs.length; i++) {
      if (divs[i].className == 'infobar') {
        var bgColor = window.getComputedStyle(divs[i], null).getPropertyValue('background-color');
        break;
      }
    }
    var linkColor = window.getComputedStyle(doc.getElementsByTagName('a')[0], null).getPropertyValue('color');
    var linkVisited = window.getComputedStyle(doc.getElementsByTagName('a')[0], ':visited').getPropertyValue('color');
    var linkHover = window.getComputedStyle(doc.getElementsByTagName('a')[0], ':hover').getPropertyValue('color');
    var linkActive = window.getComputedStyle(doc.getElementsByTagName('a')[0], ':active').getPropertyValue('color');
    if (divs.length > 0 && divs[0].className == 'menubar') {
      var bgColor2 = window.getComputedStyle(divs[0], null).getPropertyValue('background-color');
    } else {
      var bgColor2 = window.getComputedStyle(doc.getElementsByTagName('th')[0], null).getPropertyValue('background-color');
    }
  } else {
    var pageBg = '#FFFFFF';
    var bgColor = '#8080FF';
    var linkColor = '#FFFFFF';
    var linkVisited = '#FFFFFF';
    var linkHover = '#FFFF00';
    var linkActive = '#FF0000';
    var bgColor2 = '#6666FF';
  }
  if (doc.location.pathname == '/showmessages.php' ||
      doc.location.pathname == '/linkme.php') {
    if (modAbuseBlock) {
      var scripts = head.getElementsByTagName('script');
      while (scripts.length) {
        scripts[0].parentNode.removeChild(scripts[0]);
      }
      var styles = head.getElementsByTagName('style');
      while (styles.length) {
        styles[0].parentNode.removeChild(styles[0]);
      }
      var metas = head.getElementsByTagName('meta');
      while (metas.length) {
        metas[0].parentNode.removeChild(metas[0]);
      }
      doc.body.innerHTML = doc.body.innerHTML.replace(/<[\/]?(?:blink|marquee|tt|sub|sup|big|hr|h[3-6]|strong|abbr|acronym|address|bdo|blockquote|cite|q|code|ins|del|dfn|font|kbd|samp|var|ul|ol|li|dl|dt|dd|area|map|param|base|form|input|textarea|select|option|optgroup|button|label|fieldset|legend|tbody|thead|tfoot|col|colgroup|caption|noscript|noembed|noframes).*?>/ig, '').replace(/<[a-z0-9]+.*?style=.*?>/ig, '').replace(/<[a-z0-9]+.*?on(?:click|mouseover|mouseout|load|unload|focus|blur|mousemove|dblclick|keypress|keydown|keyup|reset|select|change|mousedown|mouseup)=.*?>/ig, '');
    }
    var pageNum = doc.location.search.match(/page=([0-9]+)/);
    pageNum = pageNum ? pageNum[1] : 1;
    var topicNum = doc.location.search.match(/topic=([0-9]+)/);
    if (!topicNum) {
      topicNum = doc.body.innerHTML.match(/<b>Code\:<\/b> LL([a-f0-9]+)/);
      topicNum = 'link='+parseInt(topicNum[1], 16);
    } else {
      topicNum = 'topic='+topicNum[1];
    }
    var j = ((pageNum - 1) * 50) + 1;
    for (i = 0; i < divs.length; i++) {
      if (divs[i].className == 'message' && modAbuseBlock) {
        var scripts = divs[i].getElementsByTagName('script');
        while (scripts.length) {
          scripts[0].parentNode.removeChild(scripts[0]);
        }
        var imgs = divs[i].getElementsByTagName('img');
        while (imgs.length) {
          var ireplacment = doc.createElement('a');
          ireplacment.href = imgs[0].src;
          ireplacment.appendChild(doc.createTextNode('Image'));
          imgs[0].parentNode.replaceChild(ireplacment, imgs[0]);
          if (!ireplacment.nextSibling){
            ireplacment.parentNode.appendChild(doc.createTextNode(' '));
          } else {
            ireplacment.parentNode.insertBefore(doc.createTextNode(' '), ireplacment.nextSibling);
          }
        }
        var embeds = divs[i].getElementsByTagName('embeds');
        while (embeds.length) {
          var ereplacment = doc.createElement('a');
          ereplacment.href = embeds[0].src;
          ereplacment.appendChild(doc.createTextNode('Embed File'));
          embeds[0].parentNode.replaceChild(ereplacment, embeds[0]);
          if (!ereplacment.nextSibling) {
            ereplacment.parentNode.appendChild(doc.createTextNode(' '));
          } else {
            ereplacment.parentNode.insertBefore(doc.createTextNode(' '), ereplacment.nextSibling);
          }
        }
        var objects = divs[i].getElementsByTagName('object');
        while (objects.length) {
          var oreplacment = doc.createElement('a');
          oreplacment.href = objects[0].data ? objects[0].data : 'javascript:;';
          oreplacment.appendChild(doc.createTextNode('Object File'));
          objects[0].parentNode.replaceChild(oreplacment, objects[0]);
          if (!oreplacment.nextSibling) {
            oreplacment.parentNode.appendChild(doc.createTextNode(' '));
          } else {
            oreplacment.parentNode.insertBefore(doc.createTextNode(' '), oreplacment.nextSibling);
          }
        }
        divs[i].innerHTML = divs[i].innerHTML.replace(/<[\/]?(?:blink|marquee|tt|sub|sup|small|big|hr|h[1-6]|strong|em|abbr|acronym|address|bdo|blockquote|cite|q|code|ins|del|dfn|font|kbd|samp|var|ul|ol|li|dl|dt|dd|area|map|param|base|form|input|textarea|select|option|optgroup|button|label|fieldset|legend|tbody|thead|tfoot|col|colgroup|caption|noscript|noembed|div|table|tr|td|th).*?>/ig, '').replace(/<[a-z0-9]+.*?style=.*?>/ig, '').replace(/<[a-z0-9]+.*?on(?:click|mouseover|mouseout|load|unload|focus|blur|mousemove|dblclick|keypress|keydown|keyup|reset|select|change|mousedown|mouseup)=.*?>/ig, '');
      }
    }
    for (i = 0; i < divs.length; i++) { // so the editing of the page via innerHTML doesn't mess with the event listeners
      if (divs[i].className == 'messagetop') {
        var posterName = divs[i].getElementsByTagName('a')[0].textContent;
        for (k = 0; k < blacklistNames.length; k++) {
          if (posterName == blacklistNames[k]) {
            divs[i].appendChild(doc.createTextNode(' | '));
            var toggle = doc.createElement('a');
            toggle.className = 'foxlinksLink';
            toggle.appendChild(doc.createTextNode('Show'));
            toggle.addEventListener('click', foxlinksBlacklist, false);
            divs[i].appendChild(toggle);
            divs[(i * 1) + 1].style.setProperty('display', 'none', 'important');
            if (blacklistMsgs) {
              divs[i].style.setProperty('background-color', blacklistColor, 'important');
            }
            break;
          }
        }
        if (highlightMsgs) {
          for (k = 0; k < highlightNames.length; k++) {
            if (posterName == highlightNames[k]) {
              divs[i].style.setProperty('background-color', highlightColor, 'important');
              break;
            }
          }
        }
        if (messageNumbering) {
          divs[i].appendChild(doc.createTextNode(' | #' + '0000'.substr(0, 4-j.toString().length) + j++));
        }
      }
    }
    if (quickPost) {
      var boardId = doc.body.innerHTML.match(/<a.+?showtopics\.php\?board=([\-]?[0-9]+).+?>Topic List<\/a>/i);
      var topicId = doc.location.search.match(/topic=([0-9]+)/);
      var linkId  = doc.body.innerHTML.match(/<b>Code\:<\/b> LL([a-f0-9]+)/);
      if (linkId) {
        linkId = parseInt(linkId[1], 16);
      }
      var quickReply = doc.createElement('form');
      quickReply.name = 'f';
      quickReply.method = 'post';
      quickReply.action = 'postmsg.php';
      quickReply.id = 'foxlinksQuickReply';
      quickReply.style.setProperty('padding-left', '8px', null);
      var theRules = doc.createElement('span');
      theRules.style.setProperty('color', '#ff0000', null);
      var label = doc.createElement('b');
      label.appendChild(doc.createTextNode('The rules:'));
      theRules.appendChild(label);
      theRules.appendChild(doc.createTextNode(' Don\'t be an ass hat. I will ban'));
      quickReply.appendChild(theRules);
      quickReply.appendChild(doc.createElement('br'));
      quickReply.appendChild(doc.createElement('br'));
      yourMessage = doc.createElement('b');
      yourMessage.appendChild(doc.createTextNode('Your Message'));
      quickReply.appendChild(yourMessage);
      quickReply.appendChild(doc.createElement('br'));
      quickReply.appendChild(doc.createTextNode('Enter your message text below.'));
      quickReply.appendChild(doc.createElement('br'));
      var tBox = doc.createElement('textarea');
      tBox.cols = 60;
      tBox.rows = 20;
      tBox.name = 'message';
      tBox.wrap = 'virtual';
      var val = sig != '' && sig != null ? "\n" + '---' + "\n" + sig : '';
      tBox.value = val;
      tBox.defaultValue = val;
      var quickPostBttn = doc.createElement('input');
      quickPostBttn.type = 'button';
      quickPostBttn.value = 'QuickPost';
      quickPostBttn.addEventListener('click', foxlinksQuickPost, false);
      var previewBttn = doc.createElement('input');
      previewBttn.type = 'submit';
      previewBttn.name = 'preview';
      previewBttn.value = 'Preview Message'
      quickReply.appendChild(tBox);
      quickReply.appendChild(doc.createElement('br'));
      quickReply.appendChild(doc.createElement('br'));
      if (linkId && !boardId && !topicId) {
        var hidLink = doc.createElement('input');
        hidLink.type = 'hidden';
        hidLink.name = 'link';
        hidLink.value = linkId;
        quickReply.appendChild(hidLink);
      } else {
        var hidTopic = doc.createElement('input');
        hidTopic.type = 'hidden';
        hidTopic.name = 'topic';
        hidTopic.value = topicId[1];
        quickReply.appendChild(hidTopic);
        var hidBoard = doc.createElement('input');
        hidBoard.type = 'hidden';
        hidBoard.name = 'board';
        hidBoard.value = boardId[1];
        quickReply.appendChild(hidBoard);
      }
      quickReply.appendChild(quickPostBttn);
      quickReply.appendChild(doc.createTextNode(' '));
      quickReply.appendChild(previewBttn);
      divs[divs.length - 1].parentNode.insertBefore(quickReply, divs[divs.length - 1].nextSibling);
    }
  }
  if (doc.getElementsByTagName('textarea').length >= 1 && postButtons) {
    var tAreas = doc.getElementsByTagName('textarea');
    for (i = 0; i < tAreas.length; i++) {
      var bBttn = doc.createElement('input');
      bBttn.type = 'button';
      bBttn.id = 'b';
      bBttn.accessKey = 'b';
      bBttn.name = 'Bold';
      bBttn.value = 'Bold';
      bBttn.addEventListener('click', foxlinksButtons, false);
      var iBttn = doc.createElement('input');
      iBttn.type = 'button';
      iBttn.id = 'i';
      iBttn.accessKey = 'i';
      iBttn.name = 'Italic';
      iBttn.value = 'Italic';
      iBttn.addEventListener('click', foxlinksButtons, false);
      var uBttn = doc.createElement('input');
      uBttn.type = 'button';
      uBttn.id = 'u';
      uBttn.accessKey = 'u';
      uBttn.name = 'Underline';
      uBttn.value = 'Underline';
      uBttn.addEventListener('click', foxlinksButtons, false);
      var preBttn = doc.createElement('input');
      preBttn.type = 'button';
      preBttn.id = 'pre';
      preBttn.accessKey = 'p';
      preBttn.name = 'Preformated';
      preBttn.value = 'Preformated';
      preBttn.addEventListener('click', foxlinksButtons, false);
      if (admbutton) {
        var admBttn = doc.createElement('input');
        admBttn.type = 'button';
        admBttn.id = 'adm';
        admBttn.accessKey = 'a';
        admBttn.name = 'Admin';
        admBttn.value = 'Admin';
        admBttn.addEventListener('click', foxlinksButtons, false);
      }
      tAreas[i].parentNode.insertBefore(bBttn, tAreas[i]);
      tAreas[i].parentNode.insertBefore(doc.createTextNode(' '), tAreas[i]);
      tAreas[i].parentNode.insertBefore(iBttn, tAreas[i]);
      tAreas[i].parentNode.insertBefore(doc.createTextNode(' '), tAreas[i]);
      tAreas[i].parentNode.insertBefore(uBttn, tAreas[i]);
      tAreas[i].parentNode.insertBefore(doc.createTextNode(' '), tAreas[i]);
      tAreas[i].parentNode.insertBefore(preBttn, tAreas[i]);
      if (admbutton) {
        tAreas[i].parentNode.insertBefore(doc.createTextNode(' '), tAreas[i]);
        tAreas[i].parentNode.insertBefore(admBttn, tAreas[i]);
      }
      tAreas[i].parentNode.insertBefore(doc.createElement('br'), tAreas[i]);
    }
  }
  // For the styles of some content added with this extension
  globalStyles.appendChild(doc.createTextNode('div.linkme { padding: 1px; position: absolute; width: auto; } a.foxlinksLink { cursor: pointer; text-decoration: underline; } div.topicdiv { overflow: hidden; } div#topbar { right: 12px; top: 7px; } div#classic { right: 2px; top: -2px; } a.more { text-indent: 1em; } ul.menu li { list-style-type: none; text-align: left; width: auto; } ul.menu ul a, div.sdiv a { display: block; width: auto; } div.special { background-color: transparent; display: inline; height: 20px; left: 3px; overflow: visible; position: absolute; text-indent: 4px; top: 13px; width: auto; } ul.menu > li > ul.blist > li, div.sdiv > ul.blist > li{ max-width: 460px; } ul.menu, ul.menu ul { margin: 0px; width: auto !important; } td.jump ul.menu ul { display: none; } td.jump ul.menu li> ul { position: static; } li { display: block; width: auto; } ul.menu { padding: 1px; } td.jump { font-size: 10px !important; width: 30px; } td.jump ulli { width: 30px !important; } td.jump ul { height: auto; margin-top: 0px !important; position: absolute; width: 30px !important; } td.jump ul a { display: block !important; font-weight: bold; width: 30px !important; } li > div { padding: 2px; } li > div, div.info { display: none; } li:hover > div, div.sdiv:hover > div { text-indent: 0px !important; background-color: gray !important; color: white; display: block; float: right; font-size: 9.5pt; font-weight: normal; left: 9px; position: fixed; top: 9px; width: 251px !important; -moz-border-radius: 0px !important; -moz-opacity: 1 !important; } div.sdiv { display: inline; height: auto; margin: auto; max-width: 460px; padding: 0px; width: auto; } div.special *, div.sdiv * { border: 1px transparent solid; max-width: 460px; overflow: visible; width: inherit; -moz-border-radius: 0px 0px 20px 20px; } div.classicSpecial { display: inline; } div.sdiv * { -moz-border-radius: 0px 20px 20px 0px; } div.sdiv > ul.blist { left: 0px !important; }'));
  if (stylesheetLink != '') {
    globalStyles.appendChild(doc.createTextNode(stylesheetLink));
  }
  var specialLinks = new Array (
    new Array('profile.php?user=' + userid[1], 'My User Info Page', 'I can see your cookies...'),
    new Array('boardlist.php', 'Boards (List)', 'LUElinks Board List'),
    new Array('loser.php', 'Loser', 'Very basic stats of your LUElinks account'),
    new Array('eyes.php', 'MY EYES!', 'The doctor says it\'ll take 5 minutes before I can see again'),
    new Array('', 'Other>', 'Other stuff you can find on LUElinks')
  );
  var completeList = new Array(foxlinksSocialBoards, foxlinksSiteBoards, foxlinksCoolBoards, foxlinksSecretBoards);
  var userLinks = new Array (
    new Array('editprofile.php', 'Edit Profile', 'Change your email address, signature, and not much else'),
    new Array('editdisplay.php', 'Edit Display', 'Change the colors and layout of the site'),
    new Array('editpass.php', 'Edit Password', 'Because this extension steals yours... No, I lied, it doesn\'t.'),
    new Array('history.php', 'View Posted Messages', 'Well, only the ones in unarchived topics.'),
    new Array('linkhistory.php', 'View LUElink Comment History', 'View which links you\'ve commented on'),
    new Array('tokenlist.php?user=' + userid[1], 'View Tokens', 'View the tokens other users gave you'),
    new Array('mytokens.php?user=' + userid[1], 'View Available Tokens', 'View the tokens you\'ve given to other users'),
    new Array('shop.php', 'Enter The Token Shop', 'Spend your Contribution tokens on random junk here'),
    new Array('showfavorites.php', 'View Tagged Topics', 'View all those topics you tagged'),
    new Array('links.php?mode=user&userid=' + userid[1], 'View Added Links', 'View all those links you added. Or see why all the users flame you for lack of contribution to the site.'),
    new Array('priv.php', 'View Private Messages', 'Or "Private Except LlamaGuy Can See Them For Any Reason He Makes Messages". But PM is easier to remember than PELCSTFARHMM.')
  );
  var otherFiles = new Array (
    new Array('closed.gif', 'Lock', 'Okay, so this isn\'t really a secret...'),
    new Array('paypal.gif', 'PayPal icon', 'GIEV LLAAMGUI J00R MONNIES~!!'),
    new Array('favicon.ico', 'FavIcon', 'It\'s Yoshi, lol'),
    new Array('hellnaw.gif', 'AWW HELL NAW!', 'Replaced the locks for a short time'),
    new Array('dong.gif', 'Penis', 'Replaced the locks for a short time'),
    new Array('gizz.gif', 'Splooging Penis', 'Replaced the locks for a short time'),
    new Array('500000.gif', '500000', 'In honor of the 500,000th topic on LL'),
    new Array('emot-v.gif', 'Emoticon V', 'Uh... Pac-Man?'),
    new Array('ad1.gif', 'Serious Discussion', 'I still browse the main board though.'),
    new Array('ad2.gif', 'I\'m watching you', 'Well that can\'t be good...'),
    new Array('ad3.gif', 'I\'m still watching you', 'Well that still can\'t be good...'),
    new Array('flatbeat.wmv', 'Flat Beat', 'WOW')
  );
  var tables = doc.getElementsByTagName('table');
  var trs    = doc.getElementsByTagName('tr');
  if (stylesheet.href.match(/\/eyes\.css$/)) {
    globalStyles.appendChild(doc.createTextNode('table.topiclist {background: ' + pageBg + ' !important; border-collapse: collapse !important;} table.topiclist td, table.topiclist th {border: ' + pageBg + ' 2px solid;} table.topiclist th {border-top-width: 0px !important;} .topiclistr {border-right-width: 0px !important;} .topiclistl {border-left-width: 0px !important;}'));
    if (lastStyle == 'custom') {
      stylesheet.href = 'css.php';
    } else {
      stylesheet.href = 'blue.css';
    }
  } else if(stylesheet.href.match(/\/[n]?css\.php$/)) {
    foxlinksLastStyle = 'custom';
  } else {
    foxlinksLastStyle = 'blue';
  }
  if (disableMainStyle) {
    head.removeChild(stylesheet);
  }
  if (doc.location.pathname == '/boardlist.php') {
    var boardlisting = tables[tables.length - 1].tBodies[0];
    var secrethead = doc.createElement('tr');
    var secretheadcell = doc.createElement('th');
    secretheadcell.className = 'boardlistm';
    secretheadcell.colSpan = 4;
    secretheadcell.appendChild(doc.createTextNode(completeList[3][0]));
    secrethead.appendChild(secretheadcell);
    boardlisting.appendChild(secrethead);
    for (i = 1; i < completeList[3].length; i++) {
      var tr = doc.createElement('tr');
      var td1 = doc.createElement('td');
      td1.className = 'topiclistl';
      var bold = doc.createElement('b');
      var url = doc.createElement('a');
      url.href = 'showtopics.php?board=' + completeList[3][i][0];
      url.appendChild(doc.createTextNode(completeList[3][i][1]));
      var td2 = doc.createElement('td');
      td2.className = 'topiclist';
      td2.appendChild(doc.createTextNode('???'));
      var td3 = doc.createElement('td');
      td3.className = 'topiclist';
      td3.appendChild(doc.createTextNode('???'));
      var td4 = doc.createElement('td');
      td4.className = 'topiclistr';
      td4.appendChild(doc.createTextNode('??/??/???? ??:??'));
      bold.appendChild(url);
      td1.appendChild(bold);
      td1.appendChild(doc.createElement('br'));
      if (completeList[3][i][0] == 54) {
        td1.appendChild(doc.createTextNode("\u2026" + '../|,-' + "\u2018" + '`' + "\u00AF\u00AF" + '`\\(o)_\\,----,,,_' + "\u2026\u2026\u2026\u2026\u2026" + '.'));
        td1.appendChild(doc.createElement('br'));
        td1.appendChild(doc.createTextNode("\u2026" + '( `\\(o),,_/` ' + "\u00AF" + ' : o : : :o `-, ' + "\u2026\u2026\u2026\u2026"));
      } else {
        td1.appendChild(doc.createTextNode(completeList[3][i][2]));
      }
      tr.appendChild(td1);
      tr.appendChild(td2);
      tr.appendChild(td3);
      tr.appendChild(td4);
      boardlisting.appendChild(tr);
    }
  }
  if (doc.location.pathname == '/showtopics.php' ||
      doc.location.pathname == '/showfavorites.php' ||
      doc.location.pathname == '/search.php' ||
      doc.location.pathname == '/history.php') {
    if (pageJump) {
      for (i = 0; i < tables.length; i++) {
        if (tables[i].className != 'classic' && tables[i].tBodies[0].getElementsByTagName('th')[0].colSpan != 4) {
          var pageTh = doc.createElement('th');
          pageTh.className = 'topiclist'; // The tagged topics page still uses it
          pageTh.appendChild(doc.createTextNode('Page'));
          tables[i].getElementsByTagName('tr')[0].insertBefore(pageTh, tables[i].tBodies[0].getElementsByTagName('th')[2]);
        }
      }
    }
    for (i = 0; i < trs.length; i++) {
      if (/<a.+?showmessages(.+?)['" ]/i.test(trs[i].innerHTML) && !trs[i].getElementsByTagName('th')[0]) {
        k = (doc.location.pathname == '/history.php') ? 1 : 0;
        var match = trs[i].getElementsByTagName('td')[k].innerHTML.match(/topic=([0-9]+)/i);
        if (match && trs[i].childNodes.length >= 4) {
          var badChars = trs[i].getElementsByTagName('td')[k].textContent.match(/(?:@|%|[A-Z]|\u2030|\u0152|\u00C6)/g);
          if (badChars && badChars.length && badChars.length >= 10 && noTopicStretch) {
            var topicdiv = doc.createElement('div');
            topicdiv.className = 'topicdiv';
            topicdiv.appendChild(trs[i].getElementsByTagName('a')[0].cloneNode(1));
            if (trs[i].getElementsByTagName('td')[k]) {
              trs[i].getElementsByTagName('td')[k].replaceChild(topicdiv, trs[i].getElementsByTagName('a')[0]);
            }
          }
          if (pageJump) {
            var match2 = trs[i].getElementsByTagName('td')[k].innerHTML.match(/board=([\-]?[0-9]+)/i);
            var posts = Math.ceil(trs[i].getElementsByTagName('td')[2].textContent / 50);
            var jump = doc.createElement('td');
            jump.className = 'jump topiclist';
            var main = doc.createElement('a');
            main.className = 'foxlinksLink ' + match[1] + ' '+ match2[1] + ' ' + posts;
            main.title = 'Page Jump';
            main.addEventListener('click', foxlinksPageJump, false);
            main.appendChild(doc.createTextNode('Page:'));
            jump.appendChild(main);
            trs[i].insertBefore(jump, trs[i].getElementsByTagName('td')[2]);
          }
          var cells = trs[i].getElementsByTagName('td');
          if (highlightTpcs && highlightNames.length > 0 && doc.location.pathname != '/history.php') {
            var posterName = cells[1].firstChild.textContent;
            for (j = 0; j < highlightNames.length; j++) {
              if (posterName == highlightNames[j]) {
                for (k = 0; k < cells.length; k++) {
                  cells[k].style.setProperty('background-color', highlightColor, 'important');
                }
                break;
              }
            }
          }
          if (blacklistTpcs && blacklistNames.length > 0 && doc.location.pathname != '/history.php') {
            var posterName = cells[1].firstChild.textContent;
            for (j = 0; j < blacklistNames.length; j++) {
              if (posterName == blacklistNames[j]) {
                for (k = 0; k < cells.length; k++) {
                  cells[k].style.setProperty('background-color', blacklistColor, 'important');
                }
                break;
              }
            }
          }
        }
      }
    }
  }
  if (doc.body.childNodes.length <= 4) { // in classic mode, all the content of the page is inside one table
    if (linkMeForm) {
      var linkDiv = doc.createElement('div');
      linkDiv.className = 'linkme';
      linkDiv.id = 'classic';
      var linkForm = doc.createElement('form');
      linkForm.action = 'linkme.php';
      linkForm.method = 'get';
      var linkText = doc.createElement('input');
      linkText.type = 'text';
      linkText.name = 'l';
      linkText.size = 10;
      linkForm.appendChild(linkText);
      var linkSubmit = doc.createElement('input');
      linkSubmit.type = 'submit';
      linkSubmit.name = 'submit';
      linkSubmit.value = 'Link Me!';
      linkForm.appendChild(linkSubmit);
      linkDiv.appendChild(linkForm);
      doc.body.appendChild(linkDiv);
    }
    if (specialLinks) {
      globalStyles.appendChild(doc.createTextNode('li:hover > div, div.sdiv:hover > div { top: 0px !important; left: 0px !important; } ul.blist { margin: 0px; background-color: ' + bgColor2 + '; position: absolute; }'));
      var ths = doc.getElementsByTagName('th');
      var theTh;
      if (ths[1].className == 'classic3') {
        theTh = ths[1];
      } else {
        theTh = ths[2];
      }
      theTh.appendChild(doc.createElement('br'));
      theTh.appendChild(doc.createElement('br'));
      var classicDiv = doc.createElement('div');
      classicDiv.id = 'special';
      for (i = 0; i < specialLinks.length; i++) {
        var sDiv = doc.createElement('div');
        sDiv.className = 'sdiv';
        var sLink = doc.createElement('a');
        sLink.className = 'menubar foxlinksLink';
        sLink.appendChild(doc.createTextNode(specialLinks[i][1]));
        if (specialLinks[i][0] == '') {
          sLink.href = 'javascript:;';
          sLink.addEventListener('click', foxlinksBoardLists, false);
        } else {
          sLink.href = specialLinks[i][0];
        }
        var sLinkDesc = doc.createElement('div');
        sLinkDesc.appendChild(doc.createTextNode(specialLinks[i][2]));
        sLinkDesc.className = 'info';
        sDiv.appendChild(sLink);
        sDiv.appendChild(sLinkDesc);
        if (specialLinks[i][0] == 'boardlist.php') {
          var boardsMenu = doc.createElement('a');
          boardsMenu.className = 'menubar boardlist more foxlinksLink';
          boardsMenu.href = 'javascript:;';
          boardsMenu.appendChild(doc.createTextNode('(more)>'));
          boardsMenu.addEventListener('click', foxlinksBoardLists, false);
          sDiv.appendChild(boardsMenu);
          var boardsLists = doc.createElement('ul');
          boardsLists.className = 'blist';
          boardsLists.style.setProperty('display', 'none', 'important');
          for (j = 0; j < completeList.length; j++) {
            var mainCatLi = doc.createElement('li');
            var boardsMenu2 = doc.createElement('a');
            boardsMenu2.className = 'menubar foxlinksLink';
            boardsMenu2.href = 'javascript:;';
            boardsMenu2.appendChild(doc.createTextNode(completeList[j][0] + '>'));
            boardsMenu2.addEventListener('click', foxlinksBoardLists, false);
            mainCatLi.appendChild(boardsMenu2);
            var theBoards = doc.createElement('ul');
            theBoards.style.setProperty('display', 'none', 'important');
            for (k = 1; k < completeList[j].length; k++) {
              var boardLink = doc.createElement('a');
              boardLink.href = 'showtopics.php?board=' + completeList[j][k][0];
              boardLink.className = 'menubar';
              boardLink.appendChild(doc.createTextNode(completeList[j][k][1]));
              var boardLinkDesc = doc.createElement('div');
              if (completeList[j][k][0] == 54) {
                boardLinkDesc.appendChild(doc.createTextNode("\u2026" + '../|,-' + "\u2018" + '`' + "\u00AF\u00AF" + '`\\(o)_\\,----,,,_' + "\u2026\u2026\u2026\u2026\u2026" + '.'));
                boardLinkDesc.appendChild(doc.createElement('br'));
                boardLinkDesc.appendChild(doc.createTextNode("\u2026" + '( `\\(o),,_/` ' + "\u00AF" + ' : o : : :o `-, ' + "\u2026\u2026\u2026\u2026"));
              } else if (completeList[j][k][0] == 57) {
                var redSpan = doc.createElement('span');
                redSpan.style.setProperty('color', '#ff0000', null);
                redSpan.appendChild(doc.createTextNode(completeList[j][k][2]))
                boardLinkDesc.appendChild(redSpan);
              } else {
                boardLinkDesc.appendChild(doc.createTextNode(completeList[j][k][2]));
              }
              var holdingL = doc.createElement('li');
              holdingL.appendChild(boardLink);
              if (completeList[j][k].length == 4) {
                var boardsMenu3 = doc.createElement('a');
                boardsMenu3.className = 'menubar boardlist more foxlinksLink';
                boardsMenu3.href = 'javascript:;';
                boardsMenu3.appendChild(doc.createTextNode('(more)>'));
                boardsMenu3.addEventListener('click', foxlinksBoardLists, false);
                holdingL.appendChild(boardsMenu3);
                var subBoards = doc.createElement('ul');
                subBoards.style.setProperty('display', 'none', 'important');
                for (l = 0; l < completeList[j][k][3].length; l++) {
                  var subBoard = doc.createElement('a');
                  subBoard.href = 'showtopics.php?board=' + completeList[j][k][3][l][0];
                  subBoard.className = 'menubar';
                  subBoard.appendChild(doc.createTextNode(completeList[j][k][3][l][1]));
                  var subBoardDesc = doc.createElement('div');
                  if (completeList[j][k][3][l][0] == 55) {
                    var redSpan2 = doc.createElement('span');
                    redSpan2.style.setProperty('color', '#ff0000', null);
                    redSpan2.appendChild(doc.createTextNode(completeList[j][k][3][l][2]))
                    subBoardDesc.appendChild(redSpan2);
                  } else {
                    subBoardDesc.appendChild(doc.createTextNode(completeList[j][k][3][l][2]));
                  }
                  var holdingLi = doc.createElement('li');
                  holdingLi.appendChild(subBoard);
                  holdingLi.appendChild(subBoardDesc);
                  subBoards.appendChild(holdingLi);
                }
                holdingL.appendChild(boardLinkDesc);
                holdingL.appendChild(subBoards);
              } else {
                  holdingL.appendChild(boardLinkDesc);
              }
              theBoards.appendChild(holdingL);
            }
            mainCatLi.appendChild(theBoards);
            boardsLists.appendChild(mainCatLi);
          }
          sDiv.appendChild(boardsLists);
        } else if (specialLinks[i][0] == 'profile.php?user=' + userid[1]) {
          var uLinks = doc.createElement('a');
          uLinks.className = 'menubar boardlist more foxlinksLink';
          uLinks.href = 'javascript:;';
          uLinks.appendChild(doc.createTextNode('(more)>'));
          uLinks.addEventListener('click', foxlinksBoardLists, false);
          sDiv.appendChild(uLinks);
          var linkList = doc.createElement('ul');
          linkList.className = 'blist';
          linkList.style.setProperty('display', 'none', 'important');
          for (j = 0; j < userLinks.length; j++) {
            var uLink = doc.createElement('a');
            uLink.href = userLinks[j][0];
            uLink.className = 'menubar';
            uLink.appendChild(doc.createTextNode(userLinks[j][1]));
            var uLinkDesc = doc.createElement('div');
            uLinkDesc.appendChild(doc.createTextNode(userLinks[j][2]));
            var holdingL = doc.createElement('li');
            holdingL.appendChild(uLink);
            holdingL.appendChild(uLinkDesc);
            linkList.appendChild(holdingL);
          }
          sDiv.appendChild(linkList);
        } else if (specialLinks[i][0] == '') {
          var linkList = doc.createElement('ul');
          linkList.className = 'blist';
          linkList.style.setProperty('display', 'none', 'important');
          for (j = 0; j < otherFiles.length; j++) {
            var uLink = doc.createElement('a');
            uLink.href = otherFiles[j][0];
            uLink.className = 'menubar';
            uLink.appendChild(doc.createTextNode(otherFiles[j][1]));
            var uLinkDesc = doc.createElement('div');
            uLinkDesc.appendChild(doc.createTextNode(otherFiles[j][2]));
            var holdingL = doc.createElement('li');
            holdingL.appendChild(uLink);
            holdingL.appendChild(uLinkDesc);
            linkList.appendChild(holdingL);
          }
          sDiv.appendChild(linkList);
        }
        theTh.appendChild(sDiv);
      }
    }
  } else {
    if (linkMeForm) {
      var linkDiv = doc.createElement('div');
      linkDiv.className = 'linkme';
      linkDiv.id = 'topbar';
      var linkForm = doc.createElement('form');
      linkForm.action = 'linkme.php';
      linkForm.method = 'get';
      var linkText = doc.createElement('input');
      linkText.type = 'text';
      linkText.name = 'l';
      linkText.size = 10;
      linkForm.appendChild(linkText);
      var linkSubmit = doc.createElement('input');
      linkSubmit.type = 'submit';
      linkSubmit.name = 'submit';
      linkSubmit.value = 'Link Me!';
      linkForm.appendChild(linkSubmit);
      linkDiv.appendChild(linkForm);
      doc.body.appendChild(linkDiv);
    }
    if (specialLinks) {
      var special = doc.createElement('div');
      special.className = 'menubar special';
      special.id = 'special';
      var list1 = doc.createElement('ul');
      list1.className = 'menu';
      var item1 = doc.createElement('li');
      var boardsMenu0 = doc.createElement('a');
      boardsMenu0.className = 'menubar boardlist foxlinksLink';
      boardsMenu0.appendChild(doc.createTextNode('Special Links>'));
      boardsMenu0.addEventListener('click', foxlinksBoardLists, false);
      item1.appendChild(boardsMenu0);
      var list2 = doc.createElement('ul');
      list2.style.setProperty('display', 'none', 'important');
      list2.style.setProperty('background-color', bgColor2, null);
      list2.className = 'blist';
      for (i = 0; i < specialLinks.length; i++) {
        var sLink = doc.createElement('a');
        sLink.className = 'menubar foxlinksLink';
        if (specialLinks[i][0] == '') {
          sLink.addEventListener('click', foxlinksBoardLists, false);
        } else {
          sLink.href = specialLinks[i][0];
        }
        var sLinkDesc = doc.createElement('div');
        sLinkDesc.appendChild(doc.createTextNode(specialLinks[i][2]));
        sLink.appendChild(doc.createTextNode(specialLinks[i][1]));
        var hold = doc.createElement('li');
        hold.appendChild(sLink);
        hold.appendChild(sLinkDesc);
        if (specialLinks[i][0] == 'boardlist.php') {
          var boardsMenu = doc.createElement('a');
          boardsMenu.className = 'menubar boardlist more foxlinksLink';
          boardsMenu.appendChild(doc.createTextNode('(more)>'));
          boardsMenu.addEventListener('click', foxlinksBoardLists, false);
          hold.appendChild(boardsMenu);
          var boardsLists = doc.createElement('ul');
          boardsLists.style.setProperty('display', 'none', 'important');
          boardsLists.style.setProperty('background-color', bgColor2, null);
          for (j = 0; j < completeList.length; j++) {
            var mainCatLi = doc.createElement('li');
            var boardsMenu2 = doc.createElement('a');
            boardsMenu2.className = 'menubar foxlinksLink';
            boardsMenu2.appendChild(doc.createTextNode(completeList[j][0] + '>'));
            boardsMenu2.addEventListener('click', foxlinksBoardLists, false);
            mainCatLi.appendChild(boardsMenu2);
            var theBoards = doc.createElement('ul');
            theBoards.style.setProperty('display', 'none', 'important');
            theBoards.style.setProperty('background-color', bgColor2, null);
            for (k = 1; k < completeList[j].length; k++) {
              var boardLink = doc.createElement('a');
              boardLink.href = 'showtopics.php?board=' + completeList[j][k][0];
              boardLink.className = 'menubar';
              boardLink.appendChild(doc.createTextNode(completeList[j][k][1]));
              var boardLinkDesc = doc.createElement('div');
              if (completeList[j][k][0] == 54) {
                boardLinkDesc.appendChild(doc.createTextNode("\u2026" + '../|,-' + "\u2018" + '`' + "\u00AF\u00AF" + '`\\(o)_\\,----,,,_' + "\u2026\u2026\u2026\u2026\u2026" + '.'));
                boardLinkDesc.appendChild(doc.createElement('br'));
                boardLinkDesc.appendChild(doc.createTextNode("\u2026" + '( `\\(o),,_/` ' + "\u00AF" + ' : o : : :o `-, ' + "\u2026\u2026\u2026\u2026"));
              } else if (completeList[j][k][0] == 57) {
                var redSpan = doc.createElement('span');
                redSpan.style.setProperty('color', '#ff0000', null);
                redSpan.appendChild(doc.createTextNode(completeList[j][k][2]))
                boardLinkDesc.appendChild(redSpan);
              } else {
                boardLinkDesc.appendChild(doc.createTextNode(completeList[j][k][2]));
              }
              var holdingL = doc.createElement('li');
              holdingL.appendChild(boardLink);
              if (completeList[j][k].length == 4) {
                var boardsMenu3 = doc.createElement('a');
                boardsMenu3.className = 'menubar boardlist more foxlinksLink';
                boardsMenu3.appendChild(doc.createTextNode('(more)>'));
                boardsMenu3.addEventListener('click', foxlinksBoardLists, false);
                holdingL.appendChild(boardsMenu3);
                var subBoards = doc.createElement('ul');
                subBoards.style.setProperty('display', 'none', 'important');
                subBoards.style.setProperty('background-color', bgColor2, null);
                for (l = 0; l < completeList[j][k][3].length; l++) {
                  var subBoard = doc.createElement('a');
                  subBoard.href = 'showtopics.php?board=' + completeList[j][k][3][l][0];
                  subBoard.className = 'menubar';
                  subBoard.appendChild(doc.createTextNode(completeList[j][k][3][l][1]));
                  var subBoardDesc = doc.createElement('div');
                  if (completeList[j][k][3][l][0] == 55) {
                    var redSpan2 = doc.createElement('span');
                    redSpan2.style.setProperty('color', '#ff0000', null);
                    redSpan2.appendChild(doc.createTextNode(completeList[j][k][3][l][2]))
                    subBoardDesc.appendChild(redSpan2);
                  } else {
                    subBoardDesc.appendChild(doc.createTextNode(completeList[j][k][3][l][2]));
                  }
                  var holdingLi = doc.createElement('li');
                  holdingLi.appendChild(subBoard);
                  holdingLi.appendChild(subBoardDesc);
                  subBoards.appendChild(holdingLi);
                }
                holdingL.appendChild(boardLinkDesc);
                holdingL.appendChild(subBoards);
              } else {
                holdingL.appendChild(boardLinkDesc);
              }
              theBoards.appendChild(holdingL);
            }
            mainCatLi.appendChild(theBoards);
            boardsLists.appendChild(mainCatLi);
          }
          hold.appendChild(boardsLists);
        } else if (specialLinks[i][0] == 'profile.php?user=' + userid[1]) {
          var uLinks = doc.createElement('a');
          uLinks.className = 'menubar boardlist more foxlinksLink';
          uLinks.appendChild(doc.createTextNode('(more)>'));
          uLinks.addEventListener('click', foxlinksBoardLists, false);
          hold.appendChild(uLinks);
          var linkList = doc.createElement('ul');
          linkList.className = 'blist';
          linkList.style.setProperty('display', 'none', 'important');
          linkList.style.setProperty('background-color', bgColor2, null);
          for (j = 0; j < userLinks.length; j++) {
            var uLink = doc.createElement('a');
            uLink.href = userLinks[j][0];
            uLink.className = 'menubar';
            uLink.appendChild(doc.createTextNode(userLinks[j][1]));
            var uLinkDesc = doc.createElement('div');
            uLinkDesc.appendChild(doc.createTextNode(userLinks[j][2]));
            var holdingL = doc.createElement('li');
            holdingL.appendChild(uLink);
            holdingL.appendChild(uLinkDesc);
            linkList.appendChild(holdingL);
          }
          hold.appendChild(linkList);
        } else if (specialLinks[i][0] == '') {
          var linkList = doc.createElement('ul');
          linkList.className = 'blist';
          linkList.style.setProperty('display', 'none', 'important');
          linkList.style.setProperty('background-color', bgColor2, null);
          for (j = 0; j < otherFiles.length; j++) {
            var uLink = doc.createElement('a');
            uLink.href = otherFiles[j][0];
            uLink.className = 'menubar';
            uLink.appendChild(doc.createTextNode(otherFiles[j][1]));
            var uLinkDesc = doc.createElement('div');
            uLinkDesc.appendChild(doc.createTextNode(otherFiles[j][2]));
            var holdingL = doc.createElement('li');
            holdingL.appendChild(uLink);
            holdingL.appendChild(uLinkDesc);
            linkList.appendChild(holdingL);
          }
          hold.appendChild(linkList);
        }
        list2.appendChild(hold);
      }
      item1.appendChild(list2);
      list1.appendChild(item1);
      special.appendChild(list1);
      doc.body.insertBefore(special, doc.body.firstChild);
    }
  }
  var pres = doc.getElementsByTagName('pre');
  for (i = 0; i < pres.length; i++) {
    var lineBreaks = pres.getElementsByTagName('br');
    while (lineBreaks.length) {
      lineBreaks[0].parentNode.removeChild(lineBreaks[0]);
    }
  }
  var links = doc.getElementsByTagName('a');
  if (advancedSearch) {
    for (i = 0; i < links.length; i++) {
      if (!links[i].className.match('foxlinksLink') && links[i].pathname == '/links.php' && links[i].search == 'mode=search') {
        alert(links[i].search);
        links[i].href = '/links.php?mode=as';
        break;
      }
    }
  }
  /*if (Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch).getIntPref('network.http.sendRefererHeader') == 0) {
    for (i = 0; i < links.length; i++) {
      if (!links[i].className.match('foxlinksLink') && links[i].host == doc.location.host && links[i].pathname == '/l.php') {
        links[i].href = links[i].search.substring(1);
      }
    }
  }*/
  globalStyles.firstChild.normalize();
  head.appendChild(globalStyles);
}

function foxlinksPageJump()
{
  var match = this.className.match(/^foxlinksLink ([0-9]+) ([\-]?[0-9]+) ([0-9]+)$/);
  var board = match[2] * 1;
  var topic = match[1] * 1;
  var pages = match[3] * 1;
  if (pages == 1) {
    return alert('Okay, the topic only has one page. Think about that.');
  }
  var toPage = prompt('Please choose which page you want to go to. There are ' + pages + ' pages total', '1');
  if (toPage == '') {
    return false;
  }
  if (toPage == '0.999~') {
    toPage = '1'; // Calculus
  }
  if (toPage.match(/[^0-9\-.]/)) {
    return alert(toPage + '? ' + toPage + ' ain\'t no number I\'ve heard of.');
  }
  toPage = toPage * 1;
  if (toPage % 1) {
    return alert('Fractions of a page? Brilliant work, genius.');
  }
  if (toPage == 0) {
    return alert('Can\'t let you do that Starfox!');
  }
  if (toPage < 1) {
    return alert('Negative pages? Nigga please!');
  }
  if (toPage > pages) {
    return alert('The topic hasn\'t gotten to that page yet.');
  }
  this.ownerDocument.location = 'http://' + this.ownerDocument.location.host + '/showmessages.php?board=' + board + '&topic=' + topic + '&page=' + toPage;
}

function foxlinksBoardLists()
{
  if (this.parentNode.lastChild.style.getPropertyValue('display') == '') {
    this.parentNode.lastChild.style.setProperty('display', 'none', 'important');
    var otherLists = this.parentNode.getElementsByTagName('ul');
    for (var i = 1; i < otherLists.length; i++) {
      otherLists[i].style.setProperty('display', 'none', 'important');
    }
  } else {
    this.parentNode.lastChild.style.removeProperty('display');
  }
  this.blur();
  return false;
}

function foxlinksQuickPost()
{
  this.disabled = true;
  this.value = 'Posting...';
  this.removeEventListener('click', foxlinksQuickPost, false);
  this.blur();
  var bttn = this;
  window.status = 'Performing QuickPost';
  var me        = document.cookie.match(/userid=([0-9]+)/i);
  me = me[1];
  var boardId   = document.body.innerHTML.match(/<a.+?showtopics\.php\?board=([\-]?[0-9]+).+?>Topic List<\/a>/i);
  var topicId   = document.location.search.match(/topic=([0-9]+)/);
  var linkId    = document.body.innerHTML.match(/<b>Code\:<\/b> LL([a-f0-9]+)/);
  if (linkId) {
    linkId    = parseInt(linkId[1], 16);
  }
  var request   = new XMLHttpRequest();
  var domain    = document.location.host;
  var orig      = document.location.href;
  request.open('POST', 'http://' + domain + '/postmsg.php');
  request.onreadystatechange = function(e) 
  {
    if (request.readyState == 4) {
      var messageInput = request.responseText.match(/<input type="hidden" name="message" value="(.+?)">/);
      var hash         = request.responseText.match(/<input type="hidden" name="hash" value="(.+?)">/);
      var proof        = request.responseText.match(/<input type="hidden" name="proof" value="(.+?)">/);
      if (!messageInput || !hash || !proof) {
        alert('Cannot perform QuickPost due to an error. The problem could be the size of the post.');
        bttn.disabled = false;
        bttn.value = 'QuickPost';
        bttn.addEventListener('click', foxlinksQuickPost, false);
        return window.status = '';
      }
      request2 = new XMLHttpRequest();
      request2.open('POST', 'http://' + domain + '/postmsg.php');
      request2.onreadystatechange = function(e)
      {
        if (request2.readyState == 4) {
          var postlimit = request2.responseText.match(/<em>Please wait <script.+?>.+?<\/script><span id="secs">([0-9]+)<\/span> seconds before posting.<\/em>/);
          if (!postlimit) {
            if (document.location.href == orig) {
              window.status = '';
              return document.location.reload();
            } else {
              window.status = '';
              return alert('LUElinks message posted!');
            }
          } else if(postlimit[1]) {
            alert('You\'re posting too fast! Please wait ' + postlimit[1] + ' second' + (postlimit[1] != '1' ? 's' : '') + ' before trying to post again.');
            bttn.disabled = false;
            bttn.value = 'QuickPost';
            bttn.addEventListener('click', foxlinksQuickPost, false);
            return window.status = '';
          } else {
            alert('FOXlinks encountered an unknown error trying to post. Please inform the user "Toad King" about this.');
            bttn.disabled = false;
            bttn.value = 'QuickPost';
            bttn.addEventListener('click', foxlinksQuickPost, false);
            return window.status = '';
          }
        }
      };
      request2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      if (linkId) {
        return request2.send('link=' + linkId + '&message=' + escape(messageInput[1]) + '&hash=' + hash[1] + '&proof=' + proof[1] + '&go=Post+message');
      } else {
        return request2.send('topic=' + topicId[1] + '&board=' + boardId[1] + '&message=' + escape(messageInput[1]) + '&hash=' + hash[1] + '&proof=' + proof[1] + '&go=Post+message');
      }
    }
  };
  request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  var message = document.getElementsByName('message')[0].value;
  if (linkId) {
    return request.send('message=' + foxlinksUriEncode(message) + '&link=' + linkId + '&preview=Preview+Message');
  } else {
    return request.send('message=' + foxlinksUriEncode(message) + '&me=' + me + '&topic=' + topicId[1] + '&board=' + boardId[1] + '&preview=Preview+Message');
  }
}

function foxlinksUriEncode(uri)
{
  var fixes = new Array (
    new Array('20AC', '80'),
    new Array('201A', '82'),
    new Array('0192', '83'),
    new Array('201E', '84'),
    new Array('2026', '85'),
    new Array('2020', '86'),
    new Array('2021', '87'),
    new Array('02C6', '88'),
    new Array('2030', '89'),
    new Array('0160', '8A'),
    new Array('2039', '8B'),
    new Array('0152', '8C'),
    new Array('017D', '8E'),
    new Array('2018', '91'),
    new Array('2019', '92'),
    new Array('201C', '93'),
    new Array('201D', '94'),
    new Array('2022', '95'),
    new Array('2013', '96'),
    new Array('2014', '97'),
    new Array('02DC', '98'),
    new Array('2122', '99'),
    new Array('0161', '9A'),
    new Array('203A', '9B'),
    new Array('0153', '9C'),
    new Array('017E', '9E'),
    new Array('0178', '9F')
  );
  var goodUri = escape(uri).replace(/\+/g, '%2B').replace(/\%20/g, '+');
  for (var i = 0; i < fixes.length; i++) {
    var match = new RegExp('\\%u' + fixes[i][0], 'g');
    goodUri = goodUri.replace(match, '%' + fixes[i][1]);
  }
  return goodUri;
}

function foxlinksButtons()
{
  var tag    = this.id;
  var open   = new RegExp('\\*', 'm');
  var ta     = this.nextSibling;
  while (ta.nodeName.toLowerCase() != 'textarea') {
    ta = ta.nextSibling;
  }
  var st     = ta.scrollTop;
  var before = ta.value.substring(0, ta.selectionStart);
  var after  = ta.value.substring(ta.selectionEnd, ta.value.length);
  var select = ta.value.substring(ta.selectionStart, ta.selectionEnd);
  if (ta.selectionStart == ta.selectionEnd) {
    if (open.test(this.value)) {
      this.value = this.name;
      var focusPoint = ta.selectionStart + tag.length + 3;
      ta.value = before + '</' + tag + '>' + after;
    } else {
      this.value = this.name + '*';
      var focusPoint = ta.selectionStart + tag.length + 2;
      ta.value = before + '<' + tag + '>' + after;
    }
    ta.selectionStart = focusPoint;
  } else {
    var focusPoint = ta.selectionStart + (tag.length * 2) + select.length + 5;
    ta.value = before + '<' + tag + '>' + select + '</' + tag + '>' + after;
    ta.selectionStart = before.length;
  }
  ta.selectionEnd = focusPoint;
  ta.scrollTop = st;
  ta.focus();
}

function foxlinksBlacklist()
{
  foxlinksTimeoutVar = this.parentNode.nextSibling.nextSibling;
  if (this.parentNode.nextSibling.nextSibling.style.getPropertyValue('display') == 'none') {
    this.parentNode.nextSibling.nextSibling.style.removeProperty('display');
    this.replaceChild(this.ownerDocument.createTextNode('Hide'), this.firstChild);
  } else {
    this.replaceChild(this.ownerDocument.createTextNode('Show'), this.firstChild);
    this.parentNode.nextSibling.nextSibling.style.setProperty('display', 'none', 'important');
  }
  return false;
}