InoReader embed current article

restores the recently-removed (jan 29, 2020 (v13)) functionality to embed the full article page using the q shortcut-key

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         InoReader embed current article
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  restores the recently-removed (jan 29, 2020 (v13)) functionality to embed the full article page using the q shortcut-key
// @author       You
// @match        https://www.inoreader.com/*
// @grant        none
// ==/UserScript==

const injectStyle = () => {
    const style = `
        .overlayContainer {
            width: 100vw;
            height: 100vh;
            background-color: rgba(0,0,0,0);
            position: absolute;
            cursor: pointer;
            z-index: 99999;
        }

        .embedOverlay {
            position: absolute;
            z-index: 999999;
            background-color: #484848;
            width: 90%;
            height: 95%;
            top: -100%;
            left: 5%;
            box-shadow: black 0px 0px 20px;
            -webkit-animation: slide 0.5s forwards;
            animation: slide 0.5s forwards;
        }

        @-webkit-keyframes slide {
            100% { top: 2.5%; }
        }

        @keyframes slide {
            100% { top: 2.5%; }
        }

        .closeControl {
            position: absolute;
            z-index: 9999999;
            cursor: pointer;
            right: 30px;
            top: 13px;
            font-size: 30px;
            background-color: white;
            border: 1px solid black;
            padding: 0 5px;
            box-shadow: black 0 0 3px;
        }

        .articleEmbed {
            width: 100%;
            height: calc(100% - 25px);
            height: 100%;
        }
    `;
    const injectedStyle = document.createElement(`style`);
    injectedStyle.innerHTML = style;
    document.body.appendChild(injectedStyle);
};

const hideOverlay = () => {
    document.body.removeChild(document.querySelector(`.overlayContainer`));
}

const showOverlay = () => {
    let selectedArticle;
    document.querySelectorAll(`.article_current a`).forEach(a => {
        if (!selectedArticle && a.href.startsWith(`http`)) {
            selectedArticle = a;
        }
    });
    if (!selectedArticle) {
        alert(`Cannot open embed article, because there is no active article selected`);
        return;
    }

    const overlayContainerElement = document.createElement(`div`);
    overlayContainerElement.className = `overlayContainer`;
    overlayContainerElement.onclick = hideOverlay;

    const overlayElement = document.createElement(`div`);
    overlayElement.className = `embedOverlay`;

    const closeElement = document.createElement(`div`);
    closeElement.className = `closeControl`;
    closeElement.onclick = (e) => { e.stopPropagation(); hideOverlay(); };
    closeElement.innerText = `⨯`;

    const iframeElement = document.createElement(`iframe`);
    iframeElement.className = `articleEmbed`;
    iframeElement.src = selectedArticle.href.replace(`http:`, `https:`);

    overlayElement.appendChild(closeElement);
    overlayElement.appendChild(iframeElement);
    overlayContainerElement.appendChild(overlayElement);

    document.body.insertBefore(overlayContainerElement, document.body.childNodes[0]);
}

const checkKey = (e) => {
    if (document.activeElement.tagName == 'TEXTAREA') {
        return;
    }
    if (event.keyCode == 81 && !event.ctrlKey && !event.shiftKey) { // q
        if (!document.querySelector(`.overlayContainer`)) {
            showOverlay();
        } else {
            hideOverlay();
        }
    }
}

const init = () => {
    injectStyle();
    document.addEventListener("keydown", checkKey);
};

init();