feat(desktop): add more config options for qutebrowser.
This commit is contained in:
parent
e83d05f265
commit
6a169af344
5 changed files with 219 additions and 77 deletions
|
@ -0,0 +1,16 @@
|
|||
// ==UserScript==
|
||||
// @name DarkMode Disable
|
||||
// @match https://monkeytype.com/*
|
||||
// @match https://nc.cronyakatsuki.xyz/*
|
||||
// @match https://company-mode.github.io/*
|
||||
// @match https://adventofcode.com/*
|
||||
// @match https://cronyakatsuki.xyz/qbt/*
|
||||
// @match https://www.keybr.com/*
|
||||
// @match https://192.168.100:8006/*
|
||||
// @match https://proxmox.me:8006/*
|
||||
// ==/UserScript==
|
||||
|
||||
const meta = document.createElement("meta");
|
||||
meta.name = "color-scheme";
|
||||
meta.content = "dark light";
|
||||
document.head.appendChild(meta);
|
|
@ -0,0 +1,83 @@
|
|||
// ==UserScript==
|
||||
// @name Adds scrolling JS that can be used within QB to do smarter scrolling
|
||||
// @qute-js-world jseval
|
||||
// @run-at document-start
|
||||
// ==/UserScript==
|
||||
unsafeWindow.scrollHelper = (() => {
|
||||
const scrollableElemOverflowTypes = [
|
||||
'auto',
|
||||
'scroll',
|
||||
]
|
||||
|
||||
const getFocusedWindow = (nextElem) => {
|
||||
if (nextElem === null) return null
|
||||
if (nextElem === undefined) return getFocusedWindow(window.document.activeElement ?? null)
|
||||
return getFocusedWindow(nextElem.contentDocument?.activeElement ?? null) ?? nextElem.ownerDocument?.defaultView ?? null
|
||||
}
|
||||
|
||||
const getScrollMaxY = ({ document: { documentElement } }) => documentElement.scrollHeight - documentElement.clientHeight
|
||||
|
||||
const getWindowVisibleArea = ({ document: { documentElement } }) => documentElement.clientHeight * documentElement.clientWidth
|
||||
|
||||
const findVertScrollableWindow = () => {
|
||||
const focusedWindow = getFocusedWindow() ?? window
|
||||
if (getScrollMaxY(focusedWindow) > 0) return focusedWindow
|
||||
if (getScrollMaxY(window) > 0) return window
|
||||
|
||||
return Array
|
||||
.from(window.frames)
|
||||
.sort((x, y) => getWindowVisibleArea(y) - getWindowVisibleArea(x))
|
||||
.find((frame) => getScrollMaxY(frame) > 0) ?? window
|
||||
}
|
||||
|
||||
const getScrollTopMax = (elem) => elem.scrollHeight - elem.clientHeight
|
||||
const isElementVertScrollable = (element) => element.clientHeight !==0 &&
|
||||
scrollableElemOverflowTypes.includes(getComputedStyle(element).overflowY)
|
||||
|
||||
const findVertScrollableAncestor = (delta, nextElem) => {
|
||||
if (!(nextElem?.parentNode instanceof Element)) return nextElem
|
||||
|
||||
if (isElementVertScrollable(nextElem)) {
|
||||
if (delta < 0 && nextElem.scrollTop > 0) return nextElem
|
||||
if (delta > 0 && nextElem.scrollTop < getScrollTopMax(nextElem)) return nextElem
|
||||
if (delta === 0 && getScrollTopMax(nextElem) > 0) return nextElem
|
||||
}
|
||||
|
||||
return findVertScrollableAncestor(delta, nextElem.parentNode)
|
||||
}
|
||||
|
||||
const getSelectionElem = () => {
|
||||
const selection = getFocusedWindow().getSelection()
|
||||
return selection.rangeCount !== 0
|
||||
? selection.getRangeAt(0).startContainer
|
||||
: null
|
||||
}
|
||||
|
||||
const getParentIfNotElement = (maybeElement) => maybeElement instanceof Element ? maybeElement : maybeElement?.parentNode
|
||||
|
||||
const findVertScrollable = (delta = 0) => {
|
||||
const selectionScrollableElem = findVertScrollableAncestor(delta, getParentIfNotElement(getSelectionElem()))
|
||||
if (selectionScrollableElem instanceof Element) return selectionScrollableElem
|
||||
|
||||
const scrollableDoc = findVertScrollableWindow().document
|
||||
const scrollableElem = scrollableDoc.body || scrollableDoc.getElementsByTagName('body')[0] || scrollableDoc.documentElement
|
||||
return findVertScrollableAncestor(delta, getParentIfNotElement(scrollableElem))
|
||||
}
|
||||
|
||||
return {
|
||||
scrollTo: (position) => findVertScrollable().scrollTo({top: position}),
|
||||
scrollToPercent: (percentPosition) => {
|
||||
const scrollElement = findVertScrollable()
|
||||
const paneHeight = scrollElement.scrollHeight
|
||||
scrollElement.scrollTo({top: percentPosition / 100 * paneHeight})
|
||||
},
|
||||
scrollBy: (delta) => findVertScrollable(delta).scrollBy({top: delta, behavior: 'smooth'}),
|
||||
scrollPage: (pages) => {
|
||||
const fakeDelta = pages < 0 ? -10 : 10
|
||||
const scrollElement = findVertScrollable(fakeDelta)
|
||||
const pageHeight = scrollElement.clientHeight
|
||||
scrollElement.scrollBy({top: pageHeight * pages})
|
||||
},
|
||||
}
|
||||
|
||||
})()
|
|
@ -0,0 +1,33 @@
|
|||
import operator
|
||||
|
||||
from qutebrowser.api import interceptor, message
|
||||
|
||||
REDIRECT_MAP = {
|
||||
"reddit.com": operator.methodcaller("setHost", "libreddit.cronyakatsuki.xyz"),
|
||||
"old.reddit.com": operator.methodcaller("setHost", "libreddit.cronyakatsuki.xyz"),
|
||||
"www.reddit.com": operator.methodcaller("setHost", "libreddit.cronyakatsuki.xyz"),
|
||||
"twitter.com": operator.methodcaller("setHost", "nitter.cronyakatsuki.xyz"),
|
||||
"www.twitter.com": operator.methodcaller("setHost", "nitter.cronyakatsuki.xyz"),
|
||||
"music.youtube.com": operator.methodcaller(
|
||||
"setHost", "hyperpipe.cronyakatsuki.xyz"
|
||||
),
|
||||
"twitch.tv": operator.methodcaller("setHost", "safetwitch.cronyakatsuki.xyz"),
|
||||
"www.twitch.tv": operator.methodcaller("setHost", "safetwitch.cronyakatsuki.xyz"),
|
||||
"tiktok.com": operator.methodcaller("setHost", "proxytok.cronyakatsuki.xyz"),
|
||||
"www.tiktok.com": operator.methodcaller("setHost", "proxytok.cronyakatsuki.xyz"),
|
||||
"imgur.com": operator.methodcaller("setHost", "rimgo.cronyakatsuki.xyz"),
|
||||
"www.imgur.com": operator.methodcaller("setHost", "rimgo.cronyakatsuki.xyz"),
|
||||
"github.com": operator.methodcaller("setHost", "gh.cronyakatsuki.xyz"),
|
||||
"gist.github.com": operator.methodcaller("setHost", "gh.cronyakatsuki.xyz/gist"),
|
||||
}
|
||||
|
||||
|
||||
def int_fn(info: interceptor.Request):
|
||||
url = info.request_url
|
||||
redir = REDIRECT_MAP.get(url.host())
|
||||
if redir is not None and redir(url) is not False:
|
||||
message.info("Redirecting to " + url.toString())
|
||||
info.redirect(url)
|
||||
|
||||
|
||||
interceptor.register(int_fn)
|
74
modules/linux/home-manager/configs/qutebrowser/userscripts/buku
Executable file
74
modules/linux/home-manager/configs/qutebrowser/userscripts/buku
Executable file
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Qutebrowser userscript for interacting with buku
|
||||
# requries buku and dmenu (with list patch)
|
||||
|
||||
get_bookmark() {
|
||||
buku --nostdin -p -f5 | sed 's/\t/;/g' | column -t -s ';' | tofi --horizontal false --height 380 --prompt-text "$1 bookmark: " | awk '{ print $1 }'
|
||||
}
|
||||
|
||||
get_url() {
|
||||
buku --nostdin -p "$1" -f10
|
||||
}
|
||||
|
||||
get_title() {
|
||||
buku --nostdin -p "$1" -f30
|
||||
}
|
||||
|
||||
fifo() {
|
||||
printf '%s\n' "$1" >>"$QUTE_FIFO"
|
||||
}
|
||||
|
||||
add() {
|
||||
buku --nostdin -a "$QUTE_URL"
|
||||
$TERMINAL --class badd,badd -e buku -w -1
|
||||
fifo "message-info 'Added current url to buku'"
|
||||
}
|
||||
|
||||
open() {
|
||||
bookmark=$(get_bookmark "Open")
|
||||
[ -z "$bookmark" ] && fifo "message-info 'No Bookmark selected!!!'" && exit
|
||||
if [ "$1" == "-t" ]; then
|
||||
fifo "open -t $(get_url "$bookmark")"
|
||||
fifo "message-info 'Opening bookmark $(get_title "$bookmark") in new tab.'"
|
||||
else
|
||||
fifo "open $(get_url "$bookmark")"
|
||||
fifo "message-info 'Opening bookmark $(get_title "$bookmark").'"
|
||||
fi
|
||||
}
|
||||
|
||||
delete() {
|
||||
bookmark=$(get_bookmark "Delete")
|
||||
title=$(get_title "$bookmark")
|
||||
buku --nostdin -d "$bookmark" --tacit
|
||||
fifo "message-info 'Deleted bookmark $title.'"
|
||||
}
|
||||
|
||||
edit() {
|
||||
bookmark=$(get_bookmark "Edit")
|
||||
fifo "message-info 'Editing bookmark $(get_title "$bookmark")'"
|
||||
$TERMINAL --class badd,badd -e buku -w "$bookmark"
|
||||
}
|
||||
|
||||
main() {
|
||||
case "$1" in
|
||||
"add")
|
||||
[ -n "$2" ] && QUTE_URL=$2
|
||||
add
|
||||
exit
|
||||
;;
|
||||
"open")
|
||||
open "$2"
|
||||
exit
|
||||
;;
|
||||
"delete")
|
||||
delete
|
||||
exit
|
||||
;;
|
||||
"edit")
|
||||
edit
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main $@
|
|
@ -9,83 +9,16 @@
|
|||
|
||||
config = lib.mkIf config.crony.qutebrowser.enable {
|
||||
home.file = {
|
||||
".config/qutebrowser/userscripts/buku" = {
|
||||
text = ''
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Qutebrowser userscript for interacting with buku
|
||||
# requries buku and dmenu (with list patch)
|
||||
|
||||
get_bookmark() {
|
||||
buku --nostdin -p -f5 | sed 's/\t/;/g' | column -t -s ';' | tofi --horizontal false --height 380 --prompt-text "$1 bookmark: " | awk '{ print $1 }'
|
||||
}
|
||||
|
||||
get_url() {
|
||||
buku --nostdin -p "$1" -f10
|
||||
}
|
||||
|
||||
get_title() {
|
||||
buku --nostdin -p "$1" -f30
|
||||
}
|
||||
|
||||
fifo() {
|
||||
printf '%s\n' "$1" >>"$QUTE_FIFO"
|
||||
}
|
||||
|
||||
add() {
|
||||
buku --nostdin -a "$QUTE_URL"
|
||||
$TERMINAL --class badd,badd -e buku -w -1
|
||||
fifo "message-info 'Added current url to buku'"
|
||||
}
|
||||
|
||||
open() {
|
||||
bookmark=$(get_bookmark "Open")
|
||||
[ -z "$bookmark" ] && fifo "message-info 'No Bookmark selected!!!'" && exit
|
||||
if [ "$1" == "-t" ]; then
|
||||
fifo "open -t $(get_url "$bookmark")"
|
||||
fifo "message-info 'Opening bookmark $(get_title "$bookmark") in new tab.'"
|
||||
else
|
||||
fifo "open $(get_url "$bookmark")"
|
||||
fifo "message-info 'Opening bookmark $(get_title "$bookmark").'"
|
||||
fi
|
||||
}
|
||||
|
||||
delete() {
|
||||
bookmark=$(get_bookmark "Delete")
|
||||
title=$(get_title "$bookmark")
|
||||
buku --nostdin -d "$bookmark" --tacit
|
||||
fifo "message-info 'Deleted bookmark $title.'"
|
||||
}
|
||||
|
||||
edit() {
|
||||
bookmark=$(get_bookmark "Edit")
|
||||
fifo "message-info 'Editing bookmark $(get_title "$bookmark")'"
|
||||
$TERMINAL --class badd,badd -e buku -w "$bookmark"
|
||||
}
|
||||
|
||||
main() {
|
||||
case "$1" in
|
||||
"add")
|
||||
[ -n "$2" ] && QUTE_URL=$2
|
||||
add
|
||||
exit
|
||||
;;
|
||||
"open")
|
||||
open "$2"
|
||||
exit
|
||||
;;
|
||||
"delete")
|
||||
delete
|
||||
exit
|
||||
;;
|
||||
"edit")
|
||||
edit
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main $@
|
||||
'';
|
||||
".config/qutebrowser/userscripts" = {
|
||||
source = ./configs/qutebrowser/userscripts;
|
||||
executable = true;
|
||||
};
|
||||
".config/qutebrowser/pyconfig" = {
|
||||
source = ./configs/qutebrowser/pyconfig;
|
||||
executable = true;
|
||||
};
|
||||
".config/qutebrowser/greasemonkey" = {
|
||||
source = ./configs/qutebrowser/greasemonkey;
|
||||
executable = true;
|
||||
};
|
||||
};
|
||||
|
@ -93,6 +26,9 @@
|
|||
programs.qutebrowser = {
|
||||
enable = true;
|
||||
loadAutoconfig = true;
|
||||
extraConfig = ''
|
||||
config.source("pyconfig/redirectors.py")
|
||||
'';
|
||||
searchEngines = {
|
||||
DEFAULT = "https://searx.cronyakatsuki.xyz/?q={}";
|
||||
aw = "https://wiki.archlinux.org/?search={}";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue