Readability/readability/data/Call.js
Juraj Oravec b9306987e6
Update Readability.js
closes GH-1

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-06-11 09:16:41 +02:00

110 lines
3.4 KiB
JavaScript

/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2016 Jaroslav Bambas <jar.bambas@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
* ============================================================ */
{1}
{2}
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 = '{3}';
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.");
}
}
callReadability();