javascript:(function(){
let n = prompt("Which message number (1 = most recent)?");
if (!n) return;
n = parseInt(n, 10);
if (!n) return;
let msgs = Array.from(
document.querySelectorAll(
'[data-message-id]'
)
);
msgs.reverse(); // newest message now index 0
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 all 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.