2021-02-10 00:11:23 +00:00
|
|
|
from qutebrowser.api import interceptor
|
2022-03-09 19:13:21 +00:00
|
|
|
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
|
|
|
|
2021-02-03 03:20:48 +00:00
|
|
|
o = operator.methodcaller
|
|
|
|
s = 'setHost'
|
2021-02-10 00:11:23 +00:00
|
|
|
i = interceptor
|
|
|
|
|
2022-03-09 19:13:21 +00:00
|
|
|
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/')
|
2022-09-09 18:54:48 +00:00
|
|
|
def proxitok(url: QUrl) -> bool:
|
|
|
|
return farside(url, '/proxitok/')
|
|
|
|
def querte (url: QUrl) -> bool:
|
|
|
|
return farside(url, '/querte/')
|
2022-03-09 19:13:21 +00:00
|
|
|
|
2022-09-09 18:54:48 +00:00
|
|
|
map = {
|
2022-03-09 19:13:21 +00:00
|
|
|
"reddit.com": reddit,
|
|
|
|
"www.reddit.com": reddit,
|
|
|
|
"old.reddit.com": reddit,
|
2021-02-03 03:20:48 +00:00
|
|
|
|
2022-03-09 19:13:21 +00:00
|
|
|
"youtu.be": invid,
|
|
|
|
"youtube.com": invid,
|
|
|
|
"www.youtube.com": invid,
|
2021-02-03 03:20:48 +00:00
|
|
|
|
2022-03-09 19:13:21 +00:00
|
|
|
"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,
|
2022-09-09 18:54:48 +00:00
|
|
|
"vm.tiktok.com" : proxitok,
|
2022-09-11 23:38:40 +00:00
|
|
|
"www.tiktok.com" : proxitok,
|
2022-09-09 18:54:48 +00:00
|
|
|
"www.quora.com": querte,
|
2021-02-03 03:20:48 +00:00
|
|
|
|
2022-02-04 18:17:39 +00:00
|
|
|
"www.twitch.tv" : o(s, 'm.twitch.tv'),
|
2022-02-27 23:58:18 +00:00
|
|
|
"discord.com" : o(s, 'canary.discord.com'),
|
2022-09-09 18:54:48 +00:00
|
|
|
"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):
|
2021-11-08 21:38:08 +00:00
|
|
|
if (info.resource_type != i.ResourceType.main_frame or
|
|
|
|
info.request_url.scheme() in {"data", "blob"}):
|
|
|
|
return
|
|
|
|
url = info.request_url
|
2022-09-09 18:54:48 +00:00
|
|
|
redir = map.get(url.host())
|
2021-11-08 21:38:08 +00:00
|
|
|
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)
|