2017-09-18 10:17:48 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2020-09-25 15:14:35 +02:00
|
|
|
from qutebrowser.api import interceptor
|
|
|
|
from PyQt5.QtCore import QUrl, QUrlQuery
|
2020-12-04 14:57:05 +01:00
|
|
|
from unalix import clear_url
|
2020-09-25 15:14:35 +02:00
|
|
|
|
2017-09-26 09:59:27 +02:00
|
|
|
config.backend = "webengine"
|
2017-09-18 10:17:48 +02:00
|
|
|
config.load_autoconfig = False
|
|
|
|
c.completion.shrink = True
|
|
|
|
c.confirm_quit = ["downloads"]
|
2020-12-04 14:57:05 +01:00
|
|
|
c.downloads.location.directory = "/tmp"
|
2017-09-18 10:17:48 +02:00
|
|
|
c.downloads.location.suggestion = "both"
|
|
|
|
c.downloads.open_dispatcher = "rifle"
|
2017-09-30 01:38:06 +02:00
|
|
|
c.editor.command = ["st", "-e", "vis", "{}"]
|
2017-09-18 10:17:48 +02:00
|
|
|
c.hints.auto_follow = "full-match"
|
|
|
|
c.hints.dictionary = "/usr/share/dict/mnemonic"
|
|
|
|
c.hints.mode = "word"
|
|
|
|
c.new_instance_open_target = "tab-silent"
|
2018-01-04 17:46:18 +01:00
|
|
|
c.session.default_name = "default"
|
2017-09-18 10:17:48 +02:00
|
|
|
c.tabs.background = True
|
|
|
|
c.tabs.last_close = "close"
|
|
|
|
c.tabs.show = "multiple"
|
2018-08-13 14:00:59 +02:00
|
|
|
c.url.default_page = "about:blank"
|
|
|
|
c.url.start_pages = ["qute://bookmarks"]
|
2019-04-18 17:11:10 +02:00
|
|
|
c.url.searchengines = { "startpage": "https://startpage.com/do/search?query={}"
|
2019-03-11 10:41:11 +01:00
|
|
|
, "ecosia": "https://www.ecosia.org/search?q={}"
|
2020-04-15 00:36:07 +02:00
|
|
|
, "qwant": "https://lite.qwant.com/?q={}"
|
2020-08-20 15:54:32 +02:00
|
|
|
, "cliqz": "https://beta.cliqz.com/search?q={}" # discontinued
|
2020-03-14 13:34:27 +01:00
|
|
|
, "duckduckgo": "https://duckduckgo.com/html?q={}"
|
|
|
|
, "duckduckgonion": "https://3g2upl4pq6kufc4m.onion/html?q={}"
|
2019-08-23 17:00:42 +02:00
|
|
|
, "framabee": "https://framabee.org/?q={}"
|
2020-08-27 12:32:04 +02:00
|
|
|
, "invidious": "http://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion/search?q={}"
|
|
|
|
, "invidious-untor": "https://invidious.snopyta.org/search?q={}"
|
2020-08-20 15:54:32 +02:00
|
|
|
, "openstreetmap": "https://www.openstreetmap.org/search?query={}"
|
|
|
|
, "wikipedia": "https://en.wikipedia.org/w/index.php?search={}"
|
|
|
|
, "wikipedia/nl": "https://nl.wikipedia.org/w/index.php?search={}"
|
|
|
|
, "hoogle": "https://hoogle.haskell.org/?hoogle={}"
|
|
|
|
, "snopyta": "http://juy4e6eicawzdrz7.onion/?q={}"
|
|
|
|
, "DEFAULT": "http://juy4e6eicawzdrz7.onion/?q={}"
|
|
|
|
, "telefoonboek": "https://telefoonboek.ugent.be/nl/simple?name={}"
|
2019-01-22 16:39:44 +01:00
|
|
|
}
|
2020-01-02 13:35:46 +01:00
|
|
|
|
|
|
|
# Privacy
|
|
|
|
c.content.proxy = "socks://localhost:9050"
|
|
|
|
c.content.javascript.enabled = False
|
|
|
|
c.content.canvas_reading = False # https://en.wikipedia.org/wiki/Canvas_fingerprinting
|
|
|
|
c.content.webgl = False # https://browserleaks.com/webgl
|
|
|
|
c.content.ssl_strict = True
|
|
|
|
c.content.headers.accept_language = "en-US,en;q=0.5"
|
|
|
|
c.content.headers.custom = { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" }
|
2020-11-13 11:25:08 +01:00
|
|
|
c.content.headers.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36"
|
2020-01-02 13:35:46 +01:00
|
|
|
c.content.webrtc_ip_handling_policy = "default-public-interface-only"
|
|
|
|
|
|
|
|
# Aliases
|
2017-10-02 23:48:56 +02:00
|
|
|
c.aliases = { "wq": "quit --save"
|
|
|
|
, "set": "set -t"
|
2017-11-06 17:23:19 +01:00
|
|
|
, "quickmarks": "open qute://bookmarks/"
|
2017-10-02 23:48:56 +02:00
|
|
|
}
|
2017-09-18 10:17:48 +02:00
|
|
|
|
2020-01-02 13:35:46 +01:00
|
|
|
# Bindings
|
2017-09-18 10:17:48 +02:00
|
|
|
config.bind("<backspace>", "back", mode="normal")
|
|
|
|
config.bind("x", "spawn --detach mpv {url}", mode="normal")
|
|
|
|
config.bind(";x", "hint links spawn --detach mpv {hint-url}", mode="normal")
|
2018-10-25 16:51:15 +02:00
|
|
|
config.bind("<Alt+j>", "prompt-item-focus next", mode="prompt")
|
|
|
|
config.bind("<Alt+k>", "prompt-item-focus prev", mode="prompt")
|
|
|
|
config.bind("<Alt+l>", "fake-key -g /", mode="prompt")
|
|
|
|
config.bind("<Alt+h>", "rl-unix-filename-rubout", mode="prompt")
|
2020-08-20 15:54:32 +02:00
|
|
|
config.bind("o", "set-cmd-text -s :open -s ", mode="normal")
|
|
|
|
config.bind("O", "set-cmd-text -s :open -s -t ", mode="normal")
|
|
|
|
config.bind("\\", "set-cmd-text -s :open ", mode="normal")
|
|
|
|
config.bind("|", "set-cmd-text -s :open -t ", mode="normal")
|
2017-11-06 17:23:19 +01:00
|
|
|
|
|
|
|
# I don't use bookmarks
|
|
|
|
config.unbind('wB')
|
|
|
|
config.unbind('gb')
|
|
|
|
config.unbind('gB')
|
|
|
|
config.unbind('Sb')
|
2018-03-12 10:36:09 +01:00
|
|
|
|
|
|
|
# Allowing javascript for...
|
2018-07-02 16:47:27 +02:00
|
|
|
allowed = [ 'https://duckduckgo.com/*'
|
2018-03-12 10:36:09 +01:00
|
|
|
, 'https://github.com/*'
|
2018-03-25 14:00:16 +02:00
|
|
|
, 'https://*.ugent.be/*'
|
2019-08-02 10:08:51 +02:00
|
|
|
, 'https://secure.ogone.com/*' # bancontact
|
|
|
|
, 'https://belgium-3dsecure.wlp-acs.com/*' # bancontact
|
2020-09-22 11:00:45 +02:00
|
|
|
, 'https://belgium-3ds.wlp-acs.com/*' # bancontact
|
2019-08-02 10:08:51 +02:00
|
|
|
, 'https://bcr.girogate.be/*' # bancontact
|
|
|
|
, 'https://bancontact.girogate.be/*' # bancontact
|
|
|
|
, 'https://belgium-uvj-3dsecure.wlp-acs.com/*' # bancontact
|
2018-10-25 16:51:15 +02:00
|
|
|
, 'https://*.triodos.be/*'
|
2018-06-26 15:38:39 +02:00
|
|
|
, 'https://www.openstreetmap.org/*'
|
2018-09-13 09:43:33 +02:00
|
|
|
, 'https://mattermost.zeus.gent/*'
|
2018-08-13 14:00:59 +02:00
|
|
|
, 'https://posteo.de/*'
|
2018-08-31 15:00:03 +02:00
|
|
|
, 'https://doc.rust-lang.org/*'
|
2018-11-21 16:37:36 +01:00
|
|
|
, 'https://www.paypal.com/*'
|
2019-04-18 17:11:10 +02:00
|
|
|
, 'https://www.paypal-topup.be/*'
|
|
|
|
, 'https://homebank.argenta.be/*'
|
2018-03-12 10:36:09 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
for pattern in allowed:
|
|
|
|
config.set('content.javascript.enabled', True, pattern)
|
2020-08-20 15:54:32 +02:00
|
|
|
|
|
|
|
# Allowing cookies for...
|
|
|
|
c.content.cookies.accept = "never"
|
|
|
|
allowed = [ 'https://github.com/*'
|
|
|
|
, 'https://*.ugent.be/*'
|
|
|
|
, 'https://*.triodos.be/*'
|
|
|
|
, 'https://mattermost.zeus.gent/*'
|
|
|
|
, 'https://posteo.de/*'
|
|
|
|
, 'https://homebank.argenta.be/*'
|
2020-10-16 10:31:03 +02:00
|
|
|
, 'https://*.facebookcorewwwi.onion/*'
|
2020-12-04 14:57:05 +01:00
|
|
|
, 'https://adventofcode.com/*'
|
2020-08-20 15:54:32 +02:00
|
|
|
]
|
|
|
|
for pattern in allowed:
|
|
|
|
config.set('content.cookies.accept', "no-3rdparty", pattern)
|
2020-09-25 15:14:35 +02:00
|
|
|
|
|
|
|
# Some redirects
|
|
|
|
redirects = { 'www.reddit.com': 'old.reddit.com'
|
|
|
|
, 'www.youtube.com': 'c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion'
|
|
|
|
, 'www.youtube.be': 'c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion'
|
|
|
|
, 'youtu.be': 'c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion'
|
2020-10-16 10:31:03 +02:00
|
|
|
, 'twitter.com': 'nitter.net'
|
2020-09-25 15:14:35 +02:00
|
|
|
}
|
|
|
|
|
2020-12-04 14:57:05 +01:00
|
|
|
nohttps = [ 'c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion'
|
|
|
|
, 'juy4e6eicawzdrz7.onion'
|
|
|
|
]
|
|
|
|
|
2020-09-25 15:14:35 +02:00
|
|
|
def intercept(info: interceptor.Request) -> None:
|
2020-12-04 14:57:05 +01:00
|
|
|
if not info.request_url.scheme().startswith('http'):
|
|
|
|
return
|
|
|
|
|
|
|
|
new_url = QUrl(clear_url(info.request_url.url()))
|
|
|
|
|
|
|
|
if new_host := redirects.get(new_url.host()):
|
2020-09-25 15:14:35 +02:00
|
|
|
new_url.setHost(new_host)
|
|
|
|
|
2020-12-04 14:57:05 +01:00
|
|
|
if new_url.scheme() == 'https' and new_url.host() in nohttps:
|
2020-09-28 16:51:36 +02:00
|
|
|
new_url.setScheme('http')
|
2020-12-04 14:57:05 +01:00
|
|
|
|
|
|
|
if new_url != info.request_url:
|
2020-09-28 16:51:36 +02:00
|
|
|
info.redirect(new_url)
|
|
|
|
|
2020-09-25 15:14:35 +02:00
|
|
|
interceptor.register(intercept)
|