commit ec9eb26848a41de961dbee82d393efb23d8c69cf
parent 83b4115338d629f6e972360e7df240c6e077076e
Author: hhvn <dev@hhvn.uk>
Date: Tue, 19 Apr 2022 12:05:25 +0100
Qutebrowser
Diffstat:
5 files changed, 146 insertions(+), 338 deletions(-)
diff --git a/.config/qutebrowser/config.py b/.config/qutebrowser/config.py
@@ -0,0 +1,139 @@
+from PyQt5.QtCore import QUrl
+from qutebrowser.api import interceptor
+from qutebrowser.browser import commands
+import subprocess
+
+# import <str> can mean import ./<str>.py apparently.
+# Great, transparent, design.
+import search
+import stylesheets
+
+# Qutebrowser requires me to tell it this or else it
+# gives an annoying message each time it opens.
+config.load_autoconfig(False)
+
+# Save tabs + urls
+c.auto_save.session = True
+
+# Didn't ask.
+c.changelog_after_upgrade = 'never'
+
+# Don't annoy me.
+c.new_instance_open_target = 'tab-bg-silent'
+
+# Selected tabs
+c.colors.tabs.selected.even.bg = '#1b364b'
+c.colors.tabs.selected.odd.bg = '#1b364b'
+c.colors.tabs.selected.even.fg = 'white'
+c.colors.tabs.selected.odd.fg = 'white'
+
+# Unselected tabs
+c.colors.tabs.even.bg = '#050a10'
+c.colors.tabs.odd.bg = '#050a10'
+c.colors.tabs.even.fg = 'white'
+c.colors.tabs.odd.fg = 'white'
+
+# Tabbed muscle memory
+config.bind('<Alt-q>', 'tab-close')
+config.bind('<Alt-h>', 'tab-prev')
+config.bind('<Alt-l>', 'tab-next')
+config.bind('<Alt-Shift-h>', 'tab-prev')
+config.bind('<Alt-Shift-l>', 'tab-next')
+
+# Darkmode
+c.colors.webpage.bg = '#050a10'
+c.colors.webpage.darkmode.algorithm = 'lightness-cielab'
+c.colors.webpage.darkmode.enabled = True
+c.colors.webpage.darkmode.policy.images = 'never'
+c.colors.webpage.darkmode.policy.page = 'always'
+c.colors.webpage.preferred_color_scheme = 'dark'
+
+# Configuration
+## cd to qutebrowser dir before editing to get quick access to other files
+c.editor.command = ['rc', '-c', 'cd `$nl{dirname \'{file}\'}; st -e vim `$nl{basename \'{file}\'}']
+config.bind('R', 'config-source')
+config.bind('e', 'config-edit')
+
+# I need to plumb
+config.bind('d', 'hint all spawn plumb {hint-url}')
+config.bind('D', 'hint all spawn rc -c \'net/download -d {hint-url}\'')
+config.bind('v', 'hint all spawn rc -c \'nohup mpv --pause {hint-url} >/dev/null >[2]/dev/null &\'')
+
+# Warp the mouse as seen by qtwebengine
+config.bind('a', 'hint all hover')
+
+# Alphabet soup
+config.bind('A', 'spawn --userscript randomagent')
+c.content.headers.user_agent = '.'
+
+# Stylesheets
+c.content.user_stylesheets = stylesheets.list
+
+# Home/default page
+c.url.default_page = 'about:blank'
+config.bind('~', 'open file:///home/hayden/.config/qutebrowser/home.html')
+
+# Hint characters.
+# Same as the default, but with f placed last. It seems that qutebrowser will
+# construct multichar hints by going right to left to select the first char.
+# Since f is the default hint binding I think this will make hints quicker to
+# type as my finger should already be on f when it is generating hints such as
+# 'fa', 'fb', 'fc'...
+c.hints.chars = 'asdlghjkf'
+
+# Search (search.py)
+c.url.open_base_url = True
+c.url.searchengines = search.list
+
+# Security
+## Uh-oh gmail might break with this option! Oh no!
+c.content.cookies.accept = 'no-3rdparty'
+## DNT does nothing but provide a more unique fingerprint
+c.content.headers.do_not_track = None
+## I know, I know, but I don't care.
+c.downloads.prevent_mixed_content = False
+
+# Redirects
+def domainredir(info: interceptor.Request):
+ host = info.request_url.host()
+ target = QUrl(info.request_url)
+
+ # Fuck python. Why can't I split these out on to multiple lines and indent
+ # them? Why can't you give me a switch statement? I would love for
+ # string-capable switch statements to exist in more languages.
+ if (host == 'twitter.com' or host == 'www.twitter.com' or host == 'mobile.twitter.com'):
+ target.setHost('nitter.net');
+ elif (host == 'reddit.com' or host == 'www.reddit.com' or host == 'old.reddit.com'):
+ target.setHost('teddit.net');
+ elif (host == 'instagram.com' or host == 'www.instagram.com'):
+ target.setHost('bibliogram.art');
+ elif (host == 'en.m.wikipedia.org'):
+ target.setHost('en.wikipedia.org');
+ elif (host == 'npr.org' or host == 'www.npr.org'):
+ target.setHost('text.npr.org');
+ else:
+ return
+
+ try:
+ info.redirect(target)
+ except interceptor.interceptors.RedirectException:
+ pass
+interceptor.register(domainredir)
+
+# Clipboard (use primary for everything)
+config.unbind('Pp')
+config.unbind('PP')
+config.unbind('pp')
+config.unbind('pP')
+config.unbind('yD')
+config.unbind('yM')
+config.unbind('yP')
+config.unbind('yT')
+config.unbind('yY')
+config.bind('P', 'open -t -- {primary}')
+config.bind('p', 'open -- {primary}')
+config.bind('yd', 'yank domain -s')
+config.bind('ym', 'yank inline [{title}]({url}) -s')
+config.bind('yp', 'yank pretty-url -s')
+config.bind('yt', 'yank title -s')
+config.bind('yy', 'yank -s')
diff --git a/.config/qutebrowser/userscripts/randomagent b/.config/qutebrowser/userscripts/randomagent
@@ -0,0 +1,6 @@
+#!/bin/rc
+
+chars = `$nl{head -c 200 /dev/urandom | od -Ad | tr ' ' '\n' | awk -vmin=20 -vmax=40 '{i += $1}; END {print (i % min) + (max - min)}'}
+agent = `$nl{head -c$chars /dev/urandom | base64 | tr -d '='}
+
+echo ':set content.headers.user_agent ' ^ $agent > $QUTE_FIFO
diff --git a/.config/surf/script.js b/.config/surf/script.js
@@ -1,307 +0,0 @@
-//======> linkhinting.js <======
-/* based on chromium plugin code, adapted by Nibble<.gs@gmail.com> */
-/* modified by hhvn<hayden@haydenvh.com> */
-var hint_num_str = '';
-var hint_elems = [];
-var hint_open_in_new_tab = false;
-var hint_enabled = false;
-function hintMode(newtab){
- hint_enabled = true;
- if (newtab) {
- hint_open_in_new_tab = true;
- } else {
- hint_open_in_new_tab = false;
- }
- setHints();
- document.removeEventListener('keydown', initKeyBind, false);
- document.addEventListener('keydown', hintHandler, false);
- hint_num_str = '';
-}
-function hintHandler(e){
- e.preventDefault(); //Stop Default Event
- var pressedKey = get_key(e);
- if (pressedKey == 'Enter') {
- if (hint_num_str == '')
- hint_num_str = '1';
- judgeHintNum(Number(hint_num_str));
- } else if (/[0-9]/.test(pressedKey) == false) {
- removeHints();
- } else {
- hint_num_str += pressedKey;
- var hint_num = Number(hint_num_str);
- if (hint_num * 10 > hint_elems.length + 1) {
- judgeHintNum(hint_num);
- } else {
- var hint_elem = hint_elems[hint_num - 1];
- if (hint_elem != undefined && hint_elem.tagName.toLowerCase() == 'a') {
- setHighlight(hint_elem, true);
- }
- }
- }
-}
-function setHighlight(elem, is_active) {
- if (is_active) {
- var active_elem = document.body.querySelector('a[highlight=hint_active]');
- if (active_elem != undefined)
- active_elem.setAttribute('highlight', 'hint_elem');
- elem.setAttribute('highlight', 'hint_active');
- } else {
- elem.setAttribute('highlight', 'hint_elem');
- }
-}
-function setHintRules() {
- if (document.styleSheets.length < 1) {
- var style = document.createElement("style");
- style.appendChild(document.createTextNode(""));
- document.head.appendChild(style);
- }
- var ss = document.styleSheets[0];
- ss.insertRule('a[highlight=hint_elem] {background-color: #0c0a1433}', 0);
- ss.insertRule('a[highlight=hint_active] {background-color: #0c0a1433}', 0);
-}
-function deleteHintRules() {
- var ss = document.styleSheets[0];
- ss.deleteRule(0);
- ss.deleteRule(0);
-}
-function judgeHintNum(hint_num) {
- var hint_elem = hint_elems[hint_num - 1];
- if (hint_elem != undefined) {
- execSelect(hint_elem);
- } else {
- removeHints();
- }
-}
-function execSelect(elem) {
- var tag_name = elem.tagName.toLowerCase();
- var type = elem.type ? elem.type.toLowerCase() : "";
- if (tag_name == 'a' && elem.href != '') {
- setHighlight(elem, true);
- // TODO: ajax, <select>
- if (hint_open_in_new_tab)
- window.open(elem.href);
- else location.href=elem.href;
- } else if (tag_name == 'input' && (type == "submit" || type == "button" || type == "reset")) {
- elem.click();
- } else if (tag_name == 'input' && (type == "radio" || type == "checkbox")) {
- // TODO: toggle checkbox
- elem.checked = !elem.checked;
- } else if (tag_name == 'input' || tag_name == 'textarea') {
- elem.focus();
- elem.setSelectionRange(elem.value.length, elem.value.length);
- }
- removeHints();
-}
-function setHints() {
- setHintRules();
- var win_top = window.scrollY;
- var win_bottom = win_top + window.innerHeight;
- var win_left = window.scrollX;
- var win_right = win_left + window.innerWidth;
- // TODO: <area>
- var elems = document.body.querySelectorAll('a, input:not([type=hidden]), textarea, select, button');
- var div = document.createElement('div');
- div.setAttribute('highlight', 'hints');
- document.body.appendChild(div);
- for (var i = 0; i < elems.length; i++) {
- var elem = elems[i];
- if (!isHintDisplay(elem))
- continue;
- var pos = elem.getBoundingClientRect();
- var elem_top = win_top + pos.top;
- var elem_bottom = win_top + pos.bottom;
- var elem_left = win_left + pos.left;
- var elem_right = win_left + pos.left;
- if ( elem_bottom >= win_top && elem_top <= win_bottom) {
- hint_elems.push(elem);
- setHighlight(elem, false);
- var span = document.createElement('span');
- span.style.cssText = [
- 'left: ', elem_left, 'px;',
- 'top: ', elem_top, 'px;',
- 'position: absolute;',
- 'font-size: 13px;',
- 'background-color: ' + (hint_open_in_new_tab ? '#0c0a1499' : '#0c0a1499') + ';',
- 'color: white;',
- 'font-weight: bold;',
- 'padding: 0px 1px;',
- 'z-index: 100000;'
- ].join('');
- span.innerHTML = hint_elems.length;
- div.appendChild(span);
- if (elem.tagName.toLowerCase() == 'a') {
- if (hint_elems.length == 1) {
- setHighlight(elem, true);
- } else {
- setHighlight(elem, false);
- }
- }
- }
- }
-}
-function isHintDisplay(elem) {
- var pos = elem.getBoundingClientRect();
- return (pos.height != 0 && pos.width != 0);
-}
-function removeHints() {
- if (!hint_enabled)
- return;
- hint_enabled = false;
- deleteHintRules();
- for (var i = 0; i < hint_elems.length; i++) {
- hint_elems[i].removeAttribute('highlight');
- }
- hint_elems = [];
- hint_num_str = '';
- var div = document.body.querySelector('div[highlight=hints]');
- if (div != undefined) {
- document.body.removeChild(div);
- }
- document.removeEventListener('keydown', hintHandler, false);
- document.addEventListener('keydown', initKeyBind, false);
-}
-function addKeyBind( key, func, eve ){
- var pressedKey = get_key(eve);
- if( pressedKey == key ){
- eve.preventDefault(); //Stop Default Event
- eval(func);
- }
-}
-document.addEventListener( 'keydown', initKeyBind, false );
-function initKeyBind(e){
- var t = e.target;
- if( t.nodeType == 1){
- addKeyBind( 'C-f', 'hintMode()', e );
- addKeyBind( 'C-F', 'hintMode(true)', e );
- addKeyBind( 'C-c', 'removeHints()', e );
- }
-}
-var keyId = {
- "U+0008" : "BackSpace",
- "U+0009" : "Tab",
- "U+0018" : "Cancel",
- "U+001B" : "Esc",
- "U+0020" : "Space",
- "U+0021" : "!",
- "U+0022" : "\"",
- "U+0023" : "#",
- "U+0024" : "$",
- "U+0026" : "&",
- "U+0027" : "'",
- "U+0028" : "(",
- "U+0029" : ")",
- "U+002A" : "*",
- "U+002B" : "+",
- "U+002C" : ",",
- "U+002D" : "-",
- "U+002E" : ".",
- "U+002F" : "/",
- "U+0030" : "0",
- "U+0031" : "1",
- "U+0032" : "2",
- "U+0033" : "3",
- "U+0034" : "4",
- "U+0035" : "5",
- "U+0036" : "6",
- "U+0037" : "7",
- "U+0038" : "8",
- "U+0039" : "9",
- "U+003A" : ":",
- "U+003B" : ";",
- "U+003C" : "<",
- "U+003D" : "=",
- "U+003E" : ">",
- "U+003F" : "?",
- "U+0040" : "@",
- "U+0041" : "a",
- "U+0042" : "b",
- "U+0043" : "c",
- "U+0044" : "d",
- "U+0045" : "e",
- "U+0046" : "f",
- "U+0047" : "g",
- "U+0048" : "h",
- "U+0049" : "i",
- "U+004A" : "j",
- "U+004B" : "k",
- "U+004C" : "l",
- "U+004D" : "m",
- "U+004E" : "n",
- "U+004F" : "o",
- "U+0050" : "p",
- "U+0051" : "q",
- "U+0052" : "r",
- "U+0053" : "s",
- "U+0054" : "t",
- "U+0055" : "u",
- "U+0056" : "v",
- "U+0057" : "w",
- "U+0058" : "x",
- "U+0059" : "y",
- "U+005A" : "z",
- //"U+005B" : "[",
- //"U+005C" : "\\",
- //"U+005D" : "]",
- "U+00DB" : "[",
- "U+00DC" : "\\",
- "U+00DD" : "]",
- "U+005E" : "^",
- "U+005F" : "_",
- "U+0060" : "`",
- "U+007B" : "{",
- "U+007C" : "|",
- "U+007D" : "}",
- "U+007F" : "Delete",
- "U+00A1" : "¡",
- "U+0300" : "CombGrave",
- "U+0300" : "CombAcute",
- "U+0302" : "CombCircum",
- "U+0303" : "CombTilde",
- "U+0304" : "CombMacron",
- "U+0306" : "CombBreve",
- "U+0307" : "CombDot",
- "U+0308" : "CombDiaer",
- "U+030A" : "CombRing",
- "U+030B" : "CombDblAcute",
- "U+030C" : "CombCaron",
- "U+0327" : "CombCedilla",
- "U+0328" : "CombOgonek",
- "U+0345" : "CombYpogeg",
- "U+20AC" : "€",
- "U+3099" : "CombVoice",
- "U+309A" : "CombSVoice",
-}
-function get_key(evt){
- var key = keyId[evt.keyIdentifier] || evt.keyIdentifier,
- ctrl = evt.ctrlKey ? 'C-' : '',
- meta = (evt.metaKey || evt.altKey) ? 'M-' : '',
- shift = evt.shiftKey ? 'S-' : '';
- if (evt.shiftKey){
- if (/^[a-z]$/.test(key))
- return ctrl+meta+key.toUpperCase();
- if (/^[0-9]$/.test(key)) {
- switch(key) {
- // TODO
- case "4":
- key = "$";
- break;
- };
- return key;
- }
- if (/^(Enter|Space|BackSpace|Tab|Esc|Home|End|Left|Right|Up|Down|PageUp|PageDown|F(\d\d?))$/.test(key))
- return ctrl+meta+shift+key;
- }
- return ctrl+meta+key;
-}
-function guarantee_stylesheet(){
- var thehead = document.getElementsByTagName('head')[0];
- if (document.getElementsByTagName('style').length < 1){
- var thesty = document.createElement('style');
- thesty.innerHTML = thesty.innerHTML + ' div#diag_kludge{color: #0099ff;} ';
- thesty.innerHTML = thesty.innerHTML + ' div#diag_kludge{background-color: #660000;} ';
- thehead.appendChild(thesty);
- divv = document.getElementById('diag_kludge');
- titl = headd.getElementsByTagName('title')[0];
- }
-}
-window.addEventListener('load', guarantee_stylesheet, false);
diff --git a/.config/surf/styles/default.css b/.config/surf/styles/default.css
@@ -1,30 +0,0 @@
-* {
- background-color: #050a10 !important;
- background-image: none !important;
- color: #1e5eb3 !important;
- border-color: #1e5eb3 !important;
-}
-h1,h2,h3,h4 {
- color: #31364b !important;
-}
-a,a>*,button,button>* {
- color: #777b8e !important;
-}
-input,textarea{
- border: 2px solid #1e5eb3 !important;
-}
-
-.c5a, .c5a >*, .c5a a:link, .c5a a:visited { color:#173173 !important; }
-.c73, .c73 >*, .c73 a:link, .c73 a:visited { color:#173173 !important; }
-.c82, .c82 >*, .c82 a:link, .c82 a:visited { color:#173173 !important; }
-.c88, .c88 >*, .c88 a:link, .c88 a:visited { color:#173173 !important; }
-.c9c, .c9c >*, .c9c a:link, .c9c a:visited { color:#173173 !important; }
-.cae, .cae >*, .cae a:link, .cae a:visited { color:#173173 !important; }
-.cbe, .cbe >*, .cbe a:link, .cbe a:visited { color:#173173 !important; }
-.cce, .cce >*, .cce a:link, .cce a:visited { color:#173173 !important; }
-.cdd, .cdd >*, .cdd a:link, .cdd a:visited { color:#173173 !important; }
-
-.highlight, .highlight >*, .highlight >*>*, .highlight >*>*>*, .highlight >*>*>*>*, .highlight >*>*>*>*>* {
- background-color: #0a2126 !important;
- color: #ffffff !important;
-}
diff --git a/.scripts/plumb b/.scripts/plumb
@@ -157,7 +157,7 @@ do
matches "^https?://" ||
matches "\.html?$" ||
fmatches "HTML" &&
- plumb gui 'xprop -id $(cat /tmp/tabbed.xid) >/dev/null && $proxy surf -e $(cat /tmp/tabbed.xid) $arg || { >/tmp/tabbed.xid tabbed -c & $proxy surf -e $(sleep 1 && cat /tmp/tabbed.xid) $arg; }'
+ plumb gui 'qutebrowser $arg'
matches "^gophers?://(.*/[17+0](/|$)|[^/]*$)" &&
plumb terminal '$proxy zygo $arg'