// ==UserScript==
// @name	qtalk_n
// @namespace	http://www.qtalk.de/
// @include	http://www.qtalk.de/*
// @version	1.2
// ==/UserScript==

/**
 * Settings / Einstellungen
 */
var useFullWidth = 0; // streckt das Forum über die gesamte Bildschirmbreite
var highlightUnreadBoards = 1; // hebt Foren mit ungelesenen Beiträgen deutlicher hervor
var highlightUnreadTopics = 1; // hebt Themen mit ungelesenen und eigenen Beiträgen deutlicher hervor
var highlightOwnTopics = 1; // hebt Themen mit eigenen Beiträgen deutlicher hervor
var betterPostList = 1; // vereinheitlicht die Darstellung von einzelnen Beiträgen
var customPostBackgrounds = 1; // aktiviert die Verwendung von eigenen Hintergrundfarben für Beiträge
var postBackground1 = '#F6F6F6'; // Hintergrundefarbe für Beiträge #1
var postBackground2 = '#E8E8E8'; // Hintergrundfarbe für Beiträge #2
var postUserInfoText = '#000000'; // Textfarbe für Benutzerinfos unter dem Avatar

/**
 * Adds new css classes to page elements.
 */
	// board titles
var board, icon;
var boards = document.getElementsByClassName('forumlink');
for (i in boards) {
	board = boards[i];
	if (boards[i].parentNode != undefined) {
		icon = boards[i].parentNode.parentNode.getElementsByTagName('td')[0].getElementsByTagName('img')[0];
		// check if board has unread posts
		if (icon.src.indexOf('_unread') != -1) { board.className += ' boardNew'; }
	}
}
	// topic titles
var topic;
var topics = document.getElementsByClassName('topictitle');
for (i in topics) {
	topic = topics[i];
	if (topics[i] != undefined && topics[i].parentNode != undefined && topics[i].parentNode.parentNode != undefined) {
		icon = topics[i].parentNode.parentNode.getElementsByTagName('td')[0].getElementsByTagName('img')[0];
		// check if topic has unread and/or own posts
		if (icon.src.indexOf('_unread') != -1) { topic.className += ' topicNew'; }
		if (icon.src.indexOf('mine') != -1) { topic.className += ' topicOwnPosts'; }
	}
}

	// posts
var elements = document.getElementsByClassName('postauthor');
for (var i in elements) {
	// trace back to the table element containing the post
	if (elements[i].parentNode != undefined) {
		var parent = elements[i].parentNode.parentNode.parentNode.parentNode;
		parent.className = 'postContainer';
	}
}

/**
 * Adds additional css.
 * Lines inside of customCSS/GM_addStyle have to end with \.
 */
var customCSS = '';

	// page width
if (useFullWidth) {
	customCSS += "#qm-page-border { width: 100%; margin-right: 0; padding: 0; } \
	  #qm-hoch { left: 1262px; } ";
}

	// unread boards (bold text)
if (highlightUnreadBoards) {
	customCSS += "a.forumlink { font-weight: normal !important; } \
	a.boardNew { font-weight: bold !important; } ";
}

	// unread topics (bold text)
if (highlightUnreadTopics) {
	customCSS += "a.topictitle { font-weight: normal !important; } \
	a.topicNew { font-weight: bold !important; } ";
}

	// topics containing own posts (italic text)
if (highlightOwnTopics) {
	customCSS += "a.topicOwnPosts { font-style: italic; } ";
}

	// post list (add borders, fill in side bar, create whitespace between posts)
if (betterPostList) {
	customCSS += " .postContainer tbody tr:nth-child(3) td[valign='top']:nth-child(2) { border-bottom: none !important; } \
	.postContainer tbody tr:nth-child(2) td[valign='top']:first-child, .postContainer tbody tr:nth-child(3) td[valign='top']:first-child { background-color: #326499 !important; } \
	.postContainer tbody tr:nth-child(3) td[valign='middle'], .postContainer tbody tr:nth-child(4) td[valign='middle'] {		background-color: #1D3A59 !important; } \
	.postContainer tbody tr:nth-child(3) td:nth-child(2), .postContainer tbody tr:nth-child(4) td:nth-child(2) { border-top: 2px solid #1D3A59; border-bottom: 3px solid #1D3A59; } \
	.postContainer tbody tr:nth-child(4) td[height='20']:first-child, .postContainer tbody tr:nth-child(5) td[height='20']:first-child  { background-color: #FFFFFF !important; } ";
}

	// custom post backgrounds
if (customPostBackgrounds) {
	if (postBackground1) {
	  customCSS += ".postContainer .row1 { background-color: " + postBackground1 + "; } ";
	}
	if (postBackground2) {
	  customCSS += ".postContainer .row2 { background-color: " + postBackground2 + "; } ";
	}
}

	// custom user info color
if (postUserInfoText) {
	customCSS += ".postContainer .postinfo { color: " + postUserInfoText + "; } ";
}

// insert into page source
if (customCSS != '') {
	GM_addStyle(customCSS);
}