1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2024-11-09 00:14:53 +00:00
dotfiles/qutebrowser/redirects.py

71 lines
2 KiB
Python
Raw Normal View History

2021-02-10 00:11:23 +00:00
from qutebrowser.api import interceptor
from urllib.parse import urljoin
from PyQt5.QtCore import QUrl
2022-01-12 23:02:54 +00:00
import operator
2021-02-10 00:11:23 +00:00
o = operator.methodcaller
s = 'setHost'
2021-02-10 00:11:23 +00:00
i = interceptor
def farside(url: QUrl, i) -> bool:
url.setHost('farside.link')
p = url.path().strip('/')
url.setPath(urljoin(i, p))
return True
def nitter(url: QUrl) -> bool:
return farside(url, '/nitter/')
def rimgo(url: QUrl) -> bool:
return farside(url, '/rimgo/')
def scribe(url: QUrl) -> bool:
return farside(url, '/scribe/')
def wikiless(url: QUrl) -> bool:
return farside(url, '/wikiless/')
def invid(url: QUrl) -> bool:
return farside(url, '/invidious/')
def reddit(url: QUrl) -> bool:
return farside(url, '/libreddit/')
def bibliogram(url: QUrl) -> bool:
return farside(url, '/bibliogram/')
def simplytranslate(url: QUrl) -> bool:
return farside(url, '/simplytranslate/')
def proxitok(url: QUrl) -> bool:
return farside(url, '/proxitok/')
def querte (url: QUrl) -> bool:
return farside(url, '/querte/')
map = {
"reddit.com": reddit,
"www.reddit.com": reddit,
"old.reddit.com": reddit,
"youtu.be": invid,
"youtube.com": invid,
"www.youtube.com": invid,
"twitter.com": nitter,
"mobile.twitter.com": nitter,
"imgur.com" : rimgo,
"medium.com" : scribe,
"en.wikipedia.org" : wikiless,
"www.instagram.com": bibliogram,
"translate.google.com" : simplytranslate,
"vm.tiktok.com" : proxitok,
"www.quora.com": querte,
"www.twitch.tv" : o(s, 'm.twitch.tv'),
2022-02-27 23:58:18 +00:00
"discord.com" : o(s, 'canary.discord.com'),
"tumblr.com" : o(s, 'splashblr.fly.dev'),
2022-04-25 22:18:33 +00:00
"www.npr.org" : o(s, 'text.npr.org'),
2022-03-04 17:37:45 +00:00
}
2021-02-10 00:11:23 +00:00
def f(info: i.Request):
if (info.resource_type != i.ResourceType.main_frame or
info.request_url.scheme() in {"data", "blob"}):
return
url = info.request_url
redir = map.get(url.host())
if redir is not None and redir(url) is not False:
info.redirect(url)
2021-02-10 00:11:23 +00:00
i.register(f)