fix forgotten reader mode script

This commit is contained in:
Martin Rotter 2022-03-16 11:33:13 +01:00
parent ac1948eead
commit 2222043b1b
3 changed files with 31 additions and 4 deletions

View File

@ -16,6 +16,7 @@
<file>sounds/goodresult.wav</file> <file>sounds/goodresult.wav</file>
<file>scripts/adblock/adblock-server.js</file> <file>scripts/adblock/adblock-server.js</file>
<file>scripts/readability/readabilize-article.js</file>
<file>graphics/rssguard.ico</file> <file>graphics/rssguard.ico</file>

View File

@ -0,0 +1,10 @@
var rd = require('@mozilla/readability');
var fs = require('fs');
var jsd = require('jsdom');
var iconvlite = require('iconv-lite');
var data = fs.readFileSync(0);
var encData = iconvlite.decode(data, "utf-8");
var doc = new jsd.JSDOM(encData);
var article = new rd.Readability(doc.window.document).parse();
console.log(article['content']);

View File

@ -7,9 +7,14 @@
#include "gui/messagebox.h" #include "gui/messagebox.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include <QDir>
#define READABILITY_PACKAGE "@mozilla/readability" #define READABILITY_PACKAGE "@mozilla/readability"
#define READABILITY_VERSION "0.4.2" #define READABILITY_VERSION "0.4.2"
#define JSDOM_PACKAGE "jsdom"
#define JSDOM_VERSION "19.0.0"
Readability::Readability(QObject* parent) : QObject{parent}, m_modulesInstalling(false), m_modulesInstalled(false) { Readability::Readability(QObject* parent) : QObject{parent}, m_modulesInstalling(false), m_modulesInstalled(false) {
connect(qApp->nodejs(), &NodeJs::packageInstalledUpdated, this, &Readability::onPackageReady); connect(qApp->nodejs(), &NodeJs::packageInstalledUpdated, this, &Readability::onPackageReady);
connect(qApp->nodejs(), &NodeJs::packageError, this, &Readability::onPackageError); connect(qApp->nodejs(), &NodeJs::packageError, this, &Readability::onPackageError);
@ -63,9 +68,13 @@ void Readability::onPackageError(const QList<NodeJs::PackageMetadata>& pkgs, con
void Readability::makeHtmlReadable(const QString& html, const QString& base_url) { void Readability::makeHtmlReadable(const QString& html, const QString& base_url) {
if (!m_modulesInstalled) { if (!m_modulesInstalled) {
try { try {
NodeJs::PackageStatus st = qApp->nodejs()->packageStatus({ QSL(READABILITY_PACKAGE), QSL(READABILITY_VERSION) }); NodeJs::PackageStatus stReadability = qApp->nodejs()->packageStatus({ QSL(READABILITY_PACKAGE),
QSL(READABILITY_VERSION) });
NodeJs::PackageStatus stJsdom = qApp->nodejs()->packageStatus({ QSL(READABILITY_PACKAGE),
QSL(READABILITY_VERSION) });
if (st != NodeJs::PackageStatus::UpToDate) { if (stReadability != NodeJs::PackageStatus::UpToDate ||
stJsdom != NodeJs::PackageStatus::UpToDate) {
if (!m_modulesInstalling) { if (!m_modulesInstalling) {
// We make sure to update modules. // We make sure to update modules.
m_modulesInstalling = true; m_modulesInstalling = true;
@ -100,13 +109,20 @@ void Readability::makeHtmlReadable(const QString& html, const QString& base_url)
} }
} }
QString temp_script = QDir::toNativeSeparators(IOFactory::getSystemFolder(QStandardPaths::StandardLocation::TempLocation)) +
QDir::separator() +
QSL("readabilize-article.js");
if (!IOFactory::copyFile(QSL(":/scripts/readability/readabilize-article.js"), temp_script)) {
qWarningNN << LOGSEC_ADBLOCK << "Failed to copy Readability script to TEMP.";
}
QProcess* proc = new QProcess(this); QProcess* proc = new QProcess(this);
connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Readability::onReadabilityFinished); connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, &Readability::onReadabilityFinished);
qApp->nodejs()->runScript(proc, qApp->nodejs()->runScript(proc,
QSL("c:\\Projekty\\Moje\\build-rssguard-Desktop_Qt_6_2_3_MSVC2017_64bit-Debug\\" temp_script,
"src\\rssguard\\data4\\node-packages-windows\\article-to-readable.js"),
{ base_url }); { base_url });
proc->write(html.toUtf8()); proc->write(html.toUtf8());