1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2024-12-29 08:16:52 +00:00
dotfiles/qutebrowser/redirects.py

94 lines
2.9 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 PyQt6.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
def farside(url: QUrl, i) -> bool:
url.setHost('farside.link')
p = url.path().strip('/')
url.setPath(urljoin(i, p))
return True
def twitter(url: QUrl) -> bool:
return farside(url, '/nitter/')
def imgur(url: QUrl) -> bool:
return farside(url, '/rimgo/')
def medium(url: QUrl) -> bool:
return farside(url, '/scribe/')
def youtube(url: QUrl) -> bool:
return farside(url, '/invidious/')
def reddit(url: QUrl) -> bool:
return farside(url, '/libreddit/')
def instagram(url: QUrl) -> bool:
return farside(url, '/proxigram/')
def translate(url: QUrl) -> bool:
return farside(url, '/simplytranslate/')
def tiktok(url: QUrl) -> bool:
return farside(url, '/proxitok/')
def quora (url: QUrl) -> bool:
return farside(url, '/querte/')
def fandom(url: QUrl) -> bool:
return farside(url, '/breezewiki/')
def genius(url: QUrl) -> bool:
return farside(url, '/dumb/')
def stackoverflow (url: QUrl) -> bool:
return farside(url, '/anonymousoverflow/')
def wikipedia(url: QUrl) -> bool:
return farside(url, '/wikiless/')
def github(url: QUrl) -> bool:
return farside(url, '/gothub/')
#twitter = o(s, 'unrollnow.com')
m = {
"reddit.com": reddit,
"www.reddit.com": reddit,
"old.reddit.com": reddit,
"youtu.be": youtube,
"youtube.com": youtube,
"www.youtube.com": youtube,
"music.youtube.com": youtube,
"twitter.com": twitter,
"mobile.twitter.com": twitter,
"x.com": twitter,
"imgur.com" : imgur,
"medium.com" : medium,
"www.instagram.com": instagram,
"translate.google.com" : translate,
"vm.tiktok.com" : tiktok,
"www.tiktok.com" : tiktok,
"www.quora.com": quora,
"fandom.com": fandom,
"www.fandom.com": fandom,
"genius.com" : genius,
"stackoverflow.com" : stackoverflow,
"en.wikipedia.org" : wikipedia,
"gothub.com" : github,
"www.twitch.tv" : o(s, 'twineo.exozy.me'),
2022-02-27 23:58:18 +00:00
"discord.com" : o(s, 'canary.discord.com'),
2024-01-12 00:34:37 +00:00
"tumblr.com" : o(s, 'tumblash.fly.dev'),
"www.tumblr.com" : o(s, 'priviblur.fly.dev'),
2022-04-25 22:18:33 +00:00
"www.npr.org" : o(s, 'text.npr.org'),
"www.goodreads.com" : o(s, 'bl.vern.cc'),
"zelda.fandom.com" : o(s, 'zeldawiki.wiki'),
"avatar.wiki" : o(s, 'avatar.antifandom.com'),
"news.ycombinator.com" : o(s, 'news.workers.tools'),
"www.pixiv.net" : o(s, 'pixivfe.exozy.me'),
2022-03-04 17:37:45 +00:00
}
def rewrite(info: interceptor.Request):
if (info.resource_type != interceptor.ResourceType.main_frame or
info.request_url.scheme() in {"data", "blob"}):
return
url = info.request_url
redir = m.get(url.host())
if redir is not None and redir(url) is not False:
info.redirect(url)
interceptor.register(rewrite)