-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
1 lines (1 loc) · 6.57 KB
/
background.js
1
self.importScripts("firebase/app.js", "firebase/auth.js", "firebase/firestore.js", "util/firestore-string-functions.js", "util/chrome-storage-functions.js", "util/random-functions.js", "util/delay.js", "functions/mimic-human-typing.js", "functions/open-search-panel.js", "functions/mimic-human-scrolling.js", "functions/watch-posts.js", "functions/mimic-scroll-top.js", "functions/click-message-button.js", "functions/click-input.js", "functions/click-element.js"); try { const e = { apiKey: "AIzaSyCeQB6YfQPyyYMcfEn4SvT3xR4Vgjs0rP0", authDomain: "wisp-ai.firebaseapp.com", projectId: "wisp-ai", storageBucket: "wisp-ai.appspot.com", messagingSenderId: "844655261609", appId: "1:844655261609:web:e9652b320dc271cb9b36b8" }, s = firebase.initializeApp(e), t = firebase.auth(s), a = s.firestore(); chrome.tabs.onUpdated.addListener((async (e, s, t) => { const a = await self.getCurrentCampaignTabId(); "complete" === s.status && e === a && ("https://www.instagram.com/" === t.url ? chrome.scripting.executeScript({ target: { tabId: e }, files: ["util/chrome-storage-functions.js", "util/delay.js", "util/random-functions.js", "functions/mimic-human-scrolling.js", "functions/mimic-human-typing.js", "functions/click-element.js"] }, (() => { chrome.scripting.executeScript({ target: { tabId: e }, files: ["functions/home-page-flow.js"] }) })) : "https://www.instagram.com/explore/" === t.url ? chrome.scripting.executeScript({ target: { tabId: e }, files: ["util/chrome-storage-functions.js", "util/delay.js", "util/random-functions.js", "functions/click-element.js", "functions/watch-posts.js"] }, (() => { chrome.scripting.executeScript({ target: { tabId: e }, files: ["functions/explore-page-flow.js"] }) })) : isInstagramProfileUrl(t.url) ? chrome.scripting.executeScript({ target: { tabId: e }, files: ["util/chrome-storage-functions.js", "util/delay.js", "util/random-functions.js", "functions/click-element.js", "functions/watch-posts.js"] }, (() => { chrome.scripting.executeScript({ target: { tabId: e }, files: ["functions/profile-page-flow.js"] }) })) : t.url.includes("instagram.com/direct/t/") && chrome.scripting.executeScript({ target: { tabId: e }, files: ["util/chrome-storage-functions.js", "util/delay.js", "util/random-functions.js"] }, (() => { chrome.scripting.executeScript({ target: { tabId: e }, files: ["functions/dm-page-flow.js"] }) }))) })), chrome.runtime.onMessage.addListener(((e, s, i) => { if ("is_user_signed_in" === e.message) return getFirebaseUser().then((e => i({ message: "success" }))).catch((e => i({ message: e.message }))), !0; if ("sign_in" === e.message) { const { email: s, password: a } = e; return t.signInWithEmailAndPassword(s, a).then((() => { i({ message: "success" }) })).catch((e => { i({ message: e.message }) })), !0 } if ("fetch_bulk_imports" === e.message) return getFirebaseUser().then((async e => { try { const s = await a.collection("bulk_imports").doc(e.uid).get(); if (s.exists) { const e = s.data(), t = Object.keys(e.uploads).map((s => { if ("complete" === e.uploads[s].status) return self.replaceUnderscoreWithDots(s) })); i({ message: "success", uploads: t }) } else i({ message: "No uploaded files found" }) } catch (e) { i({ message: e.message }) } })), !0; if ("start_campaign" === e.message) { const { campaignName: s, minMessages: t, maxMessages: i } = e, n = Math.round(calculateRandomNumber(t, i)); setDmLimit(n); const c = self.replaceDotWithUnderscore(s); getFirebaseUser().then((e => { a.collection("bulk_imports").doc(e.uid).get().then((t => { if (t.exists) { const i = t.data(), n = i.uploads[c].data, r = i.uploads[c].selected_scripts; a.collection("scripts").doc(e.uid).get().then((async e => { if (e.exists) { const t = e.data().scripts, a = r.map((e => t[e])); updateCampaignData({ name: s, data: n, scripts: a }); const i = await getUnsentUsername(); resetTotalIncrements(), chrome.tabs.create({ url: `https://www.instagram.com/${i}/`, active: !1, pinned: !0 }, (e => { chrome.tabs.update(e.id, { muted: !0 }), chrome.debugger.attach({ tabId: e.id }, "1.3", (() => { chrome.debugger.sendCommand({ tabId: e.id }, "Emulation.setFocusEmulationEnabled", { enabled: !0 }) })), updateCurrentCampaignTabId(e.id), updateAutomationStatus(!0) })) } })).catch((e => console.error(e))) } })).catch((e => { console.error(e) })) })) } else { if ("dm_sent" === e.message) { const { dmId: s } = e; return getUsernameFromDmId(s).then((async e => { modifySentStatusForUsername(e, !0), await incrementMessageCount(); const s = await getMessageCounter(), t = await getCurrentCampaignTabId(), a = await getDmLimit(); if (s.totalIncrements >= a || 70 === s.value) i({ message: "dm_limit_reached", tabId: t }); else { s.incrementsSince === s.decidedThreshold ? (i({ message: "threshold_hit", tabId: t }), resetIncrementsAndThreshold()) : i({ message: "continue", tabId: t }) } })), !0 } if ("update_username_sent_status_true_firestore" === e.message) { const { username: s } = e; getFirebaseUser().then((e => { getCampaignData().then((t => { const i = replaceDotWithUnderscore(t.name), n = replaceUsernameDotsWithSpecialCharsEscape(s); a.collection("bulk_imports").doc(e.uid).update({ [`uploads.${i}.data.${n}.campaign_info_message`]: firebase.firestore.FieldValue.delete(), [`uploads.${i}.data.${n}.sent`]: !0 }) })) })) } else { if ("update_campaign_info_message_for_username" === e.message) { const { username: s, content: t } = e; return getFirebaseUser().then((e => { getCampaignData().then((n => { const c = replaceDotWithUnderscore(n.name), r = replaceUsernameDotsWithSpecialCharsEscape(s); a.collection("bulk_imports").doc(e.uid).update({ [`uploads.${c}.data.${r}.campaign_info_message`]: t }).then((() => { i({ message: "success" }) })) })) })), !0 } if ("type_text" === e.message) { const { text: s } = e; return mimicHumanTyping(s).then((() => { i({ message: "success" }) })), !0 } if ("open_search_panel" === e.message) openSearchPanel(); else if ("mimic_human_scrolling" === e.message) { const { maxDuration: s } = e; mimicHumanScrolling(s) } else if ("watch_posts" === e.message) { const { maxDuration: s } = e; watchPosts(s) } else if ("mimic_scroll_top" === e.message) mimicScrollTop(); else if ("click_message_button" === e.message) clickMessageButton(); else if ("click_input" === e.message) clickInput(); else if ("click_element" === e.message) { const { x: s, y: t } = e; clickElement({ x: s, y: t }) } } } })) } catch (e) { console.error(e) } function isInstagramProfileUrl(e) { return /^https?:\/\/(www\.)?instagram\.com\/[a-zA-Z0-9._]+\/?$/.test(e) } function getFirebaseUser() { return new Promise(((e, s) => { try { firebase.auth().onAuthStateChanged((t => { t ? e(t) : s("User not signed in") }), (e => { s(e) })) } catch (e) { s(e) } })) }