1
0
Fork 0
mirror of https://github.com/Phantop/dotfiles synced 2024-11-25 08:13:11 +00:00
dotfiles/qutebrowser/redirects.py

97 lines
3 KiB
Python

from qutebrowser.api import interceptor
from urllib.parse import urljoin
from PyQt6.QtCore import QUrl
import operator
o = operator.methodcaller
s = 'setHost'
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,
"tumblr.com" : o(s, 'priviblur.fly.dev'),
"www.tumblr.com" : o(s, 'priviblur.fly.dev'),
"avatar.wiki" : o(s, 'avatar.antifandom.com'),
"tardis.fandom.com" : o(s, 'tardis.wiki'),
"zelda.fandom.com" : o(s, 'zeldawiki.wiki'),
"discord.com" : o(s, 'canary.discord.com'),
"news.ycombinator.com" : o(s, 'news.workers.tools'),
"www.goodreads.com" : o(s, 'bl.vern.cc'),
"www.npr.org" : o(s, 'text.npr.org'),
"www.pixiv.net" : o(s, 'pixivfe.exozy.me'),
"www.twitch.tv" : o(s, 'twineo.exozy.me'),
}
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)