qutebrowser: Add proxying support for websites

Added automatic proxying to floss alternative frontends for proprietary
websites like reddit (teddit), youtube (invidious), twitter (nitter),
and instagram (bibliogram).

Often does not work on calling cached websites, meaning when it does not
load the correct page a full reload (shift-R) should call up the correct
frontend on first use of a previously visited page.

Squashed commit of the following:

commit ccf5a9f9a001c466e4fe00763f561d09a598bd70
Author: Marty Oehme <marty.oehme@gmail.com>
Date:   Wed Jul 28 10:05:37 2021 +0200

    qutebrowser: Add LocalLeader key concept

    Added differentiation between leader mappings and local leader mappings,
    with a similar idea to vim:
    leader mappings enact changes within qutebrowser on a more general level
    (currently e.g. changing tab display, javascript switch, stylesheet
    setting) while
    local leader mappings enact changes or interact with the current page
    context
    (e.g. start mpv stream, display in readability mode, download pdf
    version of page, and so on).

    This will be hard for my muscle memory, but I think such a switch
    benefits logical action separation in the long run, especially in case I
    add more action shortcuts over time.

    An interesting thing this separation also allows is a more
    buffer-specific action repertoire (for example through recognition of
    current page context with interceptors) so specific pages contain
    different actions.

commit afbe573d527b70fa57d643ede78cd5e71f3ca4c1
Author: Marty Oehme <marty.oehme@gmail.com>
Date:   Tue Jul 27 16:00:37 2021 +0200

    qutebrowser: Rename key mapping file

    Renamed from `keys.py` to `maps.py` to keep some coherence with nvim
    naming scheme.

commit cc78cbb67953bba7ab4d5a6dd48dfa50fbcfe2fc
Author: Marty Oehme <marty.oehme@gmail.com>
Date:   Tue Jul 27 10:19:34 2021 +0200

    qutebrowser: Add reddit redirection

    Added redirection to old.reddit whenever a link on reddit is opened.
    Added redirection of youtube links to yewtu.be invidious instance.
This commit is contained in:
Marty Oehme 2021-08-18 22:28:50 +02:00
parent 496522605f
commit 62f680ecd3
Signed by: Marty
GPG Key ID: B7538B8F50A1C800
6 changed files with 67 additions and 30 deletions

2
.gitignore vendored
View File

@ -24,6 +24,8 @@ sponsorblock.txt
/qutebrowser/.config/qutebrowser/qsettings
/qutebrowser/.config/qutebrowser/bookmarks
/qutebrowser/.config/qutebrowser/stylesheets
# ignore the generated readability file for webpages
readability.html
# ignore vifm & ueberzug utility files
vifm-help.txt

View File

@ -101,3 +101,4 @@ indices
Anthropocene
ecotourism
legitimation
wellbeing

View File

@ -41,7 +41,7 @@ c.downloads.location.directory = os.getenv("XDG_DOWNLOAD_DIR", "~/downloads")
c.downloads.location.prompt = False
config.source("alias.py")
config.source("keys.py")
config.source("maps.py")
config.source("content.py")
config.source("url.py")

View File

