/* ============================================================ * Readability - plugin for Falkon * Copyright (C) 2016 Jaroslav Bambas * Copyright (C) 2019-2022 Juraj Oravec * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ {readability.js} {toolbar.js} function callReadability(){ var article = new Readability(document).parse(); renderPage(article); } function readabilityHead(article){ var head = document.createElement('head'); document.documentElement.appendChild(head); var title = document.createElement('title'); title.innerHTML = article.title; head.appendChild(title); var css = document.createElement('style'); css.innerHTML = '{style.css}'; head.appendChild(css); var meta = document.createElement('meta'); meta.content = "text/html; charset=UTF-8"; meta.httpEquiv = 'content-type'; head.appendChild(meta); meta = document.createElement('meta'); meta.name = 'viewport'; meta.content = 'width=device-width, user-scalable=0'; head.appendChild(meta); } function readablilityBody(article){ var body = document.createElement('body'); body.className = 'loaded sans-serif sepia'; document.documentElement.appendChild(body); var container = document.createElement('div'); container.className = 'container font-size5'; container.id = 'container'; body.appendChild(container); var header = document.createElement('div'); header.className = 'header'; header.id = 'reader-header'; header.style.display = 'block'; container.appendChild(header); var domain = document.createElement('a'); domain.id = 'reader-domain'; domain.className = 'domain'; domain.href = document.location.href; domain.innerHTML = document.location.host; header.appendChild(domain); var h1 = document.createElement('h1'); h1.id = 'reader-title'; h1.innerHTML = article.title; header.appendChild(h1); var credit = document.createElement('div'); credit.id = 'reader-credits'; credit.className = 'credits'; credit.innerHTML = article.byline; header.appendChild(credit); var content = document.createElement('div'); content.className = 'content'; container.appendChild(content); var reader_content = document.createElement('div'); reader_content.id = 'moz-reader-content'; reader_content.style.display = 'block'; reader_content.innerHTML = article.content; content.appendChild(reader_content); } function renderPage(article){ var element = document.documentElement; if(element && !!article && !!article.content){ element.removeChild(document.body); element.removeChild(document.head); readabilityHead(article); readablilityBody(article); readablilityToolbar(); } else { alert("No content to transform."); } } function initConfig(colorTheme, font, fontSize){ switch(colorTheme) { case "light": switchToLight(); break; case "dark": switchToDark(); break; case "sepia": default: switchToSepia(); } switch(font){ case "serif": switchToSerif(); break; case "sans-serif": default: switchToSansSerif(); } fontSizeSet(fontSize); } function init() { external.extra.readability.init.connect(function(theme, font, fontSize) { if (!document.hidden) { callReadability(); initConfig(theme, font, fontSize) } }) } if (window._falkon_external) { init(); } else { document.addEventListener("_falkon_external_created", init); }