// ==UserScript==
// @name           KVR Forum Resizer
// @namespace      http://tuzemec.com
// @description    Resizes the forum layout
// @include        http://www.kvraudio.com/forum/*
// ==/UserScript==

// KVRForumResizer by tuzemec@gmail.com

// resizing the layout
GM_addStyle ("#kvrblock, #column1 {width: 99%}");
GM_addStyle ("#shlinks {width: 320px; float: right;}");
GM_addStyle ("#main {width: 100% !important;}");
GM_addStyle (".kvrgencontenttrail, .kvrgencontenttrailalt, .kvrgencontentalt {background-image: none !important; background-color: #304060 !important;}");


GM_addStyle ("#tzmMarks {width: 190px; position: fixed; top: 1px; right: 1px; background: #506F89; padding: 1px 1px 0; font-size: 10px;}");
GM_addStyle ("#tzmMarks ul {text-align: left; margin:0; list-style-position: inside; list-style-type: decimal;}");
GM_addStyle ("#tzmMarks ul li {background: #304060; margin-bottom: 1px; padding: 2px 2px 2px 6px; color: #ccc;}");
GM_addStyle ("#tzmMarks a {color: #fff;}");
GM_addStyle ("#tzmHandler {cursor: pointer; padding: 2px 0; color: #fff;}" );

GM_addStyle ("table.forumline tr.hover td {background: #496880;}")


var jQ = unsafeWindow.jQuery;

try {
	jQ("#shlinks").insertBefore("#main"); // moving the user panel
	jQ("#sidecol, #navcol, #kvrlidb, #kvrlmm, #subcol").hide(); // hiding some elements
	jQ("#kvrqrbox").show(); // show the quick reply by default
	
	jQ("<div id='tzmMarks'><div id='tzmHandler' title='click to expand/contract'>KVRmarks</div></div>").appendTo("body");
	
	jQ("#tzmHandler").bind("click", function(){
		jQ("#tzmMarks ul").slideToggle("fast");
	});
	
	jQ.get("/inc/a.php?w=kvrmarks", function(data) {
		var $r = jQ("<div></div>");
		$r.html( data );
		jQ("#tzmMarks").prepend( $r.find("ul").hide() );
	});
	
	jQ("table.forumline tr:not(':first')").hover( function() { jQ(this).addClass("hover") }, function(){ jQ(this).removeClass("hover") } );
	
} catch (e) {

} 
		
// for keyboard shortcuts
	window.addEventListener('keydown', keyHandler, false);
	
	const ACTIONS = {
		49 : "0",
		50 : "1",
		51 : "2",
		52 : "3",
		53 : "4",
		54 : "5",
		55 : "6",
		56 : "7",
		57 : "8",
		58 : "9"
	}
	
	
	function keyHandler (event) {
		// keyHandling code borrowed from gmail macros script by persistent.info
		
		// just the shift + letter combinations
		if (!event.shiftKey) return;
		
	  // Apparently we still see Firefox shortcuts like control-T for a new tab - 
	  // checking for modifiers lets us ignore those
	  if (event.altKey || event.ctrlKey || event.metaKey) return;
	  
	  // We also don't want to interfere with regular user typing
	  if (event.target && event.target.nodeName) {
	    var targetNodeName = event.target.nodeName.toLowerCase();
	    if (targetNodeName == "textarea" ||
	        (targetNodeName == "input" && event.target.type &&
	         (event.target.type.toLowerCase() == "text" ||
	          event.target.type.toLowerCase() == "file"))) {
	      return;
	    }
	  }
	  
	  var k = event.keyCode;
	  
	  if (k in ACTIONS) {
	  	if (jQ("#tzmMarks ul li:eq('" + ACTIONS[k] + "') a")[0])
				document.location = jQ("#tzmMarks ul li:eq('" + ACTIONS[k] + "') a").attr("href");
	  }
	  
	  return;
	}

