javascript:(function(){
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;
}
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;
targets.forEach(target => {
// Add class to all descendants
target.querySelectorAll('*').forEach(child => {
child.classList.add('target-element-e');
});
// Add class to ancestors (including <html>)
let el = target;
while (el) {
el.classList.add('target-element-e');
el = el.parentElement;
}
});
document.querySelectorAll('*').forEach(el => {
if (!el.classList.contains('target-element-e')) {
el.style.display = 'none';
}
});
})();
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.