# Documentation:
# qute://help/configuring.html
# qute://help/settings.html
import os
import qutebrowser.api.interceptor
from qutebrowser.config.configfiles import ConfigAPI # noqa: F401
from qutebrowser.config.config import ConfigContainer # noqa: F401
config: ConfigAPI = config # noqa: F821 pylint: disable=E0602,C0103
c: ConfigContainer = c # noqa: F821 pylint: disable=E0602,C0103
config.load_autoconfig(True)
editor = os.getenv('EDITOR')
terminal = os.getenv('TERMINAL')
filemanager = os.getenv('FILE')
# Colors (I only use 3 colors)
background = "#111111"
transparent = "rgba(17, 17, 17, 0.8)"
foreground = "white"
accent = "#ee2222"
# Keybindings
#-----------------------------------------------------------------#
# unbind some stupid bindings (comments are the default)
config.unbind('q') #macro
config.unbind('sf') #something stupid
config.unbind('sl') #set temp
config.unbind('sk') #bind
config.unbind('ss') #set
config.unbind('co') #close all exept the focused tab
config.unbind('cd') #clear download
config.unbind('B') #view quickmarks
config.unbind('ad') #show downloads
config.unbind('') #passtrough
config.unbind('gb') #back
config.unbind('gB') #forwards
config.unbind('wB') #don't remember
# qute-pass binding
config.bind('za', 'spawn --userscript qute-pass')
config.bind('zz', 'spawn --userscript qute-pass --unfiltered -d dmenu')
config.bind('zu', 'spawn --userscript qute-pass --username-only')
config.bind('zp', 'spawn --userscript qute-pass --password-only')
config.bind('zo', 'spawn --userscript qute-pass --otp-only')
# General binding
config.bind(';xa', 'hint all delete')
config.bind(';xi', 'hint inputs delete')
config.bind(';m', 'hint links spawn --detach mpv {hint-url}')
config.bind(';M', 'hint all spawn --detach mpv {hint-url}')
config.bind(';H', 'hint links spawn --detach dhandler {hint-url}')
config.bind('', 'config-cycle -t hints.mode number letter', mode='hint')
config.bind('', 'spawn --detach mpv {url}')
config.bind('', 'leave-mode', mode='passthrough')
config.bind('q', 'set-cmd-text -s :quickmark-load')
config.bind('Q', 'set-cmd-text -s :quickmark-load -t')
config.bind('wq', 'set-cmd-text -s :quickmark-load -w')
config.bind('b', 'set-cmd-text -s :bookmark-load')
config.bind('B', 'set-cmd-text -s :bookmark-load -t')
config.bind('wb', 'set-cmd-text -s :bookmark-load -w')
config.bind('e', 'edit-url')
config.bind('E', 'edit-url -t')
config.bind('', 'edit-text')
config.bind('', 'edit-command', mode='command')
config.bind('s', 'set-cmd-text -s :tab-select')
#config.bind('S', 'set -u *://{url:host}/* content.javascript.enabled true;; reload')
#config.bind('s', 'set -u *://{url:host}/* content.javascript.enabled true;; reload')
#config.bind('S', 'set -u *://{url:host}/* content.javascript.enabled false;; reload')
#config.bind('S', 'set -u *://*.{url:host}/* content.javascript.enabled true;; reload')
config.bind('tb', 'config-cycle -t statusbar.show always never', mode='normal')
config.bind('tB', 'config-cycle -t fonts.default_size 10pt 16pt', mode='normal')
config.bind('tt', 'config-cycle -t tabs.show switching multiple')
config.bind('f', 'hint all')
config.bind('F', 'hint all tab')
config.bind(';f', 'hint links')
config.bind(';F', 'hint links tab')
config.bind('wf', 'hint all window')
# Make half-page not require ctrl (tab-close has also a default of )
config.unbind('d')
config.unbind('u')
config.bind('d', 'scroll-page 0 0.5')
config.bind('u', 'scroll-page 0 -0.5')
config.bind('U', 'undo')
config.unbind('xo')
config.unbind('xO')
config.bind('x', 'tab-close')
#-----------------------------------------------------------------#
c.editor.command = [terminal, "-e", editor, "{file}", "-c", "normal {line}G{column0}l"]
# Use nnn for file selection
c.fileselect.handler = 'external'
c.fileselect.multiple_files.command = [terminal, "-e", filemanager, "-p", "{}"]
c.fileselect.single_file.command = [terminal, "-e", filemanager, "-p", "{}"]
# Minimize fingerprinting / tracking
#c.content.host_blocking.lists = [
# 'https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters-2020.txt',
# 'https://easylist.to/easylist/easylist.txt',
# 'https://easylist.to/easylist/easyprivacy.txt',
# 'https://secure.fanboy.co.nz/fanboy-annoyance.txt',
# '/home/ait/.config/qutebrowser/blocklist'
#]
#c.content.headers.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
c.content.canvas_reading = False
c.content.prefers_reduced_motion = True
c.content.private_browsing = True
c.content.geolocation = False
c.content.notifications.enabled = False
c.content.cookies.accept = 'no-3rdparty'
# - smart: Search case-sensitively if there are capital characters.
c.search.ignore_case = 'smart'
# the zoom default
c.zoom.default = '90'
# Tabs option
c.tabs.position = 'top'
c.tabs.favicons.scale = 1
c.tabs.padding = {"bottom": 0, "left": 5, "right": 5, "top": 0}
c.fonts.tabs.selected = '8px default_family'
c.fonts.tabs.unselected = '8px default_family'
c.tabs.indicator.width = 0
#c.tabs.tabs_are_windows = True
c.tabs.last_close = 'close'
c.tabs.show = 'multiple' # switching,multiple,never
c.tabs.title.alignment = 'left'
c.tabs.title.format = '{current_title}'
c.tabs.max_width = -1
# Statusbar
c.statusbar.show = 'never' # in-mode, never, always
c.statusbar.padding = {"bottom": 5, "left": 5, "right": 5, "top": 5}
# Completion settings
c.completion.show = 'always'
c.completion.height = '25%'
c.completion.scrollbar.width = 0
c.completion.shrink = True
c.completion.use_best_match = True
c.completion.open_categories = ["history", "searchengines", "filesystem"]
# Download settings
c.downloads.remove_finished = 1000
# Browser settings
c.content.javascript.enabled = False
c.content.javascript.alert = False
c.content.javascript.can_access_clipboard = False
c.content.javascript.can_open_tabs_automatically = False
c.content.fullscreen.window = True
c.colors.webpage.preferred_color_scheme = "dark"
c.scrolling.smooth = True
#c.content.user_stylesheets = '~/.config/qutebrowser/lol.css'
c.url.default_page = "https://ait.place"
c.url.start_pages = "https://ait.place"
#c.url.default_page = "https://start.duckduckgo.com/?kak=-1&kal=-1&kao=-1&kaq=-1&kae=d&k7=111&kj=111&kw=n&km=m"
#c.url.start_pages = "https://start.duckduckgo.com/?kak=-1&kal=-1&kao=-1&kaq=-1&kae=d&k7=111&kj=111&kw=n&km=m"
# Set the spellchecking
c.spellcheck.languages = ["en-GB", "nb-NO"]
# Setting dark mode
config.set("colors.webpage.darkmode.enabled", True)
c.colors.webpage.darkmode.enabled = True
c.colors.webpage.bg = background
c.colors.webpage.darkmode.threshold.background = 100
c.colors.webpage.darkmode.threshold.text = 230
#timeouts
c.messages.timeout = 500
# Hints
#c.hints.mode = 'number' # You can search for strings
c.hints.auto_follow_timeout = 1000
#c.hints.chars = "AaSsDdFfGgHhJjKkLlQqWwEeRrTtYyUuIiOoPp{[}]|\ZzXxCcVvBbNnMm<,>.?/!123$4%5^6&7*8(9)0_-+=@~#:;"
#c.hints.chars = "asdfghjklqwertyuiop[]\zxcvbnm,./1234567890-=#;"
#c.hints.chars = "abcdefghijklmnopqrstuvwxyz"
c.hints.chars = "asdfjkl;"
c.hints.padding = {"bottom": 2, "left": 2, "right": 2, "top": 2}
c.hints.border = "2px solid rgba(238, 34, 34, 0.5)"
#c.hints.border = "2px solid " + accent
# c.colors.hints.bg = background
c.colors.hints.bg = 'rgba(17, 17, 17, 0.5)'
c.colors.hints.fg = foreground
# Colors
c.colors.statusbar.normal.bg = background
c.colors.statusbar.private.bg = background
c.colors.statusbar.command.bg = background
c.colors.statusbar.command.private.bg = background
c.colors.tabs.selected.odd.bg = accent
c.colors.tabs.selected.even.bg = accent
c.colors.tabs.odd.bg = background
c.colors.tabs.even.bg = background
c.colors.tabs.bar.bg = background
c.colors.messages.info.bg = background
c.colors.messages.error.bg = accent
c.colors.prompts.bg = background
c.colors.prompts.selected.fg = foreground
c.colors.completion.item.selected.bg = accent
c.colors.completion.item.selected.border.bottom = accent
c.colors.completion.item.selected.border.top = accent
c.colors.completion.item.selected.fg = foreground
c.colors.completion.item.selected.match.fg = background
c.colors.completion.odd.bg = background
c.colors.completion.even.bg = background
c.colors.completion.category.border.bottom = accent
c.colors.completion.category.border.top = accent
c.colors.completion.category.bg = accent
c.colors.downloads.bar.bg = background
c.colors.downloads.start.bg = background
c.colors.downloads.stop.bg = background
c.colors.downloads.error.bg = accent
c.colors.downloads.system.bg = "none"
c.colors.downloads.system.fg = "none"
c.colors.hints.match.fg = accent
c.colors.contextmenu.menu.bg = background
c.colors.contextmenu.selected.bg = accent
c.url.searchengines = {
"DEFAULT": "https://search.brave.com/search?q={}",
#"DEFAULT": "https://duckduckgo.com/?q={}",
#"DEFAULT": "https://search.snopyta.org/?q={}",
#"DEFAULT": "https://www.startpage.com/do/dsearch?query={}",
#"s": "https://www.startpage.com/do/dsearch?query={}",
"aw": "https://wiki.archlinux.org/?search={}",
"gw": "https://wiki.gentoo.org/?search={}",
"y": "http://www.youtube.com/results?search_query={}",
"r": "https://www.reddit.com/r/{}",
"g": "https://encrypted.google.com/search?q={}",
"gg": "https://www.google.co.uk/search?&q={}",
"ggi": "https://www.google.co.uk/search?q={}&tbm=isch",
"w": "https://en.wikipedia.org/w/index.php?search={}",
"st": "http://store.steampowered.com/search/?term={}",
"mw": "http://en.uesp.net/w/index.php?title=Special%3ASearch&search={}",
"aur": "https://aur.archlinux.org/packages/?O=0&K={}",
"pac": "https://www.archlinux.org/packages/?sort=&arch=x86_64&maintainer=&flagged=&q={}",
#"nh": "https://nethackwiki.com/wiki/index.php?search={}",
"i": "http://www.imdb.com/find?ref_=nv_sr_fn&s=all&q={}",
"dic": "https://en.wiktionary.org/wiki/{}",
"ety": "http://www.etymonline.com/index.php?allowed_in_frame=0&search={}",
"u": "http://www.urbandictionary.com/define.php?term={}",
"y": "https://www.youtube.com/results?search_query={}",
"it": "https://itch.io/search?q={}",
"tpb": "https://www.magnetdl.com/search/?m=1&q={}",
"p": "https://www.protondb.com/search?q={}",
"x": "https://search.snopyta.org/?q={}",
"gt": "https://translate.google.com/#view=home&op=translate&sl=auto&tl=en&text={}",
"trig": "https://trigedasleng.net/search?q={}",
"rt": "https://www.rottentomatoes.com/search?search={}",
}
urlsubs = {
"twitter.com": "nitter.eu",
"www.twitter.com": "www.nitter.eu",
"mobile.twitter.com": "nitter.eu",
#"www.reddit.com": "old.reddit.com",
#"reddit.com": "old.reddit.com",
#"youtube.com": "vid.puffyan.us",
"instagram.com": "bibliogram.art",
"www.instagram.com": "www.bibliogram.art",
"i.imgur.com": "i.actionsack.com",
}
def rewrite(request: qutebrowser.api.interceptor.Request):
url = request.request_url.host()
if url in urlsubs:
request.request_url.setHost(urlsubs.get(url))
try:
request.redirect(request.request_url)
except:
pass
qutebrowser.api.interceptor.register(rewrite)