32 lines
1.7 KiB
JavaScript
32 lines
1.7 KiB
JavaScript
// 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});
|
|
})();
|