mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2024-11-10 09:07:45 +01:00
Added wait function
This commit is contained in:
parent
adb60c6357
commit
a6c77185de
1 changed files with 14 additions and 0 deletions
14
utils.js
14
utils.js
|
@ -1,3 +1,17 @@
|
|||
// Function that can be used to wait for a condition before returning
|
||||
async function wait(condition, timeout = 5000, check = 100) {
|
||||
return await new Promise((resolve, reject) => {
|
||||
setTimeout(() => {reject("TIMEOUT")}, timeout);
|
||||
const interval = setInterval(() => {
|
||||
let result = condition();
|
||||
if (result !== false) {
|
||||
resolve(result);
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, check);
|
||||
});
|
||||
}
|
||||
|
||||
function getYouTubeVideoID(url) {
|
||||
//Attempt to parse url
|
||||
let urlObject = null;
|
||||
|
|
Loading…
Reference in a new issue