show read more button for attachments in sidebar by default

This commit is contained in:
2026-05-17 11:39:51 +02:00
parent b2d836ffb1
commit a7b8f8f8e5

View File

@@ -1,4 +1,4 @@
(function() { (function () {
let customEmojis = {}; let customEmojis = {};
let loading = false; let loading = false;
let loadingMore = false; let loadingMore = false;
@@ -67,7 +67,7 @@
return data.meta; return data.meta;
} }
} }
} catch (e) {} } catch (e) { }
return null; return null;
})(); })();
ytOembedPending.set(videoId, promise); ytOembedPending.set(videoId, promise);
@@ -175,7 +175,7 @@
const urlToParse = href.startsWith('//') ? window.location.protocol + href : href; const urlToParse = href.startsWith('//') ? window.location.protocol + href : href;
const urlObj = new URL(urlToParse, siteOrigin); const urlObj = new URL(urlToParse, siteOrigin);
isSameSite = (urlObj.hostname === window.location.hostname); isSameSite = (urlObj.hostname === window.location.hostname);
} catch(e) {} } catch (e) { }
} }
let displayText = text; let displayText = text;
@@ -184,7 +184,7 @@
const urlToParse = href.startsWith('//') ? window.location.protocol + href : href; const urlToParse = href.startsWith('//') ? window.location.protocol + href : href;
const url = new URL(urlToParse.startsWith('http') ? urlToParse : siteOrigin + (urlToParse.startsWith('/') ? '' : '/') + urlToParse); const url = new URL(urlToParse.startsWith('http') ? urlToParse : siteOrigin + (urlToParse.startsWith('/') ? '' : '/') + urlToParse);
displayText = url.pathname + url.search + url.hash; displayText = url.pathname + url.search + url.hash;
} catch (e) {} } catch (e) { }
} }
const isMention = href.startsWith('/user/') && text.startsWith('@'); const isMention = href.startsWith('/user/') && text.startsWith('@');
@@ -195,8 +195,8 @@
}; };
renderer.image = function (href, title, text) { renderer.image = function (href, title, text) {
const src = (typeof href === 'object' && href !== null) ? (href.href || '') : (href || ''); const src = (typeof href === 'object' && href !== null) ? (href.href || '') : (href || '');
const alt = text || ''; const alt = text || '';
const ttl = title ? ` title="${title}"` : ''; const ttl = title ? ` title="${title}"` : '';
return `<img class="sidebar-comment-img" src="${src}" alt="${alt}"${ttl} loading="lazy">`; return `<img class="sidebar-comment-img" src="${src}" alt="${alt}"${ttl} loading="lazy">`;
}; };
@@ -206,8 +206,8 @@
if (trimmed.startsWith('>') && !trimmed.match(/^>>\d+/)) { if (trimmed.startsWith('>') && !trimmed.match(/^>>\d+/)) {
// Manual greentext handling — apply emoji if the user preference allows it // Manual greentext handling — apply emoji if the user preference allows it
const quoteContent = line.substring(line.indexOf('>') + 1); const quoteContent = line.substring(line.indexOf('>') + 1);
const quoteEmojis = window.f0ckSession?.quote_emojis === true; const quoteEmojis = window.f0ckSession?.quote_emojis === true;
const rendered = quoteEmojis const rendered = quoteEmojis
? quoteContent.replace(/:([a-z0-9_]+):/g, (m, n) => renderEmoji(m, n)) ? quoteContent.replace(/:([a-z0-9_]+):/g, (m, n) => renderEmoji(m, n))
: quoteContent; : quoteContent;
return `<span class="greentext">&gt;${rendered}</span>`; return `<span class="greentext">&gt;${rendered}</span>`;
@@ -316,7 +316,7 @@
const urlToParse = cleanUrl.startsWith('//') ? window.location.protocol + cleanUrl : cleanUrl; const urlToParse = cleanUrl.startsWith('//') ? window.location.protocol + cleanUrl : cleanUrl;
const urlObj = new URL(urlToParse, siteOrigin); const urlObj = new URL(urlToParse, siteOrigin);
isSameSite = (urlObj.hostname === window.location.hostname); isSameSite = (urlObj.hostname === window.location.hostname);
} catch(e) { } catch (e) {
isSameSite = cleanUrl.startsWith(siteOrigin) || (cleanUrl.startsWith('/') && !cleanUrl.startsWith('//')); isSameSite = cleanUrl.startsWith(siteOrigin) || (cleanUrl.startsWith('/') && !cleanUrl.startsWith('//'));
} }
const label = isSameSite ? 'Video Link' : 'External Video Link'; const label = isSameSite ? 'Video Link' : 'External Video Link';
@@ -441,6 +441,16 @@
}); });
}; };
const attachMediaLoadListeners = (element) => {
element.querySelectorAll('img, video').forEach(media => {
if (media.dataset.loadListenerBound) return;
media.dataset.loadListenerBound = 'true';
media.addEventListener('load', checkOverflow, { once: true });
media.addEventListener('loadedmetadata', checkOverflow, { once: true });
});
};
// Event delegation — read-more expands, see-less collapses // Event delegation — read-more expands, see-less collapses
document.addEventListener('click', (e) => { document.addEventListener('click', (e) => {
// Read more / See less // Read more / See less
@@ -490,7 +500,7 @@
} }
container.innerHTML = html; container.innerHTML = html;
// Auto-play converted GIF videos // Auto-play converted GIF videos
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => {}), { once: true }); }); }); container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
}; };
const renderFromCache = () => { const renderFromCache = () => {
@@ -507,14 +517,15 @@
if (ioSentinel) { if (ioSentinel) {
container.appendChild(ioSentinel); container.appendChild(ioSentinel);
} }
attachMediaLoadListeners(container);
checkOverflow(); checkOverflow();
fetchSidebarYoutubeTitles(container); fetchSidebarYoutubeTitles(container);
// Auto-play converted GIF videos // Auto-play converted GIF videos
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => {}), { once: true }); }); }); container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
return true; return true;
}; };
const SIDEBAR_PAGE_LIMIT = 50; const SIDEBAR_PAGE_LIMIT = 5;
const loadActivity = async (silent = false) => { const loadActivity = async (silent = false) => {
const container = document.getElementById('sidebar-activity-container'); const container = document.getElementById('sidebar-activity-container');
@@ -613,10 +624,11 @@
} }
// Keep the IO sentinel at the very end so it triggers on the next scroll // Keep the IO sentinel at the very end so it triggers on the next scroll
if (ioSentinel) container.appendChild(ioSentinel); if (ioSentinel) container.appendChild(ioSentinel);
attachMediaLoadListeners(container);
checkOverflow(); checkOverflow();
fetchSidebarYoutubeTitles(container); fetchSidebarYoutubeTitles(container);
// Auto-play converted GIF videos // Auto-play converted GIF videos
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => {}), { once: true }); }); }); container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
} }
} else { } else {
hasMore = false; hasMore = false;
@@ -656,11 +668,12 @@
if (container) { if (container) {
const html = renderActivityItem(newItem); const html = renderActivityItem(newItem);
const temp = document.createElement('div'); const temp = document.createElement('div');
temp.innerHTML = html; temp.innerHTML = html;
const node = temp.firstElementChild; const node = temp.firstElementChild;
if (node) { if (node) {
node.classList.add('new-item-fade'); node.classList.add('new-item-fade');
container.prepend(node); container.prepend(node);
attachMediaLoadListeners(node);
checkOverflow(); checkOverflow();
fetchSidebarYoutubeTitles(container); fetchSidebarYoutubeTitles(container);
} }
@@ -701,10 +714,11 @@
el.classList.remove('new-item-fade'); el.classList.remove('new-item-fade');
void el.offsetWidth; void el.offsetWidth;
el.classList.add('new-item-fade'); el.classList.add('new-item-fade');
attachMediaLoadListeners(inner);
checkOverflow(); checkOverflow();
fetchSidebarYoutubeTitles(el); fetchSidebarYoutubeTitles(el);
// Auto-play converted GIF videos // Auto-play converted GIF videos
inner.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => {}), { once: true }); }); }); inner.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
} }
} }
} }