Skip to content

Instantly share code, notes, and snippets.

@EmSixTeen
Created April 28, 2021 07:04
Show Gist options
  • Save EmSixTeen/47ed28a16062d3618453eef0f6d51c4f to your computer and use it in GitHub Desktop.
Save EmSixTeen/47ed28a16062d3618453eef0f6d51c4f to your computer and use it in GitHub Desktop.
Automatically expand "Show more" on the YouTube video details page
/*
Automatically expand the 'Show more' button on the 'Video details' page for YouTube videos
Adapted from: https://stackoverflow.com/a/29754070/493159
2021.04.28
*/
// Call the below function
waitForElementToDisplay("#toggle-button", function () {
document.getElementById("toggle-button").click();
}, 1000, 9000);
function waitForElementToDisplay(selector, callback, checkFrequencyInMs, timeoutInMs) {
var startTimeInMs = Date.now();
(function loopSearch() {
if (document.querySelector(selector) != null) {
callback();
return;
} else {
setTimeout(function () {
if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs)
return;
loopSearch();
}, checkFrequencyInMs);
}
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment