summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorrien333 <rien334@gmail.com>2020-10-01 22:33:29 +0200
committerrien333 <rien334@gmail.com>2020-10-01 22:33:29 +0200
commit2ec17db260438a7d3fb43b56efcd285229bf9675 (patch)
treea338a40f1400ff8c88504665df1fd80fa690f45d /misc
parentc8bae7ac5f0f92669aca8969277a0879672a3750 (diff)
downloadqutebrowser-2ec17db260438a7d3fb43b56efcd285229bf9675.tar.gz
qutebrowser-2ec17db260438a7d3fb43b56efcd285229bf9675.zip
[readability-js] When hinting, use the URL selected via hints
Previously, this userscript always assumed the user wanted to parse the current page. However, this meant that something like `:hint all userscript readability-js` wouldn't work. To fix this, the script now checks if qutebrowser is in hinting mode, and sets the page to be processed accordingly. An alternative solution would be to rewrite this script to rely on `QUTE_URL`+`JSDOM.fromURL` accross the board. However, using `QUTE_HTML` when the target page is already loaded seems faster, uses less data, and works offline.
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/userscripts/readability-js17
1 files changed, 14 insertions, 3 deletions
diff --git a/misc/userscripts/readability-js b/misc/userscripts/readability-js
index 00610db68..b93ac64a2 100755
--- a/misc/userscripts/readability-js
+++ b/misc/userscripts/readability-js
@@ -97,13 +97,24 @@ const HEADER = `
</head>`;
const scriptsDir = path.join(process.env.QUTE_DATA_DIR, 'userscripts');
const tmpFile = path.join(scriptsDir, '/readability.html');
-const domOpts = {url: process.env.QUTE_URL, contentType: "text/html; charset=utf-8"};
-if (!fs.existsSync(scriptsDir)){
+if (!fs.existsSync(scriptsDir)) {
fs.mkdirSync(scriptsDir);
}
-JSDOM.fromFile(process.env.QUTE_HTML, domOpts).then(dom => {
+// When hinting, use the selected hint instead of the current page
+if (process.env.QUTE_MODE === 'hints') {
+ var getDOM = JSDOM.fromURL;
+ var domOpts = {};
+ var target = process.env.QUTE_URL;
+}
+else {
+ var getDOM = JSDOM.fromFile;
+ var domOpts = {url: process.env.QUTE_URL, contentType: "text/html; charset=utf-8"};
+ var target = process.env.QUTE_HTML;
+}
+
+getDOM(target, domOpts).then(dom => {
let reader = new Readability(dom.window.document);
let article = reader.parse();
let content = util.format(HEADER, article.title) + article.content;