if (location.hostname === "www.remove.bg") { let ROOT_KEY = "remove_bg"; window.addEventListener("load", async () => { // do something after ready page }); // LISTEN event 🎧🎧🎧 chrome.runtime.onMessage.addListener(function (res, sendResponse) { if (res.action === ROOT_KEY + "__execute") { const idEl = "btn_" + new Date().getTime(); document.body.innerHTML += ` `; // Wait to handle trigger "upload" button setTimeout(() => { document.querySelector(`#${idEl}`).click(); document.querySelector(`#${idEl}`).remove(); chrome.runtime.sendMessage({ action: "remove_bg__loading", status: true, }); }, 100); window.$getImageRm = setInterval(() => { const imgEl = document.querySelector( 'img[src*="removebg-preview.png"]' ); if (imgEl) { clearInterval(window.$getImageRm); chrome.runtime.sendMessage({ action: "remove_bg__loading", status: false, }); chrome.runtime.sendMessage({ action: "image_editor__save_image", payload: { id: res.payload.id, url: imgEl.src, }, }); // Clear old data document .querySelectorAll(".image-result--delete-btn") ?.forEach((btn) => btn.click()); setTimeout(() => (location.href = "/"), 500); } }, 500); window.$checkCapcha = setInterval(() => { const hasCapcha = document.querySelector(".checkbox-captcha"); if (hasCapcha) { clearInterval(window.$checkCapcha); // stop loading chrome.runtime.sendMessage({ action: "image_editor__loading", status: false, }); chrome.runtime.sendMessage({ action: "image_editor__has_capcha", payload: { msg: "Has capcha!", }, }); } }, 500); } }); }