// ==UserScript==
// @name        Narrow browser
// @namespace   http://boris.joff3.com
// @description Remove horizontal scrolling by setting max-width on scripts
// @include     *
// @exclude     *.newegg.com/*
// @exclude     *.wunderground.com/*
// @exclude     *.github.com/*
// @version     1.1.2
// @author      borisjoffe
// @run-at      document-start
// @grant       none
// ==/UserScript==

/*
The MIT License (MIT)

Copyright (c) 2016 Boris Joffe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/


(function() {
	'use strict';

	var DBG = false;

	function log() {
	 if (DBG)
		console.log.apply(console, arguments);
	 return arguments[0];
	}

	var changeMinWidth = true;

	var MAXWIDTH = {
		log: log,
		DBG: DBG,
		changeMinWidth: changeMinWidth,
		elements: [
			'p',
			'span',
			'h1, h2, h3, h4, h5, h6',
			'div',
			'nav',
			'a',
			'pre',
			'li',
			'input',
			'body'
		].join(','),

		screenWidth: function () {
			return log(window.innerWidth, '- innerWidth');
		}
	};

	MAXWIDTH.width = function () {
		return log(MAXWIDTH.screenWidth() - 10, ' - width');
	};

	MAXWIDTH.css = function () {
		return log(
			MAXWIDTH.elements + ' { max-width: ' + MAXWIDTH.width() + 'px !important;' +
			// TODO: change minWidth better - only if it's set
			(changeMinWidth ? 'min-width: 0px !important; ' : '') +
			' }',
			' - css'
		);
	};

	if (DBG)
		window.MAXWIDTH = MAXWIDTH;

	function addCss() {
		var css = MAXWIDTH.css();

		if (typeof GM_addStyle != "undefined") {
			GM_addStyle(css);
		} else if (typeof PRO_addStyle != "undefined") {
			PRO_addStyle(css);
		} else if (typeof addStyle != "undefined") {
			addStyle(css);
		} else {
			var node = document.createElement("style");
			node.type = "text/css";
			node.appendChild(document.createTextNode(css));
			var heads = document.getElementsByTagName("head");
			if (heads.length > 0) {
				heads[0].appendChild(node);
			} else {
				// no head yet, stick it whereever
				document.documentElement.appendChild(node);
			}
		}
	}

	addCss();

	// TODO: adjust previous css instead of adding more css
	// to avoid bloat
	window.onresize = addCss;

})();

@@ -34,17 +34,17 @@
  Narrow 
-b
+B
 rowser%0A/
@@ -294,17 +294,17 @@
     1.1.
-2
+3
 %0A// @aut

bump version