Skip to content

Commit

Permalink
fix: wait For Objects webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jun 16, 2023
1 parent 84ffa6b commit 6c22540
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,35 @@ function injectParasite() {
}
}

async function waitForObjects() {
return new Promise((resolve) => {
const checkObjects = () => {
if (
window[injectConfig.webpack] &&
Array.isArray(window[injectConfig.webpack]) &&
window[injectConfig.webpack].every(
(item) => Array.isArray(item) && item.length > 0
)
) {
resolve();
} else {
setTimeout(checkObjects, 200);
}
};

checkObjects();
});
}

(async () => {
// window[injectConfig.webpack] = window[injectConfig.webpack] || [];
if (typeof window[injectConfig.webpack] === 'undefined') {
window[injectConfig.webpack] = [];
}
while (true) {
const last = window[injectConfig.webpack].length - 1;
if (
!window[injectConfig.webpack][last][0].includes(injectConfig.parasite) &&
document.querySelectorAll('#app .two').length
) {
injectParasite();
break;
}
await sleep(2000);
await waitForObjects();

const last = window[injectConfig.webpack].length - 1;
if (
!window[injectConfig.webpack][last][0].includes(injectConfig.parasite) &&
document.querySelectorAll('#app .two').length
) {
injectParasite();
}
})();

Expand Down

0 comments on commit 6c22540

Please sign in to comment.