Reading Ruler

A userscript that adds a horizontal translucent bar that follows the cursor. A reading aid for pages with wiiiiiiide paragraphs. Ctrl+Shift+R to toggle by default.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Reading Ruler
// @namespace    https://old.reddit.com/r/SomebodyMakeThis/comments/9huwbw/smt_a_firefox_addon_that_adds_a_horizontal/
// @version      1.0.3
// @description  A userscript that adds a horizontal translucent bar that follows the cursor. A reading aid for pages with wiiiiiiide paragraphs. Ctrl+Shift+R to toggle by default.
// @author       /u/defproc
// @match        */*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // quick options
    const conf = {
        colour: "#55cc551c",
        lineColour: "#33aa3334", // colour of the bottom edge of the bar
        scale: 1.05, // how many times the text's line-height should the bar's height be
        shadow: 0.08, // opacity of the bar's shadow (0 to 1)
        key: "r", // toggle key
        keyCtrl: true, // toggle key requires ctrl?
        keyAlt: true, // toggle key requires alt?
        keyShift: false, // toggle key requires shift?
    };







    const bar = document.createElement("div");
    let visible = false;
    const styles = {
        left: 0,
        right: 0,
        height: "1em",
        backgroundColor: conf.colour,
        borderBottom: conf.lineColour ? `1px ${conf.lineColour} solid` : void 0,
        position: "fixed",
        transform: "translateY(-50%)",
        display: "none",
        pointerEvents: "none",
        transition: "120ms height",
        boxShadow: `0 1px 4px rgba(0, 0, 0, ${conf.shadow})`,
        zIndex: 9999999
    };
    Object.keys(styles).forEach(function(k){ bar.style[k] = styles[k] });
    document.body.addEventListener("mousemove", function(ev){
        bar.style.top = ev.clientY + "px";
        if(visible){
            const over = document.elementFromPoint(ev.clientX, ev.clientY);
            const size = window.getComputedStyle(over).getPropertyValue("line-height");
            const [m, num, unit] = (size && size.match(/([\d\.]+)([^\d]+)/)) || [];
            bar.style.height = m ? num * conf.scale + unit : "1em";
        }
    });
    const toggle = function(){
        visible = !visible;
        if(!bar.parentElement){
            document.body.appendChild(bar);
        }
        bar.style.display = visible ? "block" : "none";
    };
    window.addEventListener("keypress", function(ev){
        if(
            !(ev.ctrlKey ^ conf.keyCtrl) &&
            !(ev.altKey ^ conf.keyAlt) &&
            !(ev.shiftKey ^ conf.keyShift) &&
            ev.key.toLowerCase() == conf.key.toLowerCase()
        ){
            toggle();
            ev.preventDefault();
        }
    });

})();