~chimo/dotfiles

7179afe1a52eec30946872dafa32b745cfbbc710 — chimo 3 months ago c6f263c
qutebrowser: Add custom userscripts
3 files changed, 31 insertions(+), 0 deletions(-)

M .config/qutebrowser/config.py
A .config/qutebrowser/userscripts/list_rss.py
M .gitignore
M .config/qutebrowser/config.py => .config/qutebrowser/config.py +2 -0
@@ 6,6 6,8 @@ def bind_chained(key, *commands):

bind_chained('<Escape>', 'clear-keychain', 'search')

config.bind('gF', 'spawn --userscript ~/.config/qutebrowser/userscripts/list_rss.py')

c.qt.force_platform = 'wayland'

# Enable JS

A .config/qutebrowser/userscripts/list_rss.py => .config/qutebrowser/userscripts/list_rss.py +28 -0
@@ 0,0 1,28 @@
#!/usr/bin/env python3

# Inspired by https://github.com/qutebrowser/qutebrowser/blob/main/misc/userscripts/openfeeds

import os
import re
import base64

from bs4 import BeautifulSoup
from urllib.parse import urljoin

with open(os.environ['QUTE_HTML'], 'r') as f:
    soup = BeautifulSoup(f)

with open(os.environ['QUTE_FIFO'], 'w') as f:
    txt = ''
    for link in soup.find_all('link', rel='alternate', type=re.compile(r'application/((rss|rdf|atom)\+)?xml|text/xml')):
        txt += urljoin(os.environ['QUTE_URL'], link.get('href')) + '\n'

    if txt == '':
        txt = 'None.'

    b = base64.b64encode(bytes(txt, 'utf-8')) # bytes
    base64_str = b.decode('utf-8') # convert bytes to string
    data_url = 'data:text/plain;base64,' + base64_str

    f.write('open -t %s\n' % data_url)


M .gitignore => .gitignore +1 -0
@@ 1,3 1,4 @@
.config/qutebrowser/*
!.config/qutebrowser/config.py
!.config/qutebrowser/userscripts
!.config/qutebrowser/pyconfig