javascript:(function(){
/* -------------------------------------------------
STEP 1 — USER CLICKS PARENT CHAT CONTAINER
------------------------------------------------- */
alert("Click the chat container you want to start from.");
function handler(ev) {
ev.preventDefault();
ev.stopPropagation();
const start = ev.target;
document.removeEventListener('click', handler, true);
/* -------------------------------------------------
STEP 2 — FIX OVERFLOW FROM CLICKED ELEMENT UPWARD
------------------------------------------------- */
let el = start;
while (el && el !== document.documentElement) {
el.style.setProperty('overflow','visible','important');
el.style.setProperty('overflow-y','visible','important');
el.style.setProperty('overflow-x','visible','important');
el.style.setProperty('max-height','none','important');
el.style.setProperty('height','auto','important');
el.style.setProperty('max-width','none','important');
el.style.setProperty('width','auto','important');
el = el.parentElement;
}
/* -------------------------------------------------
STEP 3 — ASK WHICH MESSAGE NUMBER TO KEEP
------------------------------------------------- */
let n = prompt("Which message number (1-indexed) should remain?");
if (!n) return;
n = parseInt(n, 10);
if (!n) return;
const msgs = Array.from(document.querySelectorAll('[data-message-id]'));
if (n < 1 || n > msgs.length) {
alert("Invalid index");
return;
}
/* -------------------------------------------------
STEP 4 — REMOVE ALL OTHER MESSAGES
------------------------------------------------- */
msgs.forEach((msg, i) => {
if (i !== (n - 1)) msg.remove();
});
msgs[n - 1].classList.add("target-element-e");
const targets = document.querySelectorAll('.target-element-e');
if (!targets.length) return;
/* -------------------------------------------------
STEP 5 — MARK TARGET DESCENDANTS & ANCESTORS
------------------------------------------------- */
targets.forEach(target => {
// mark descendants
target.querySelectorAll('*').forEach(child =>
child.classList.add('target-element-e')
);
// mark ancestors
let el2 = target;
while (el2) {
el2.classList.add('target-element-e');
el2 = el2.parentElement;
}
});
/* -------------------------------------------------
STEP 6 — HIDE EVERYTHING NOT MARKED
------------------------------------------------- */
document.querySelectorAll('*').forEach(el3 => {
if (!el3.classList.contains('target-element-e')) {
el3.style.display = 'none';
}
});
}
// Capture NEXT click
document.addEventListener('click', handler, true);
})();
Follow these steps to add a custom JavaScript bookmarklet to Safari on iOS:
javascript:.Here's the structure all bookmarklets follow:
javascript:(function(){
/* your code here */
})();
You can paste any valid JavaScript inside that wrapper.