From d0d2bc01a9d82c33aade756f85cc2e2b2e834a07 Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Tue, 22 Apr 2025 21:13:12 +0000 Subject: [PATCH] feat(miniflux) swap permalink/original link for specific feed --- miniflux_scripts/revert_feed_links.js | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 miniflux_scripts/revert_feed_links.js diff --git a/miniflux_scripts/revert_feed_links.js b/miniflux_scripts/revert_feed_links.js new file mode 100644 index 0000000..e48ce13 --- /dev/null +++ b/miniflux_scripts/revert_feed_links.js @@ -0,0 +1,31 @@ +// swap-liens-directs.js — feed 661 +(() => { + 'use strict'; + const FEED_ID = 661, L = location.pathname, Q = q => document.querySelector(q); + const isList = L.startsWith(`/feed/${FEED_ID}/entries`), isEntry = Q(`.entry-meta a[href*="/feed/${FEED_ID}"]`); + if (!isList && !isEntry) return; + + const findDir = d => [...d.querySelectorAll('.entry-content a')].find(a => /liens directs/i.test(a.textContent)); + // Removed '.entry-meta .entry-website a' from the list below. Pay attention next time. + const fixExt = (ctx, url) => ctx.querySelectorAll('a.page-link[data-original-link],a[data-label="website"],li.item-meta-icons-website a').forEach(a => a.href = url); + + if (isEntry) { // Single-entry view + const h = Q('#page-header-title a, h2.item-title a'), d = findDir(document); + if (h && d) { [h.href, d.href] = [d.href, h.href]; d.textContent = d.title = 'Permalien'; fixExt(document, h.href); } + return; + } + + // List view + const items = Q('.items'); if (!items) return; + const patch = a => { + const t = a.querySelector('h2.item-title a[href*="/entry/"]'); + t && fetch(t.href, {credentials:'same-origin'}).then(r => r.text()).then(html => { + const d = findDir(new DOMParser().parseFromString(html, 'text/html')); + // Only update the title and specific external links, not the entry-website link. + if (d) { t.href = d.href; fixExt(a, d.href); } + }).catch(console.error); + }; + items.querySelectorAll('article.item.entry-item').forEach(patch); + new MutationObserver(m => m.forEach(x => x.addedNodes.forEach(n => n.nodeType === 1 && n.matches('article.item.entry-item') && patch(n)))) + .observe(items, {childList:true, subtree:true}); +})();