From 2c2d5b9ce9b37754b1c645b60ac2ad2402224a22 Mon Sep 17 00:00:00 2001 From: Phantop Date: Fri, 28 Jun 2024 23:08:14 -0400 Subject: [PATCH] qute: clean miniflux greasemonkey + heading anchors --- bin/aliases | 1 + .../{minifocs.js => enclosures.js} | 3 +- qutebrowser/greasemonkey/headings.js | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) rename qutebrowser/greasemonkey/{minifocs.js => enclosures.js} (62%) create mode 100644 qutebrowser/greasemonkey/headings.js diff --git a/bin/aliases b/bin/aliases index a01e0d4..ca4a41b 100755 --- a/bin/aliases +++ b/bin/aliases @@ -51,6 +51,7 @@ a qutainer 'qutebrowser --temp-basedir' a re 'systemctl reboot -i' a rmdirs 'ff -t d -x rmdir -p' a rmlinks 'ff -t l -x rm' +a rssb 'curl rss-bridge.github.io/rss-bridge/General/Public_Hosts | pup text{} | grep https | shuf -n1 | clip' a s 'doas env "PATH=$PATH"' a sre 'systemctl soft-reboot' a ssh 'kitty +kitten ssh' diff --git a/qutebrowser/greasemonkey/minifocs.js b/qutebrowser/greasemonkey/enclosures.js similarity index 62% rename from qutebrowser/greasemonkey/minifocs.js rename to qutebrowser/greasemonkey/enclosures.js index 3319cdb..0aacd4b 100644 --- a/qutebrowser/greasemonkey/minifocs.js +++ b/qutebrowser/greasemonkey/enclosures.js @@ -1,6 +1,7 @@ // ==UserScript== // @name EnclosureExpand -// @include https://minifocs.fly.dev/* +// @include https://minifocs.fly.dev/*/entry/* +// @include https://minifocs.fly.dev/share/* // ==/UserScript== const details = document.querySelector("details.entry-enclosures"); details.setAttribute("open", ""); diff --git a/qutebrowser/greasemonkey/headings.js b/qutebrowser/greasemonkey/headings.js new file mode 100644 index 0000000..793f83a --- /dev/null +++ b/qutebrowser/greasemonkey/headings.js @@ -0,0 +1,30 @@ +// ==UserScript== +// @name AnchorHeadings +// @include https://minifocs.fly.dev/*/entry/* +// @include https://minifocs.fly.dev/share/* +// ==/UserScript== +var tagNames = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']; +var tagSelector = tagNames.join(); +var $elements = document.querySelectorAll(tagSelector); + +for ($element of $elements) { + var id = $element.id; + + if (!id) { + // Check if heading has any nested elements with id + var $innerElement = $element.querySelector('[id]'); + if ($innerElement) { id = $innerElement.id; } + else { continue; } + } + + // Create anchor if not already present + if (!$element.querySelector('[href]')) + $element.appendChild(createAnchor(id)); +} + +function createAnchor(id) { + var $link = document.createElement('a'); + $link.href = '#' + id; + $link.appendChild(document.createTextNode('♯')); + return $link; +}