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).
This commit is contained in:
parent
8627a51bb7
commit
7121897385
1 changed files with 16 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue