InoReader embed current article

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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();