Created
April 28, 2021 07:04
-
-
Save EmSixTeen/47ed28a16062d3618453eef0f6d51c4f to your computer and use it in GitHub Desktop.
Automatically expand "Show more" on the YouTube video details page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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