| redirects.py - dotfiles - These are my dotfiles. There are many like it, but th… | |
| git clone git://jay.scot/dotfiles | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| redirects.py (2062B) | |
| --- | |
| 1 from qutebrowser.api import interceptor | |
| 2 from urllib.parse import urljoin | |
| 3 from PyQt6.QtCore import QUrl | |
| 4 import operator | |
| 5 | |
| 6 o = operator.methodcaller | |
| 7 s = 'setHost' | |
| 8 i = interceptor | |
| 9 | |
| 10 def farside(url: QUrl, i) -> bool: | |
| 11 url.setHost('farside.link') | |
| 12 p = url.path().strip('/') | |
| 13 url.setPath(urljoin(i, p)) | |
| 14 return True | |
| 15 | |
| 16 def nitter(url: QUrl) -> bool: | |
| 17 return farside(url, '/nitter/') | |
| 18 def rimgo(url: QUrl) -> bool: | |
| 19 return farside(url, '/rimgo/') | |
| 20 def scribe(url: QUrl) -> bool: | |
| 21 return farside(url, '/scribe/') | |
| 22 def wikiless(url: QUrl) -> bool: | |
| 23 return farside(url, '/wikiless/') | |
| 24 def invid(url: QUrl) -> bool: | |
| 25 return farside(url, '/invidious/') | |
| 26 def reddit(url: QUrl) -> bool: | |
| 27 return farside(url, '/libreddit/') | |
| 28 def bibliogram(url: QUrl) -> bool: | |
| 29 return farside(url, '/bibliogram/') | |
| 30 def simplytranslate(url: QUrl) -> bool: | |
| 31 return farside(url, '/simplytranslate/') | |
| 32 def proxitok(url: QUrl) -> bool: | |
| 33 return farside(url, '/proxitok/') | |
| 34 def querte (url: QUrl) -> bool: | |
| 35 return farside(url, '/querte/') | |
| 36 | |
| 37 map = { | |
| 38 "reddit.com": reddit, | |
| 39 "www.reddit.com": reddit, | |
| 40 "old.reddit.com": reddit, | |
| 41 | |
| 42 "youtu.be": invid, | |
| 43 "youtube.com": invid, | |
| 44 "www.youtube.com": invid, | |
| 45 | |
| 46 "twitter.com": nitter, | |
| 47 "mobile.twitter.com": nitter, | |
| 48 | |
| 49 "imgur.com" : rimgo, | |
| 50 "medium.com" : scribe, | |
| 51 "en.wikipedia.org" : wikiless, | |
| 52 "www.instagram.com": bibliogram, | |
| 53 "translate.google.com" : simplytranslate, | |
| 54 "vm.tiktok.com" : proxitok, | |
| 55 "www.tiktok.com" : proxitok, | |
| 56 "www.quora.com": querte, | |
| 57 | |
| 58 "www.twitch.tv" : o(s, 'm.twitch.tv'), | |
| 59 "tumblr.com" : o(s, 'splashblr.fly.dev'), | |
| 60 "www.npr.org" : o(s, 'text.npr.org'), | |
| 61 } | |
| 62 def f(info: i.Request): | |
| 63 if (info.resource_type != i.ResourceType.main_frame or | |
| 64 info.request_url.scheme() in {"data", "blob"}): | |
| 65 return | |
| 66 url = info.request_url | |
| 67 redir = map.get(url.host()) | |
| 68 if redir is not None and redir(url) is not False: | |
| 69 info.redirect(url) | |
| 70 i.register(f) |