aboutsummaryrefslogtreecommitdiff
path: root/config/qutebrowser/userscripts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-12-21 18:52:51 +0530
committerAkshay Nair <phenax5@gmail.com>2020-12-21 18:52:51 +0530
commitf1cf59ce2df9204f818cfd038538a2a31a5c2262 (patch)
tree35b0a21501615b7551514262b96e9d8113375cbc /config/qutebrowser/userscripts
parent6ff5a17adcf1ed72cd2f1c7bff606bdd3352b3bb (diff)
downloadnixos-config-f1cf59ce2df9204f818cfd038538a2a31a5c2262.tar.gz
nixos-config-f1cf59ce2df9204f818cfd038538a2a31a5c2262.zip
Adds qutebrowser config
Diffstat (limited to '')
-rwxr-xr-xconfig/qutebrowser/userscripts/dl_music16
-rwxr-xr-xconfig/qutebrowser/userscripts/format_json42
-rwxr-xr-xconfig/qutebrowser/userscripts/nodemon11
-rwxr-xr-xconfig/qutebrowser/userscripts/open_downloads4
-rwxr-xr-xconfig/qutebrowser/userscripts/pick_useragent27
-rwxr-xr-xconfig/qutebrowser/userscripts/tor_identity6
-rwxr-xr-xconfig/qutebrowser/userscripts/torrent3
-rwxr-xr-xconfig/qutebrowser/userscripts/yank3
8 files changed, 112 insertions, 0 deletions
diff --git a/config/qutebrowser/userscripts/dl_music b/config/qutebrowser/userscripts/dl_music
new file mode 100755
index 0000000..39e6ac0
--- /dev/null
+++ b/config/qutebrowser/userscripts/dl_music
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+cd ~/Downloads/music/untagged;
+
+~/scripts/notify.sh "Downloading audio in the background...";
+
+youtube-dl \
+ --add-metadata \
+ --ignore-errors \
+ --output '%(title)s.%(ext)s' \
+ --extract-audio \
+ --yes-playlist \
+ "$QUTE_URL";
+
+~/scripts/notify.sh "Download complete";
+
diff --git a/config/qutebrowser/userscripts/format_json b/config/qutebrowser/userscripts/format_json
new file mode 100755
index 0000000..1977078
--- /dev/null
+++ b/config/qutebrowser/userscripts/format_json
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+set -euo pipefail
+#
+# Behavior:
+# Userscript for qutebrowser which will take the raw JSON text of the current
+# page, format it using `jq`, will add syntax highlighting using `pygments`,
+# and open the syntax highlighted pretty printed html in a new tab. If the file
+# is larger than 10MB then this script will only indent the json and will forego
+# syntax highlighting using pygments.
+#
+# In order to use this script, just start it using `spawn --userscript` from
+# qutebrowser. I recommend using an alias, e.g.
+#
+# :config-dict-add aliases json "spawn --userscript /path/to/json_format"
+#
+# Note that the color style defaults to monokai, but a different pygments style
+# can be passed as the first parameter to the script. A full list of the pygments
+# styles can be found at: https://help.farbox.com/pygments.html
+#
+# Bryan Gilbert, 2017
+
+# do not run pygmentize on files larger than this amount of bytes
+MAX_SIZE_PRETTIFY=10485760 # 10 MB
+# default style to monokai if none is provided
+STYLE=${1:-fruity}
+
+TEMP_FILE="$(mktemp --suffix .html)"
+jq . "$QUTE_TEXT" >"$TEMP_FILE"
+
+# try GNU stat first and then OSX stat if the former fails
+FILE_SIZE=$(
+ stat --printf="%s" "$TEMP_FILE" 2>/dev/null ||
+ stat -f%z "$TEMP_FILE" 2>/dev/null
+)
+
+if [ "$FILE_SIZE" -lt "$MAX_SIZE_PRETTIFY" ]; then
+ pygmentize -l json -f html -O full,style="$STYLE" <"$TEMP_FILE" >"${TEMP_FILE}_"
+ mv -f "${TEMP_FILE}_" "$TEMP_FILE"
+fi
+
+# send the command to qutebrowser to open the new file containing the formatted json
+echo "open -t file://$TEMP_FILE" >> "$QUTE_FIFO"
diff --git a/config/qutebrowser/userscripts/nodemon b/config/qutebrowser/userscripts/nodemon
new file mode 100755
index 0000000..99da415
--- /dev/null
+++ b/config/qutebrowser/userscripts/nodemon
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+WATCH_DIR="$1";
+EXTENSIONS="${2:-"js,html,css"}";
+
+nodemon --exec "echo 'reload' >> $QUTE_FIFO" -e $EXTENSIONS -w "$WATCH_DIR" &
+
+~/scripts/notify.sh "[$PID] Watching $WATCH_DIR for $EXTENSIONS...";
+
+disown;
+
diff --git a/config/qutebrowser/userscripts/open_downloads b/config/qutebrowser/userscripts/open_downloads
new file mode 100755
index 0000000..c4098a9
--- /dev/null
+++ b/config/qutebrowser/userscripts/open_downloads
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+
+sensible-terminal -e ~/.bin/with_zsh "lf ${QUTE_DOWNLOAD_DIR:-$HOME/Downloads}";
+
diff --git a/config/qutebrowser/userscripts/pick_useragent b/config/qutebrowser/userscripts/pick_useragent
new file mode 100755
index 0000000..dce67e7
--- /dev/null
+++ b/config/qutebrowser/userscripts/pick_useragent
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+
+trim() { sed '/^$/ d'; }
+
+useragents=`echo "
+Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0
+Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
+Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0
+Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
+
+Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
+Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36
+Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/83.0.4103.61 Chrome/83.0.4103.61 Safari/537.36
+Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Brave Chrome/76.0.3809.132 Safari/537.36
+
+Mozilla/5.0 (Linux; U; Android 2.2) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
+Mozilla/5.0 (Linux; Android 6.0.1; RedMi Note 5 Build/RB3N5C; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3440.91 Mobile Safari/537.36
+Mozilla/5.0 (Linux; Android 7.0; K10000 Max) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Mobile Safari/537.36 Brave/74
+
+" | trim`;
+
+ua=`echo -e "$useragents" | dmenu -p "User-agent ::"`;
+
+[[ -z "$ua" ]] && exit 0;
+
+echo "set content.headers.user_agent '$ua'" >> "$QUTE_FIFO";
+
diff --git a/config/qutebrowser/userscripts/tor_identity b/config/qutebrowser/userscripts/tor_identity
new file mode 100755
index 0000000..bf23014
--- /dev/null
+++ b/config/qutebrowser/userscripts/tor_identity
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+mypass=$(pass show Tor/client);
+
+echo -e "AUTHENTICATE \"$mypass\"\\r\\nsignal NEWNYM\\r\\nQUIT" | nc 127.0.0.1 9051;
+
diff --git a/config/qutebrowser/userscripts/torrent b/config/qutebrowser/userscripts/torrent
new file mode 100755
index 0000000..84b6555
--- /dev/null
+++ b/config/qutebrowser/userscripts/torrent
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+~/scripts/torrent.sh magnet "$QUTE_URL";
diff --git a/config/qutebrowser/userscripts/yank b/config/qutebrowser/userscripts/yank
new file mode 100755
index 0000000..a235041
--- /dev/null
+++ b/config/qutebrowser/userscripts/yank
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+echo "$QUTE_URL" | xclip -selection clipboard -i;