TextReFlower

click on text to reflow into visible area, Android FF USI

Tendrás que instalar una extensión para tu navegador como Tampermonkey, Greasemonkey o Violentmonkey si quieres utilizar este script.

You will need to install an extension such as Tampermonkey to install this script.

Tendrás que instalar una extensión como Tampermonkey o Violentmonkey para instalar este script.

Necesitarás instalar una extensión como Tampermonkey o Userscripts para instalar este script.

Tendrás que instalar una extensión como Tampermonkey antes de poder instalar este script.

Necesitarás instalar una extensión para administrar scripts de usuario si quieres instalar este script.

(Ya tengo un administrador de scripts de usuario, déjame instalarlo)

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Tendrás que instalar una extensión como Stylus antes de poder instalar este script.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

Para poder instalar esto tendrás que instalar primero una extensión de estilos de usuario.

(Ya tengo un administrador de estilos de usuario, déjame instalarlo)

// ==UserScript==
// @name             TextReFlower
// @version          0.1.0
// @author           _leBluem_
// @description      click on text to reflow into visible area, Android FF USI 
// @info             it does this for the text and some parents
// @info             if your lucky, you only have to click once!
// @info             if it already fits the click is ignored
// @info             also works under Android with Firefox and USI UserScriptInjector
// @namespace        https://greatest.deepsurf.us/de/users/83368-lebluem
// @include          *
// @clean-include    true
// @run-at           document-ready
// @include-jquery   true
// @use-greasemonkey true
// ==/UserScript==

// ==info==
// before using this make sure you tried changing the default 
// font size in your browser, on mobiles default is tiny ...
//
// this is simply the userscript version of (with a twist) 
//   https://addons.mozilla.org/en-US/android/addon/android-text-reflow/
//     or (which is enabled by default)
//   https://addons.mozilla.org/de/android/addon/android-text-reflow/ 
// see also:
//   https://addons.mozilla.org/en-US/android/addon/fit-text-to-width/?src=ss
// ==/info==

(function () {
	// inject into dom
  document.addEventListener("click", function(evt){
		//alert("klick!");
		fnAddReflow(window,evt);
	});

	// how many parent objects of the clicked one will be reflown...
	// three (default) levels seems to be enough for a whole article
	var parentLevel = 3;
	// le/ri margin in pixels
	var sideMargin = 15;

	// The main routine, click event.
	// Clicking any text will resize that text width to fit.
	// If it already fits nothing happens
	function fnAddReflow(cWin,e) {
		//cWin is chromeWindow, .content gets html window
		var win = cWin.content;

		// get device width in css pixels
		var winWidth=win.content.innerWidth;

		// get nearest non-inline parent.
		var target = e.target;
		for(var i=e.target; i!==null; i = i.parentElement) {
			var icss = win.getComputedStyle(i);
			target = i;
			if(icss.display!='inline') break;
			//if(icss.['display']!='inline') break;
		}

		// get width/left values for target tag
		var bbox = target.getBoundingClientRect();

		// if box is wider than screen, reset width to make it fit
		if(bbox.width>winWidth) {
			var newWidth = winWidth - (2*sideMargin);
			// do for selected text and some parents
			for (var j=0; j<parentLevel; j++) {
				target.parentNode.style.width = newWidth + "px";
				target=target.parparentNode;
			}
			// do for whole document
			win.document.style.width = newWidth + "px";
			//win.document.documentElement.scrollLeft += bbox.left - sideMargin;
		} else {
			// do for selected text and some parents
			for (var k=0; k<parentLevel; k++) {
				target.parentNode.style.width = "";
				target=target.parparentNode;
			}
			win.document.style.width = "";
		}
	}
})();