Skip to content

Instantly share code, notes, and snippets.

@R-WebsterNoble
Created April 11, 2024 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R-WebsterNoble/927497bf36f7d901d27f1ac5dadf2a62 to your computer and use it in GitHub Desktop.
Save R-WebsterNoble/927497bf36f7d901d27f1ac5dadf2a62 to your computer and use it in GitHub Desktop.
Twitter Click All Shows bookmarklet
javascript:%28function%20clickAllShows%28%29%7B%0A%20%20function%20ClickShows%28%29%20%7B%0A%20%20%20%20var%20spans%20%3D%20document.querySelectorAll%28%27span%27%29%3B%0A%20%20%20%20spans.forEach%28span%20%3D%3E%20%7B%0A%20%20%20%20%20%20if%20%28span.textContent%20%3D%3D%3D%20%22Show%22%29%20%7B%0A%20%20%20%20%20%20%20%20span.click%28%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%29%3B%0A%20%20%7D%0A%0A%20%20%2F%2F%20Create%20a%20MutationObserver%20instance%20to%20monitor%20DOM%20changes%0A%20%20var%20observer%20%3D%20new%20MutationObserver%28function%28mutations%29%20%7B%0A%20%20%20%20mutations.forEach%28function%28mutation%29%20%7B%0A%20%20%20%20%20%20%2F%2F%20For%20each%20mutation%2C%20run%20the%20ClickShows%20function%0A%20%20%20%20%20%20ClickShows%28%29%3B%0A%20%20%20%20%7D%29%3B%0A%20%20%7D%29%3B%0A%0A%20%20%2F%2F%20Configuration%20of%20the%20observer%3A%0A%20%20var%20config%20%3D%20%7B%20attributes%3A%20false%2C%20childList%3A%20true%2C%20subtree%3A%20true%2C%20characterData%3A%20false%20%7D%3B%0A%0A%20%20%2F%2F%20Select%20the%20target%20node%20to%20observe%20%28e.g.%2C%20the%20body%20of%20the%20page%29%0A%20%20var%20target%20%3D%20document.querySelector%28%27body%27%29%3B%0A%0A%20%20%2F%2F%20Pass%20in%20the%20target%20node%20and%20the%20observer%20options%0A%20%20observer.observe%28target%2C%20config%29%3B%0A%0A%20%20%2F%2F%20Optionally%2C%20run%20ClickShows%20initially%20in%20case%20the%20page%20is%20already%20loaded%20with%20the%20desired%20content%0A%20%20ClickShows%28%29%3B%0A%7D%29%28%29%3B
(function clickAllShows(){
function ClickShows() {
var spans = document.querySelectorAll('span');
spans.forEach(span => {
if (span.textContent === "Show") {
span.click();
}
});
}
// Create a MutationObserver instance to monitor DOM changes
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
// For each mutation, run the ClickShows function
ClickShows();
});
});
var config = { attributes: false, childList: true, subtree: true, characterData: false };
// Select the target node to observe (e.g., the body of the page)
var target = document.querySelector('body');
// Pass in the target node and the observer options
observer.observe(target, config);
// Optionally, run ClickShows initially in case the page is already loaded with the desired content
ClickShows();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment