From 7121897385529d51d187cc4d09c645afa4e848d7 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 23 May 2023 15:42:03 +0200 Subject: [PATCH] qutebrowser: Add URL rewriting for scribe redirects Scribe links are often not redirected correctly if belonging to medium's 'global-identity' redirections. This is a first attempt at fixing those by removing the superfluous string from the scribe URL. Generalized enough to work as a 'post-processing' function for the redirection plugin, which can be set up by pointing the 'postprocess' key of a page entry to a callable object (most likely a function). --- qutebrowser/.config/qutebrowser/redirects.py | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/qutebrowser/.config/qutebrowser/redirects.py b/qutebrowser/.config/qutebrowser/redirects.py index 8323b9d..55c8a14 100644 --- a/qutebrowser/.config/qutebrowser/redirects.py +++ b/qutebrowser/.config/qutebrowser/redirects.py @@ -2,6 +2,17 @@ import random import re from qutebrowser.api import interceptor from qutebrowser.extensions.interceptors import RedirectException +from qutebrowser.utils import message + +def fixScribePath(url): + """ Fix external medium blog to scribe translation. + Some paths from medium will go through a 'global identity' + path which messes up the actual url path we want to go + to and puts it in queries. This puts it back on the path. + """ + new_path = f"{url.path()}{url.query()}" + url.setQuery("") + url.setPath(re.sub(r"m/global-identity-2redirectUrl=", "", new_path)) redirects = { "youtube": { @@ -132,13 +143,11 @@ redirects = { "rimgo.bcow.xyz", "rimgo.pussthecat.org", "rimgo.totaldarkness.net", - "rimgo.bus-hit.me", "rimgo.esmailelbob.xyz", "imgur.artemislena.eu", "rimgo.vern.cc", "rim.odyssey346.dev", "rimgo.privacytools.io", - "i.habedieeh.re", "rimgo.hostux.net", "ri.zzls.xyz", "rimgo.marcopisco.com", @@ -157,6 +166,7 @@ redirects = { "scribe.privacydev.net", "sc.vern.cc", ], + "postprocess": fixScribePath }, "google": { "source": ["google.com"], @@ -172,7 +182,6 @@ redirects = { "wiki.slipfox.xyz", "wikiless.esmailelbob.xyz", "wikiless.funami.tech", - "wikiless.northboot.xyz", "wikiless.org", "wikiless.tiekoetter.com", ], @@ -204,10 +213,12 @@ def rewrite(request: interceptor.Request): if matched: target = service["target"][random.randint(0, len(service["target"]) - 1)] if target is not None and url.setHost(target) is not False: + if "postprocess" in service: + service["postprocess"](url) try: request.redirect(url) - except RedirectException: - pass + except RedirectException as e: + message.error(str(e)) break