I have now spent several hours here reading through the solutions to this problem, like this: Get return value from setTimeout
But I can't find any solution for my problem to get the removeCount value. I also tried to add a Promise, but I don't know how to do it with the increment.
async function removeNeedlessNotifications(mutations) {
const getResult = async () => {
let removeCount = 0;
mutations.forEach((v) =>
v.addedNodes.forEach((v, i) =>
setTimeout(() => {
if (notificationFilter(v)) {
v.querySelector("div.activity-remove.js-remove").click();
removeCount++;
}
}, i * 100)
)
);
return removeCount;
};
return await getResult();
}