]> git.rmz.io Git - dotfiles.git/commitdiff
qutebrowser: add interceptor to redirect some urls
authorSamir Benmendil <me@rmz.io>
Sun, 17 Jan 2021 22:36:52 +0000 (22:36 +0000)
committerSamir Benmendil <me@rmz.io>
Sun, 17 Jan 2021 22:36:52 +0000 (22:36 +0000)
qutebrowser/config.py

index 995140464349cbfd24ccbad8ae93a05166a9f239..097a061fd10462a30578d45a2d00f7126d82c764 100644 (file)
@@ -7,6 +7,29 @@
 ## Remove it to not load settings done via the GUI.
 config.load_autoconfig()
 
+try:
+    from qutebrowser.api import interceptor, message
+    from PyQt5.QtCore import QUrl
+
+    def intercept(info: interceptor.Request):
+        url = info.request_url
+        if url.host() == "twitter.com":
+            url.setHost("nitter.net")
+            message.info("Redirecting to " + url.toString())
+            info.redirect(url)
+        if url.host() == "xkcd.com":
+            url.setHost("m.xkcd.com")
+            message.info("Redirecting to " + url.toString())
+            info.redirect(url)
+        if url.host() == "www.bristolpost.co.uk":
+            url.setUrl("https://outline.com/" + url.toString())
+            message.info("Redirecting to " + url.toString())
+            info.redirect(url)
+
+    interceptor.register(intercept)
+except ImportError:
+    pass
+
 ## Aliases for commands. The keys of the given dictionary are the
 ## aliases, while the values are the commands they map to.
 ## Type: Dict