Initial commit.

This commit is contained in:
CronyAkatsuki 2024-06-20 17:26:20 +02:00
commit fb9d04b7ef
28 changed files with 2359 additions and 0 deletions

View file

@ -0,0 +1,190 @@
import catppuccin
# pylint: disable=C0111
from qutebrowser.config.configfiles import ConfigAPI # noqa: F401
from qutebrowser.config.config import ConfigContainer # noqa: F401
# fmt: off
config: ConfigAPI = config # type: ConfigAPI # noqa: F821 pylint: disable=E0602,C0103 # pyright: ignore
c: ConfigContainer = c # type: ConfigContainer # noqa: F821 pylint: disable=E0602,C0103 # pyright: ignore
# fmt: on
# load autoconfig values
config.load_autoconfig()
# load catppuccin theme
catppuccin.setup(c, "Machiatto", True)
# load custom configs
config.source("pyconfig/redirectors.py")
##-- Dark Mode Settings --##
c.colors.webpage.preferred_color_scheme = "dark"
c.colors.webpage.darkmode.enabled = True
c.colors.webpage.bg = "black"
c.colors.webpage.darkmode.algorithm = "lightness-cielab"
c.colors.webpage.darkmode.threshold.foreground = 150
c.colors.webpage.darkmode.threshold.background = 100
c.colors.webpage.darkmode.policy.images = "never"
# c.colors.webpage.darkmode.grayscale.images = 0.35
# change startpage and default page
c.url.start_pages = ["https://startpage.cronyakatsuki.xyz"]
c.url.default_page = "https://startpage.cronyakatsuki.xyz"
# search engines
c.url.searchengines = {
"DEFAULT": "https://searx.cronyakatsuki.xyz/?q={}",
"aw": "https://wiki.archlinux.org/?search={}",
"re": "https://www.reddit.com/r/{}",
"w": "https://en.wikipedia.org/wiki/{}",
"y": "https://www.youtube.com/results?search_query={}",
}
##-- Fingerprinting settings --##
c.content.headers.user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.3"
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"
}
c.content.canvas_reading = False
c.content.webgl = False
c.content.webrtc_ip_handling_policy = "default-public-interface-only"
c.content.geolocation = False
c.content.javascript.enabled = False
c.content.notifications.enabled = False
c.content.cookies.accept = "never"
c.content.private_browsing = False
##-- AdBLock Settings --##
c.content.blocking.method = "both"
c.content.blocking.adblock.lists = [
"https://easylist.to/easylist/easylist.txt",
"https://easylist.to/easylist/easyprivacy.txt",
"https://secure.fanboy.co.nz/fanboy-annoyance.txt",
"https://easylist-downloads.adblockplus.org/abp-filters-anti-cv.txt",
"https://www.i-dont-care-about-cookies.eu/abp/",
]
# History disable
c.completion.web_history.max_items = 0
c.completion.cmd_history_max_items = 0
##-- Devtool Settings --##
with config.pattern("chrome-devtools://*") as s:
s.content.cookies.accept = "all"
s.content.images = True
s.content.javascript.enabled = True
with config.pattern("devtools://*") as s:
s.content.cookies.accept = "all"
s.content.images = True
s.content.javascript.enabled = True
with config.pattern("chrome://*/*") as s:
s.content.javascript.enabled = True
with config.pattern("qute://*/*") as s:
s.content.javascript.enabled = True
##-- Site settings --##
with config.pattern("https://searx.cronyakatsuki.xyz/*") as s:
s.content.cookies.accept = "all"
with config.pattern("https://monkeytype.com") as s:
s.content.javascript.enabled = True
s.content.cookies.accept = "all"
with config.pattern("https://piped.cronyakatsuki.xyz/*") as s:
s.content.javascript.enabled = True
s.content.cookies.accept = "all"
##-- Aliases --##
c.aliases = config.get("aliases")
c.aliases["buku"] = "spawn --userscript buku"
##-- Bindings --##
# launch with mpv
config.bind(",m", "spawn mpv {url}")
config.bind(",fm", "hint links spawn mpv {hint-url}")
# buku bundings
config.bind("b", "buku open")
config.bind("B", "buku open -t")
config.bind(",ba", "buku add")
config.bind(",be", "buku edit")
config.bind(",bd", "buku delete")
config.bind(",bfa", "hint links spawn --userscript buku add {hint-url}")
# yt-dlp
config.bind(",y", "spawn --userscript yt-dlp")
config.bind(",fy", "hint links userscript yt-dlp")
# search current selection
config.bind(",fo", "open {primary}")
config.bind(",fO", "open --tab {primary}")
# yank found url
config.bind("yf", "hint links yank")
# fix escape
config.bind(
"<Escape>", "mode-leave ;; jseval -q document.activeElement.blur()", mode="insert"
)
# fix scrolling
config.bind("j", "jseval --quiet scrollHelper.scrollBy(50)")
config.bind("k", "jseval --quiet scrollHelper.scrollBy(-50)")
config.bind("<Ctrl-D>", "jseval --quiet scrollHelper.scrollPage(0.8)")
config.bind("<Ctrl-U>", "jseval --quiet scrollHelper.scrollPage(-0.8)")
config.bind("gg", "jseval --quiet scrollHelper.scrollTo(0)")
config.bind("G", "jseval --quiet scrollHelper.scrollToPercent(100)")
# KeePassXC binding
config.bind('pw', 'spawn --userscript qute-keepassxc --key crony@cronyakatsuki.xyz')
# remove clickbard and gdpr banners
config.bind(
"ek",
"jseval (function () { "
+ ' var i, elements = document.querySelectorAll("body *");'
+ ""
+ " for (i = 0; i < elements.length; i++) {"
+ " var pos = getComputedStyle(elements[i]).position;"
+ ' if (pos === "fixed" || pos == "sticky") {'
+ " elements[i].parentNode.removeChild(elements[i]);"
+ " }"
+ " }"
+ "})();",
)
##-- Font Settings --##
c.fonts.default_family = '"Dejavu Sans Mono"'
c.fonts.default_size = "10pt"
c.fonts.completion.entry = 'default_size "default_family"'
c.fonts.debug_console = 'default_size "default_family"'
c.fonts.prompts = "default_size default_family"
c.fonts.statusbar = 'default_size "default_family"'
##-- FilePicker (nnn on crrack)--##
fileselect_cmd = [
"alacritty",
"--class",
"filepicker,filepicker",
"-e",
"tmux",
"new",
"-s",
"filepicker",
"env",
"LC_COLLATE=C",
"nnn",
"-P",
"p",
"-p",
"{}",
]
c.fileselect.handler = "external"
c.fileselect.folder.command = fileselect_cmd
c.fileselect.single_file.command = fileselect_cmd
c.fileselect.multiple_files.command = fileselect_cmd

View file

@ -0,0 +1,14 @@
// ==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/*
// ==/UserScript==
const meta = document.createElement("meta");
meta.name = "color-scheme";
meta.content = "dark light";
document.head.appendChild(meta);

View file

@ -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})
},
}
})()

View file

@ -0,0 +1,36 @@
import operator
from qutebrowser.api import interceptor, message
REDIRECT_MAP = {
"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"),
"youtube.com": operator.methodcaller("setHost", "piped.cronyakatsuki.xyz"),
"www.youtube.com": operator.methodcaller("setHost", "piped.cronyakatsuki.xyz"),
"music.youtube.com": operator.methodcaller(
"setHost", "hyperpipe.cronyakatsuki.xyz"
),
"medium.com": operator.methodcaller("setHost", "scribe.cronyakatsuki.xyz"),
"www.medium.com": operator.methodcaller("setHost", "scribe.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)

View 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 ';' | dmenu -p "$1 bookmark: " -i -l 10 | 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 $@