From 72677e6cf90bae52481b143ce3e269bcacf2568a Mon Sep 17 00:00:00 2001 From: Phantop Date: Tue, 3 Oct 2023 13:20:37 -0400 Subject: [PATCH] qute: add minifocs enclosures and plaintext links greasmonkey scripts --- qutebrowser/greasemonkey/minifocs.js | 6 +++++ qutebrowser/greasemonkey/plaintext.js | 35 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 qutebrowser/greasemonkey/minifocs.js create mode 100644 qutebrowser/greasemonkey/plaintext.js diff --git a/qutebrowser/greasemonkey/minifocs.js b/qutebrowser/greasemonkey/minifocs.js new file mode 100644 index 0000000..3319cdb --- /dev/null +++ b/qutebrowser/greasemonkey/minifocs.js @@ -0,0 +1,6 @@ +// ==UserScript== +// @name EnclosureExpand +// @include https://minifocs.fly.dev/* +// ==/UserScript== +const details = document.querySelector("details.entry-enclosures"); +details.setAttribute("open", ""); diff --git a/qutebrowser/greasemonkey/plaintext.js b/qutebrowser/greasemonkey/plaintext.js new file mode 100644 index 0000000..b2af599 --- /dev/null +++ b/qutebrowser/greasemonkey/plaintext.js @@ -0,0 +1,35 @@ +// ==UserScript== +// @name PlainText +// @description Makes links in plain text one-click to open +// @include *.txt +// @include *.xml +// ==/UserScript== +const rss = document.querySelector('rss'); + +if (rss) { + for (const link of document.querySelectorAll('link')) { + link.addEventListener('click', function() { window.open(this.textContent); }); + link.style = 'text-decorator: underline;'; + } +} +else { + const text = document.body.innerText; + + const regexpLinks = /http[s]?:\/\/[^;, \n\t]*/ + const regexpLinksAll = /http[s]?:\/\/[^;, \n\t]*/g + const links = [...text.matchAll(regexpLinksAll)] + const pieces = text.split(regexpLinks) + const combined = pieces.reduce((acc, text, index) => { acc.push(text); links[index] && acc.push(links[index]); return acc; }, []) + + const newText = '
' +
+        combined
+        .map((piece) => {
+            if (!regexpLinks.test(piece)) {
+                return piece;
+            }
+            return `${piece}`;
+        })
+        .join('')
+        + '
'; + document.body.innerHTML = newText; +}