1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | // ==UserScript==
// @name Collapsible Thread Chains/Nested Inline Replies
// @version 1.4.9
// @description Make quote links collapsible with indented hierarchy. Override panelBacklinks behavior.
// @match https://8chan.moe/*/res/*
// @match https://8chan.se/*/res/*
// @grant GM_addStyle
// @grant GM.addStyle
// ==/UserScript==
(function() {
'use strict';
GM_addStyle(`
.collapsible-container {
margin-left: 20px;
padding-left: 5px;
margin-top: 8px;
}
.post-content.collapsed {
display: none;
}
.altBacklinks {
display: none !important;
}
.postCell.post-content {
border: none !important;
}
.innerPost {
border-top: 1px solid #474b53;
border-left: 1px solid #474b53;
width: auto;
max-width: none !important;
}
`);
const linkContainers = new WeakMap();
function handlequickreply(event) {
const link = event.target.closest('a');
qr.showQr(link.href.match(/#q(\d+)/)[1]);
}
function handleQuoteClick(event) {
event.preventDefault();
event.stopPropagation();
const link = event.target.closest('a');
if (!link) return;
const rawHash = link.hash.includes('?') ? link.hash.split('?')[0] : link.hash;
const targetId = rawHash.substring(1).replace(/^q/, '');
const targetPost = document.getElementById(targetId);
if (!targetPost) return;
let container = linkContainers.get(link);
if (container) {
const clone = container.querySelector('.post-content');
clone.classList.toggle('collapsed');
return;
}
const level = link.closest('.collapsible-container')?.dataset.level || 0;
container = document.createElement('div');
container.className = 'collapsible-container';
container.dataset.level = parseInt(level) + 1;
const clone = targetPost.cloneNode(true);
clone.removeAttribute('id');
clone.classList.add('post-content');
processClonedElements(clone);
container.appendChild(clone);
const postContainer = link.closest('.innerPost');
if (postContainer) {
postContainer.appendChild(container);
} else {
link.parentNode.insertBefore(container, link.nextSibling);
}
linkContainers.set(link, container);
}
function processClonedElements(clone) {
clone.querySelectorAll('a.linkQuote, .panelBacklinks a').forEach(link => {
const href = link.getAttribute('href');
if (href && href.includes('#')) {
const cleanHash = href.split('#')[1].split('?')[0];
link.href = `#${cleanHash}`;
}
link.addEventListener('click', handleQuoteClick);
});
const firstQuoteLink = clone.querySelector('a.linkQuote');
if (firstQuoteLink) {
firstQuoteLink.addEventListener('click', handlequickreply);
}
}
function initializeLinks() {
document.querySelectorAll('a.linkQuote, .panelBacklinks a').forEach(link => {
const href = link.getAttribute('href');
if (href?.includes('#')) {
link.href = `#${href.split('#')[1].split('?')[0]}`;
}
link.removeEventListener('click', handleQuoteClick);
link.addEventListener('click', handleQuoteClick);
});
// Add the panelBacklinks prevention
document.querySelectorAll('span.panelBacklinks a').forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
e.stopPropagation();
});
});
}
initializeLinks();
new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length) {
initializeLinks();
}
});
}).observe(document.body, { childList: true, subtree: true });
})();
|