2021-02-10 00:11:23 +00:00
|
|
|
from qutebrowser.api import interceptor
|
2021-09-25 05:28:09 +00:00
|
|
|
import operator, typing, socket
|
2021-02-10 00:11:23 +00:00
|
|
|
|
2021-05-18 16:50:56 +00:00
|
|
|
invid = 'vid.puffyan.us'
|
2021-09-07 18:31:45 +00:00
|
|
|
nitter = 'nitter.snopyta.org'
|
2021-01-28 21:23:04 +00:00
|
|
|
reddit = 'teddit.net'
|
|
|
|
|
2021-09-25 05:28:09 +00:00
|
|
|
if socket.gethostname() == "aperture":
|
|
|
|
invid = 'localhost'
|
|
|
|
|
2021-02-03 03:20:48 +00:00
|
|
|
o = operator.methodcaller
|
|
|
|
s = 'setHost'
|
2021-02-10 00:11:23 +00:00
|
|
|
i = interceptor
|
|
|
|
|
2021-02-03 03:20:48 +00:00
|
|
|
MAP = {
|
|
|
|
"reddit.com": o(s, reddit),
|
|
|
|
"www.reddit.com": o(s, reddit),
|
|
|
|
"old.reddit.com": o(s, reddit),
|
|
|
|
|
|
|
|
"twitter.com": o(s, nitter),
|
|
|
|
"api.twitter.com": o(s, nitter),
|
|
|
|
"mobile.twitter.com": o(s, nitter),
|
|
|
|
"platform.twitter.com": o(s, nitter),
|
|
|
|
"www.platform.twitter.com": o(s, nitter),
|
|
|
|
|
|
|
|
"youtu.be": o(s, invid),
|
|
|
|
"youtube.com": o(s, invid),
|
|
|
|
"www.youtube.com": o(s, invid),
|
|
|
|
|
|
|
|
"www.instagram.com": o(s, 'bibliogram.art'),
|
|
|
|
"www.amazon.com": o(s, 'smile.amazon.com'),
|
2021-01-28 21:23:04 +00:00
|
|
|
}
|
2021-02-10 00:11:23 +00:00
|
|
|
def f(info: i.Request):
|
|
|
|
if (info.resource_type != i.ResourceType.main_frame or
|
2021-01-28 21:23:04 +00:00
|
|
|
info.request_url.scheme() in {"data", "blob"}):
|
|
|
|
return
|
|
|
|
url = info.request_url
|
2021-02-03 03:20:48 +00:00
|
|
|
redir = MAP.get(url.host())
|
2021-01-28 21:23:04 +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)
|