BenjaVR / TW-Forum Enhancer

// ==UserScript==
// @name			TW-Forum Enhancer
// @namespace		https://github.com/BenjaVR
// @version			1
// @author			BenjaVR
// @include			*://forum.tribalwars.*
// ==/UserScript==

//========== CONFIGURATION ==========//
var config = {
    //***** WIDTH *****//
    //if your screen is larger than this width, the following values will change (0 if always change)
    minWidth: 1200,
    //give the new width value (percentage or value), ONLY FILL IN A NUMBER, DON'T ADD '%' OR 'px'!
    newWidth: 65,
    //whether the newWidth is a percentage (1) or a fixed value (0)
    isPercentage: 1,

    //***** ZOOM *****//
    //get more content on the page (forum default = 1)
    msgZoom: 0.85,

    //***** USER INFO FIX WIDTH *****//
    //fix width of user info near posts (1) or not (0)
    doUserinfoFix: 1,

    //***** FORUM SEPARATOR *****//
    //enable seperator between threads (1) or not (0)
    enableSep: 1,

    //***** FAT TITLES *****//
    //enable bold titles on the forum threads home page (1) or not (0)
    enableFatTitles: 1,

    //***** PAGE NAV *****//
    //always show page navigation (1) or not (0)
    showPageNav: 1,
    //light color box (1) or dark/default (0)
    lightColorNav: 1,

    //***** DATE AND TIME *****//
    //full date and time from post (1) or only date (0)
    fullDateTime: 1,
    //put the date upperleft, above the avatar (1) instead under post (0)
    dateUpperleft: 1,

    //***** SMALLER HEADER *****//
    //enable smaller header (1) or not (0)
    smallerHeader: 1,
};
//===================================//

(function () {
    'use strict';
    var c = config;
    if (localStorage.forumEnhancerOptions) c = JSON.parse(localStorage.forumEnhancerOptions);
	console.log(c);

    (function () {
        var bar = $('#moderatorBar');
        bar.append('<button class="button" id="enhancerSaver">Save Enhancer Settings!</button>');
        bar.on('click', '#enhancerSaver',function () {
            localStorage.forumEnhancerOptions = JSON.stringify(config);
            alert('Saved!');
        });
    })();

    //***** WIDTH *****//
    var initWidth = (100 * parseInt($('.pageWidth').css('width')) / parseInt($('.pageWidth').parent().css('width'))) + '%';

    if (window.matchMedia) {
        var mq = window.matchMedia('(min-width: ' + c.minWidth + 'px)');
        mq.addListener(fixWidth);
        fixWidth(mq);
    }

    function fixWidth(mq) {
        if (mq.matches) {
            if (c.isPercentage) $('.pageWidth').css('width', c.newWidth + '%');
            else $('.pageWidth').css('width', c.newWidth + 'px');
        } else {
            $('.pageWidth').css('width', initWidth);
        }
    }

    //***** ZOOM *****//
    $('.messageList .message').css('zoom', c.msgZoom);

    //***** USER INFO FIX WIDTH *****//
    if (c.doUserinfoFix) {
        $('.messageUserInfo').each(function () {
            $(this).css('width', 'auto');
            var w = parseInt($('.messageUserInfo').css('width'));
            $('.messageInfo.primaryContent').css('margin-left', w + 35 + 'px');
        });
    }

    //***** FORUM SEPARATOR *****//
    var nodeListNoForum = $('.nodeList:not(#forums)');
    if (c.enableSep) {
        nodeListNoForum.each(function () {
            $(this).find('.node.forum:not(:last)').each(function () {
                $(this).css('border-bottom', '1px solid #c3ab5a');
            });
        });
    }

    //***** FAT TITLES *****//
    if (c.enableFatTitles) {
        nodeListNoForum.each(function () {
            $(this).find('.nodeTitle a').css('font-weight', 'bold');
        });
    }

    //***** PAGE NAV *****//
    if (c.showPageNav) {
        $('.itemPageNav').css('visibility', 'visible');
    }
    if (c.lightColorNav) {
        $('.itemPageNav a').css('color', '#592805');
        $('.itemPageNav a').css('background-color', '#f7ebc2');
        $('.itemPageNav a').css('border-color', '#592805');
        $('.itemPageNav a').hover(function () {
            $(this).css('background-color', '#fdf6e5');
            $(this).css('border-color', '#c3ab5a');
        }, function () {
            $(this).css('background-color', '#f7ebc2');
            $(this).css('border-color', '#592805');
        });
    }

    //***** DATE AND TIME *****//
    if (c.fullDateTime) {
        $('.DateTime').each(function () {
            $(this).text($(this).prop('title'));
        });
    }
    if (c.dateUpperleft) {
        $('.datePermalink').each(function () {
            $(this).closest('.message').find('.messageUserInfo').first().prepend($(this).html());

        });
    }

    //***** SMALLER HEADER *****//
    if (c.smallerHeader) {
        $('#header').css('background', 'none');
        $('#headerMover #headerProxy').css('height', '175px');
        $('#logo').css('line-height', 'normal');
    }
})();