mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 12:37:05 +03:00
Added wait function
This commit is contained in:
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) {
|
function getYouTubeVideoID(url) {
|
||||||
//Attempt to parse url
|
//Attempt to parse url
|
||||||
let urlObject = null;
|
let urlObject = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user