Although ForEach console.log's very fast, I am looking to introduce a delay of 8 seconds before logging the next item in Set. I experimented with setTimeout but it doesn't appear to output at the precise milliseconds specified.
const completedIds = [];
//Dom mutation observer
const observeChat = new MutationObserver(function(mutationsList) {
for (let mutation of mutationsList) {
if (mutation.addedNodes.length) {
for (i = 0; i < mutation.addedNodes.length; i++) {
mutation.addedNodes[i].firstChild.naturalWidth < 51 ? pm(mutation.addedNodes[i].firstChild.src.slice(-48, -12)) : false
}
}
}
});
observeChat.observe(document.querySelector('.accounts-container__list'), {attributes: true, childList: true, subtree: false});
// Pm function
pm = ids => {
observeChat.disconnect();
if (!completedIds.includes(ids)) {
const img = new Set().add(ids).forEach(function(id, index) {
setTimeout(function() { // This is not functioning as expected. It does NOT log in the console every 8 seconds
console.log(id)
}, index * 8000)
})
}
observeChat.observe(document.querySelector('.accounts-container__list'), {attributes: true, childList: true, subtree: false});
}