mirror of
https://github.com/Phantop/dotfiles
synced 2024-12-23 21:56:45 +00:00
qute: add minifocs enclosures and plaintext links greasmonkey scripts
This commit is contained in:
parent
d829ca2456
commit
72677e6cf9
6
qutebrowser/greasemonkey/minifocs.js
Normal file
6
qutebrowser/greasemonkey/minifocs.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
// ==UserScript==
|
||||||
|
// @name EnclosureExpand
|
||||||
|
// @include https://minifocs.fly.dev/*
|
||||||
|
// ==/UserScript==
|
||||||
|
const details = document.querySelector("details.entry-enclosures");
|
||||||
|
details.setAttribute("open", "");
|
35
qutebrowser/greasemonkey/plaintext.js
Normal file
35
qutebrowser/greasemonkey/plaintext.js
Normal file
|
@ -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 = '<pre>' +
|
||||||
|
combined
|
||||||
|
.map((piece) => {
|
||||||
|
if (!regexpLinks.test(piece)) {
|
||||||
|
return piece;
|
||||||
|
}
|
||||||
|
return `<a target="_blank" href="${piece}">${piece}</a>`;
|
||||||
|
})
|
||||||
|
.join('')
|
||||||
|
+ '</pre>';
|
||||||
|
document.body.innerHTML = newText;
|
||||||
|
}
|
Loading…
Reference in a new issue