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
|
2023-04-08 19:28:19 +00:00
|
|
|
from PyQt6.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 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/')
|
2023-05-25 16:14:34 +00:00
|
|
|
def breezewiki (url: QUrl) -> bool:
|
|
|
|
return farside(url, '/breezewiki/')
|
|
|
|
def dumb (url: QUrl) -> bool:
|
|
|
|
return farside(url, '/dumb/')
|
|
|
|
def anonymousoverflow (url: QUrl) -> bool:
|
|
|
|
return farside(url, '/anonymousoverflow/')
|
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,
|
2023-08-14 12:49:00 +00:00
|
|
|
"music.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,
|
|
|
|
"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,
|
2023-05-25 16:14:34 +00:00
|
|
|
"fandom.com": breezewiki,
|
|
|
|
"www.fandom.com": breezewiki,
|
|
|
|
"genius.com" : dumb,
|
|
|
|
"stackoverflow.com" : anonymousoverflow,
|
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'),
|
2023-08-14 12:49:00 +00:00
|
|
|
"www.tumblr.com" : o(s, 'splashblr.fly.dev'),
|
2022-04-25 22:18:33 +00:00
|
|
|
"www.npr.org" : o(s, 'text.npr.org'),
|
2023-03-07 16:20:28 +00:00
|
|
|
"www.goodreads.com" : o(s, 'bl.vern.cc'),
|
2023-09-07 16:53:42 +00:00
|
|
|
"zelda.fandom.com" : o(s, 'zeldawiki.wiki'),
|
2023-12-05 17:34:37 +00:00
|
|
|
"news.ycombinator.com" : o(s, 'news.workers.tools')
|
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)
|