feat(miniflux) swap permalink/original link for specific feed
This commit is contained in:
parent
74116adc7f
commit
d0d2bc01a9
31
miniflux_scripts/revert_feed_links.js
Normal file
31
miniflux_scripts/revert_feed_links.js
Normal file
@ -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});
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user