From 08691dc0201aad9ae27cc4eddbc5c1389c0ce952 Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 22 Sep 2016 01:18:13 +0200 Subject: [PATCH] Added readability userscript --- misc/userscripts/readability | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 misc/userscripts/readability diff --git a/misc/userscripts/readability b/misc/userscripts/readability new file mode 100755 index 000000000..2de4be5ab --- /dev/null +++ b/misc/userscripts/readability @@ -0,0 +1,25 @@ +#!/usr/bin/env python2 +# +# Executes python-readability on current page and opens the summary as new tab. +# +# Usage: +# :spawn --userscript readability +# +from __future__ import absolute_import +import codecs, os +from readability.readability import Document + +tmpfile=os.path.expanduser('~/.local/share/qutebrowser/userscripts/readability.html') +if not os.path.exists(os.path.dirname(tmpfile)): + os.makedirs(os.path.dirname(tmpfile)) + +with codecs.open(os.environ['QUTE_HTML'], 'r', 'utf-8') as source: + doc = Document(source.read()) + content = doc.summary().replace('', '%s' % doc.title()) + + with codecs.open(tmpfile, 'w', 'utf-8') as target: + target.write('') + target.write(content) + + with open(os.environ['QUTE_FIFO'], 'w') as fifo: + fifo.write('open -t %s' % tmpfile)