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
|
import re
|
||||||
from qutebrowser.api import interceptor
|
from qutebrowser.api import interceptor
|
||||||
from qutebrowser.extensions.interceptors import RedirectException
|
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 = {
|
redirects = {
|
||||||
"youtube": {
|
"youtube": {
|
||||||
|
@ -132,13 +143,11 @@ redirects = {
|
||||||
"rimgo.bcow.xyz",
|
"rimgo.bcow.xyz",
|
||||||
"rimgo.pussthecat.org",
|
"rimgo.pussthecat.org",
|
||||||
"rimgo.totaldarkness.net",
|
"rimgo.totaldarkness.net",
|
||||||
"rimgo.bus-hit.me",
|
|
||||||
"rimgo.esmailelbob.xyz",
|
"rimgo.esmailelbob.xyz",
|
||||||
"imgur.artemislena.eu",
|
"imgur.artemislena.eu",
|
||||||
"rimgo.vern.cc",
|
"rimgo.vern.cc",
|
||||||
"rim.odyssey346.dev",
|
"rim.odyssey346.dev",
|
||||||
"rimgo.privacytools.io",
|
"rimgo.privacytools.io",
|
||||||
"i.habedieeh.re",
|
|
||||||
"rimgo.hostux.net",
|
"rimgo.hostux.net",
|
||||||
"ri.zzls.xyz",
|
"ri.zzls.xyz",
|
||||||
"rimgo.marcopisco.com",
|
"rimgo.marcopisco.com",
|
||||||
|
@ -157,6 +166,7 @@ redirects = {
|
||||||
"scribe.privacydev.net",
|
"scribe.privacydev.net",
|
||||||
"sc.vern.cc",
|
"sc.vern.cc",
|
||||||
],
|
],
|
||||||
|
"postprocess": fixScribePath
|
||||||
},
|
},
|
||||||
"google": {
|
"google": {
|
||||||
"source": ["google.com"],
|
"source": ["google.com"],
|
||||||
|
@ -172,7 +182,6 @@ redirects = {
|
||||||
"wiki.slipfox.xyz",
|
"wiki.slipfox.xyz",
|
||||||
"wikiless.esmailelbob.xyz",
|
"wikiless.esmailelbob.xyz",
|
||||||
"wikiless.funami.tech",
|
"wikiless.funami.tech",
|
||||||
"wikiless.northboot.xyz",
|
|
||||||
"wikiless.org",
|
"wikiless.org",
|
||||||
"wikiless.tiekoetter.com",
|
"wikiless.tiekoetter.com",
|
||||||
],
|
],
|
||||||
|
@ -204,10 +213,12 @@ def rewrite(request: interceptor.Request):
|
||||||
if matched:
|
if matched:
|
||||||
target = service["target"][random.randint(0, len(service["target"]) - 1)]
|
target = service["target"][random.randint(0, len(service["target"]) - 1)]
|
||||||
if target is not None and url.setHost(target) is not False:
|
if target is not None and url.setHost(target) is not False:
|
||||||
|
if "postprocess" in service:
|
||||||
|
service["postprocess"](url)
|
||||||
try:
|
try:
|
||||||
request.redirect(url)
|
request.redirect(url)
|
||||||
except RedirectException:
|
except RedirectException as e:
|
||||||
pass
|
message.error(str(e))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue