// Sweclockers page widening fix
// version 0.6
// 2005-05-23 Sebastian Jansson
// License: Creative Commons Attribution-NonCommercial-ShareAlike License
// http://creativecommons.org/licenses/by-nc-sa/2.0/
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Sweclockers page widening fix
// @namespace     http://jonex.1go.dk/greasemonkey/
// @description   Stops page widening caused by [code] and [img] tags.
// @include       http://forum.sweclockers.com/*
// ==/UserScript==
function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

function addFixStyles() {
    var maxwidth = window.innerWidth - 250;
    var css = "\
    blockquote  {margin: 1em 0.5em 1em 1.5em; padding: 0;}	\n\
    pre         { overflow: auto; max-width: 500px; }		\n\
    img         { max-width: 500px; }					";
    addGlobalStyle(css);
}

function addFixScript(){
    var head, script;
    head = document.getElementsByTagName('head')[0];
    script = document.createElement('script');
    script.type = 'text/javascript';
    script.innerHTML ="\
    function fixWidth() {									\n\
        var maxwidth = window.innerWidth - 244;				\n\
        var fixRules = document.styleSheets[1].cssRules;	\n\
        fixRules[1].style.maxWidth = maxwidth;				\n\
        fixRules[2].style.maxWidth = maxwidth;			\n    }";
    head.appendChild(script);
}

function fixWidth() {
    var maxwidth = window.innerWidth - 244;
    var fixRules = document.styleSheets[1].cssRules;
    fixRules[1].style.maxWidth = maxwidth;
    fixRules[2].style.maxWidth = maxwidth;
}

//Executes at start:
document.getElementsByTagName('body')[0].setAttribute('onResize','fixWidth();');
addFixStyles();
addFixScript();
fixWidth();