@ -12,6 +12,7 @@ c.content.blocking.hosts.lists = [
]
c.content.blocking.whitelist = ["piwik.org"]
c.content.autoplay = False
c.content.prefers_reduced_motion = True
c.content.pdfjs = False
c.content.javascript.enabled = False
js_whitelist = [
@ -19,7 +20,6 @@ js_whitelist = [
"*://127.0.0.1/*",
"*://asciinema.org/*",
"*://calendar.google.com/*",
"*://clockify.me/tracker*",
"*://darksky.net/*",
"*://deepl.com/*",
"*://duckduckgo.com/*",
@ -32,8 +32,6 @@ js_whitelist = [
"*://*.martyoeh.me/*",
"*://news.ycombinator.com/*",
"*://old.reddit.com/*",
"*://todoist.com/*",
"*://toggl.com/*",
"*://translate.google.com/*",
"chrome://*/*",
"file://*",

View File

@ -1,6 +1,8 @@
# Key mappings
# 'Leader' key binding
# 'Leader' key binding -- for general personal maps
leader = "<Space>"
# 'LocalLeader' key binding -- intended for 'in-page' personal maps
lleader = ","
## CHANGED DEFAULTS
@ -24,18 +26,19 @@ config.bind(leader + "tV", "set tabs.position left")
# [M]edia shortcuts - watch, queue, download media
# bind mpv to play the current page/links, using a single instance which queues the next link passed
config.bind(leader + "M", "spawn umpv {url}")
config.bind(leader + "m", "hint links spawn umpv {hint-url}")
config.bind(lleader + "M", "spawn umpv {url}")
config.bind(lleader + "m", "hint links spawn umpv {hint-url}")
# bind youtube-dl to download the current page/links
config.bind(leader + "dM", "spawn vidl {url}")
config.bind(lleader + "dM", "spawn vidl {url}")
config.bind(
leader + "dm",
lleader + "dm",
"hint --rapid links spawn vidl {hint-url}",
)
# Download shortcuts
config.bind(leader + "dd", "download", mode="normal")
config.bind(leader + "dp", "save_to_pdf", mode="normal")
config.bind(lleader + "dd", "download", mode="normal")
config.bind(lleader + "dp", "save_to_pdf", mode="normal")
# open last download
config.bind("gD", "spawn --userscript open_download")
@ -45,12 +48,12 @@ config.bind('"s', "add-shaarli", mode="normal")
config.bind('"a', "send-to-archive", mode="normal")
config.bind('"o', "send-to-outline", mode="normal")
config.bind('"g', "translate-page-google", mode="normal")
config.bind('"G', "translate-selection-google", mode="normal")
config.bind('"t', "translate-page-google", mode="normal")
config.bind('"T', "translate-selection-google", mode="normal")
config.bind('"q', "show-qr")
config.bind(leader + "r", "spawn --userscript readability")
config.bind(lleader + "r", "spawn --userscript readability")
# set stylesheets for the browser to use
config.bind(

View File

@ -1,26 +1,59 @@
from qutebrowser.api import interceptor, message
c.url.searchengines = {
"#sci": "https://sci-hub.do/{}",
"DEFAULT": "https://search.martyoeh.me/?q={}",
"l": "https://links.martyoeh.me/?searchterm={}&searchtags=",
"ddg": "https://duckduckgo.com/?q={}",
"al": "https://wiki.archlinux.org/index.php/{}",
"alt": "https://alternativeto.net/software/{}/?license=opensource",
"aur": "https://aur.archlinux.org/packages/?K={}",
"d": "https://www.dict.cc/?s={}",
"t": "https://www.thesaurus.com/browse/{}",
"gt": "https://translate.google.com/#auto/de/{}",
"ddg": "https://duckduckgo.com/?q={}",
"dt": "https://www.deepl.com/translator#en/de/{}",
"g": "https://www.google.com/search?q={}",
"r": "https://old.reddit.com/r/{}",
"w": "https://en.wikipedia.org/w/index.php?search={}",
"gh": "https://github.com/search?q={}",
"al": "https://wiki.archlinux.org/index.php/{}",
"aur": "https://aur.archlinux.org/packages/?K={}",
"yt": "https://www.youtube.com/results?search_query={}",
"maps": "https://www.google.fr/maps?q={}",
"gol": "https://golang.org/pkg/{}/",
"man": "https://manned.org/browse/search?q={}",
"lib": "http://libgen.fun/search.php?req={}",
"#sci": "https://sci-hub.do/{}",
"alt": "https://alternativeto.net/software/{}/?license=opensource",
"gt": "https://translate.google.com/#auto/de/{}",
"hn": "https://hn.algolia.com/?q={}",
"kb": "https://soeg.kb.dk/discovery/search?query=any,contains,{}&tab=Everything&search_scope=MyInst_and_CI&vid=45KBDK_KGL:KGL&offset=0&lang=en",
"kb": "https://soeg.kb.dk/discovery/search?query=any,contains,{}&lang=en",
"l": "https://links.martyoeh.me/?searchterm={}&searchtags=",
"lib": "http://libgen.fun/search.php?req={}",
"man": "https://manned.org/browse/search?q={}",
"maps": "https://www.google.fr/maps?q={}",
"r": "https://www.reddit.com/r/{}",
"t": "https://www.thesaurus.com/browse/{}",
"w": "https://en.wikipedia.org/w/index.php?search={}",
"yt": "https://www.youtube.com/results?search_query={}",
}
c.url.default_page = "https://start.duckduckgo.com"
c.url.start_pages = ["https://start.duckduckgo.com"]
redirects = {
"reddit.com": "teddit.net",
"www.reddit.com": "teddit.net",
"youtube.com": "yewtu.be",
"www.youtube.com": "www.yewtu.be",
"twitter.com": "nitter.net",
"www.twitter.com": "nitter.net",
"instagram.com": "bibliogram.art",
"www.instagram.com": "bibliogram.art",
}
def rewrite(request: interceptor.Request):
if (
request.resource_type != interceptor.ResourceType.main_frame
or request.request_url.scheme() in {"data", "blob"}
):
return
url = request.request_url
redir = redirects.get(url.host())
if redir is not None and url.setHost(redir) is not False:
try:
request.redirect(url)
except:
pass
interceptor.register(rewrite)