Last active
July 26, 2020 02:40
-
-
Save sahin/7c5922ce5a6898670082ff7b4546c770 to your computer and use it in GitHub Desktop.
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
// await sleep(1000) | |
window.sleep = function (time) { | |
console.log("sleeping for" + time) | |
return new Promise((resolve) => setTimeout(resolve, time)); | |
} | |
console.log("sleep"); | |
// await waitfor("ul.search-results__list"); | |
window.waitfor = function(selector) { | |
console.log(selector); | |
if (!document.querySelector(selector)) { | |
console.log("waiting for " + selector) | |
setTimeout(waitfor, 800); // give everything some time to render | |
} | |
else { | |
console.log(selector + " not found") | |
} | |
} | |
console.log("waitfor"); | |
// check how to do it below | |
window.asyncForEach = async function(array, callback) { | |
for (let index = 0; index < array.length; index++) { | |
await callback(array[index], index, array); | |
} | |
} | |
console.log("asyncForEach"); | |
window.asyncForEachold = function (array, func) { | |
return new Promise(function (resolve, reject) { | |
var i = 0; | |
var next = function () { | |
i++; | |
if (i >= array.length) { | |
resolve(); | |
return; | |
} | |
func(array[i], i, next); | |
}; | |
func(array[i], i, next); | |
}); | |
} | |
console.log("asyncForEachold"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var elements = document.querySelectorAll('span.actor-name');