Created
November 9, 2019 20:03
-
-
Save dpaluy/df5bf495898f251aab145ff79cca1a26 to your computer and use it in GitHub Desktop.
how many chrome extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "use strict"; | |
| function sanitizeLocalstorage() { | |
| return !0 | |
| } | |
| function setCache(e, t) { | |
| localStorage[prefix + btoa(e)] = btoa(t); | |
| var a = localStorage.howmany; | |
| a ? (a = atob(a), a = parseInt(a) + 1) : localStorage.howmany = btoa(1), localStorage.howmany = btoa(a) | |
| } | |
| function getCache(e, t) { | |
| var a = localStorage[prefix + btoa(e)]; | |
| if (a) return atob(a) | |
| } | |
| function getCachedResult(e, t, a, n) { | |
| if (sanitizeLocalstorage()) { | |
| var o = null, | |
| r = null; | |
| if (1 == t) var o = getCache(e), | |
| r = getCache(e + "date"); | |
| if (o && r && 1 == t) { | |
| r = new Date(r); | |
| var s = new Date; | |
| r.getTime() >= s.getTime() ? (console.log("cache"), a(JSON.parse(o))) : $.post(e, n, function(n) { | |
| if (console.log("backend"), 200 == n.status && 1 == t) { | |
| setCache(e, JSON.stringify(n)); | |
| var o = new Date; | |
| o.setDate(o.getDate() + cacheDuration), setCache(e + "date", o.toISOString()) | |
| } | |
| a(n) | |
| }) | |
| } else $.post(e, n, function(n) { | |
| if (console.log("backend"), 200 == n.status && 1 == t) { | |
| setCache(e, JSON.stringify(n)); | |
| var o = new Date; | |
| o.setDate(o.getDate() + cacheDuration), setCache(e + "date", o.toISOString()) | |
| } | |
| a(n) | |
| }) | |
| } | |
| } | |
| function getRandomX(e, t, a) { | |
| return getRandomInt(t, a) * e | |
| } | |
| function getRandomInt(e, t) { | |
| return Math.floor(Math.random() * (t - e + 1) + e) | |
| } | |
| function generateSignature() { | |
| return getRandomX(10, 0, 1e3) + "-" + getRandomX(7, 0, 1e3) + "-" + getRandomX(17, 0, 1e3) + "-" + getRandomX(3, 0, 1e3) + "-" + getRandomX(24, 0, 1e3) + "-" + getRandomX(9, 0, 1e3) + "-" + getRandomX(5, 0, 1e3) | |
| } | |
| function defineContextMenu() { | |
| setTimeout(function() { | |
| var e = getCache("paidSecret"); | |
| e && chrome.contextMenus.removeAll(function() { | |
| chrome.contextMenus.create({ | |
| title: "How Many?", | |
| contexts: ["selection"], | |
| onclick: openHowManySearch | |
| }) | |
| }) | |
| }, 100) | |
| } | |
| function openHowManySearch(e, t) { | |
| var a = getCache("paidSecret"), | |
| n = localStorage.defaultCountry; | |
| n && 0 != n.length || (n = "com"); | |
| var o = "&country=" + n.toLowerCase(); | |
| chrome.tabs.create({ | |
| url: smallBaseUrl + search + "?secret=" + a + "&asin=" + e.selectionText + o | |
| }) | |
| } | |
| var baseUrl = "https://www.howmanyextension.com/", | |
| smallBaseUrl = baseUrl.replace("www.", ""), | |
| keys = "chrome/key/", | |
| validate = "chrome/validate/", | |
| search = "search/", | |
| countUses = "chrome/register/", | |
| limitUsagesDay = 5, | |
| prefix = "___", | |
| cacheDuration = 2; | |
| defineContextMenu(), | |
| function() { | |
| function e() { | |
| chrome.tabs.query({}, function(e) { | |
| console.log(e); | |
| for (var t = 0; t < e.length; t++) e[t].url && (e[t].url.indexOf("amazon") > 0 && chrome.tabs.reload(e[t].id), e[t].url.indexOf("6pm") > 0 && chrome.tabs.reload(e[t].id)) | |
| }) | |
| } | |
| function t() { | |
| chrome.tabs.query({ | |
| active: !0, | |
| currentWindow: !0 | |
| }, function(e) { | |
| try { | |
| var t = e[0].url, | |
| a = e[0].id; | |
| t && (chrome.browserAction.disable(a), t.indexOf("amazon.") > 0 ? (t.indexOf("?me=") > 0 && chrome.browserAction.enable(a), t.indexOf("/offer-listing/") > 0 && chrome.browserAction.enable(a), t.indexOf("/dp/") > 0 && chrome.browserAction.enable(a), t.indexOf("/s/") > 0 && chrome.browserAction.enable(a), t.indexOf("/s?") > 0 && chrome.browserAction.enable(a), t.indexOf("/gp/product/") > 0 && chrome.browserAction.enable(a)) : t.indexOf("6pm.") > 0 && t.indexOf("com/p/") > 0 && chrome.browserAction.enable(a)) | |
| } catch (n) {} | |
| }) | |
| } | |
| chrome.runtime.onInstalled.addListener(function(t) { | |
| "install" == t.reason && (setCache("secret", generateSignature()), chrome.tabs.create({ | |
| url: baseUrl | |
| }), e()) | |
| }), chrome.tabs.onMoved.addListener(function() { | |
| t() | |
| }), chrome.tabs.onSelectionChanged.addListener(function() { | |
| t() | |
| }), chrome.tabs.onActiveChanged.addListener(function() { | |
| t() | |
| }), chrome.tabs.onActivated.addListener(function() { | |
| t() | |
| }), chrome.tabs.onCreated.addListener(function() { | |
| t() | |
| }), chrome.tabs.onUpdated.addListener(function() { | |
| t() | |
| }), chrome.tabs.onDetached.addListener(function() { | |
| t() | |
| }), chrome.tabs.onAttached.addListener(function() { | |
| t() | |
| }), chrome.tabs.onUpdated.addListener(function() { | |
| t() | |
| }), chrome.tabs.onRemoved.addListener(function() { | |
| t() | |
| }), chrome.tabs.onReplaced.addListener(function() { | |
| t() | |
| }) | |
| }(); | |
| var Service = function() { | |
| function e(e) { | |
| e = parseFloat(e); | |
| var t = 5e4 / e * 30; | |
| return t /= 1.5, parseInt(t / 2) | |
| } | |
| function t(e) { | |
| var t = JSON.parse(getCache("junglescoutAuth")); | |
| if (t.username && t.username.length > 0) { | |
| var n = !1; | |
| if (t.token) { | |
| Date.now(); | |
| (!t.date || Date.now() - Number(t.date) > 82800) && (n = !0) | |
| } else n = !0; | |
| n && a(t.username, function(t) { | |
| e(t.success ? t.result : !1) | |
| }) | |
| } else e(!1) | |
| } | |
| function a(e, t) { | |
| $.get("https://junglescoutpro.herokuapp.com/api/v1/users/authenticate?username=" + encodeURIComponent(e), function(a) { | |
| if (a && !a.status) t({ | |
| success: !1, | |
| result: a.message | |
| }), setCache("junglescoutAuth", JSON.stringify({})); | |
| else { | |
| var n = {}; | |
| n.date = Date.now(), n.token = "undefined" != typeof a.daily_token ? $.trim(a.daily_token) : "", n.username = e, setCache("junglescoutAuth", JSON.stringify(n)), t({ | |
| success: !0, | |
| result: n.token | |
| }) | |
| } | |
| }, "json") | |
| } | |
| function n(e, t, a) { | |
| if (e && o.hasOwnProperty(e.action)) try { | |
| return o[e.action](e, t, a), !0 | |
| } catch (n) { | |
| console.log(e.action + ": " + n) | |
| } | |
| } | |
| var o = {}; | |
| return chrome.webRequest.onBeforeSendHeaders.addListener(function(e) { | |
| var t = "https://www.amazon.com/", | |
| a = !1; | |
| for (var n in e.requestHeaders) | |
| if (a = "referer" == e.requestHeaders[n].name.toLowerCase()) { | |
| e.requestHeaders[n].value = t; | |
| break | |
| } | |
| return a || e.requestHeaders.push({ | |
| name: "Referer", | |
| value: t | |
| }), { | |
| requestHeaders: e.requestHeaders | |
| } | |
| }, { | |
| urls: ["*://junglescoutpro.herokuapp.com/*"] | |
| }, ["requestHeaders", "blocking"]), chrome.runtime.onMessage.addListener(n), o.executeMainPage = function(e, t, a) { | |
| chrome.tabs.query({ | |
| active: !0, | |
| currentWindow: !0 | |
| }, function(e) { | |
| chrome.tabs.sendMessage(e[0].id, { | |
| action: "openDialogBox" | |
| }, function(e) {}), a({}) | |
| }) | |
| }, o.getAlg = function(e, t, a) { | |
| a({ | |
| alg: localStorage.alg | |
| }) | |
| }, o.getPaidSecret = function(e, t, a) { | |
| var n = getCache("paidSecret"); | |
| a({ | |
| secret: n | |
| }) | |
| }, o.getPaid = function(e, t, a) { | |
| var n = getCache("paidSecret"), | |
| o = 0; | |
| if (e.license) { | |
| n = e.license; | |
| var r = new Date; | |
| r.setDate(r.getDate() - cacheDuration), setCache(baseUrl + validate + "date", r.toISOString()) | |
| } | |
| return setCache("paidSecret", n), n ? (e.usecache && (o = e.usecache), getCachedResult(baseUrl + validate, o, function(e) { | |
| 200 == e.status && (defineContextMenu(), a({ | |
| paid: 1, | |
| message: "" | |
| })), 500 == e.status && (setCache("paidSecret", ""), a({ | |
| paid: 0, | |
| message: "Missing Arguments" | |
| })), 404 == e.status && (setCache("paidSecret", ""), a({ | |
| paid: 0, | |
| message: "License not found" | |
| })), 403 == e.status && (setCache("paidSecret", ""), a({ | |
| paid: 0, | |
| message: "Expired" | |
| })) | |
| }, { | |
| hash: n | |
| })) : a({ | |
| paid: 0, | |
| message: "unpaid" | |
| }), !0 | |
| }, o.getJunglescout = function(e, t, a) { | |
| var n = getCache("junglescoutAuth"); | |
| a(JSON.parse(n)) | |
| }, o.getJunglescoutToken = function(e, n, o) { | |
| return e.username ? a(e.username, function(e) { | |
| o(e) | |
| }) : t(function(e) { | |
| o(e) | |
| }), !0 | |
| }, o.canRun = function(e, t, a) { | |
| var n = getCache("secret"); | |
| return n ? getCachedResult(baseUrl + countUses, 0, function(e) { | |
| a(500 == e.status ? { | |
| can: 0, | |
| message: "" | |
| } : e.data >= limitUsagesDay ? { | |
| can: 0, | |
| message: "" | |
| } : { | |
| can: 1, | |
| message: "" | |
| }) | |
| }, { | |
| hash: btoa(n) | |
| }) : a({ | |
| can: 0 | |
| }), !0 | |
| }, o.getGeneralOptions = function(e, t, a) { | |
| var n = localStorage.generalOptions ? JSON.parse(localStorage.generalOptions) : {}; | |
| return a(n), !0 | |
| }, o.getProductData = function(e, t, a) { | |
| return $.get(e.url, function(e) { | |
| a({ | |
| data2: e | |
| }) | |
| }), !0 | |
| }, o.getEstimatedSales = function(a, n, o) { | |
| var r = a.data.split("||"), | |
| s = r[0], | |
| c = r[1], | |
| i = r[2]; | |
| return i = "co.uk" == i ? "uk" : "us", "Jungle Scout" == localStorage.alg ? (t(function(e) { | |
| e ? $.getJSON("https://junglescoutpro.herokuapp.com/api/v1/est_sales?store=" + i + "&category=" + encodeURIComponent(c) + "&rank=" + s + "&dailyToken=" + e, function(e) { | |
| if (e && e.status) { | |
| var t = e.estSalesResult.toString().replace(/\D/g, ""); | |
| t || (t = 0), o({ | |
| sales: t | |
| }) | |
| } else o({ | |
| sales: 0 | |
| }) | |
| }).fail(function() { | |
| o({ | |
| sales: 0 | |
| }) | |
| }) : o({ | |
| sales: 0 | |
| }) | |
| }), !0) : void o({ | |
| sales: e(s) | |
| }) | |
| }, o.getAmazonKeys = function(e, t, a) { | |
| return getCachedResult(baseUrl + keys + "?marketplace=" + e.data[3], 1, function(t) { | |
| 200 == t.status && a({ | |
| keys: btoa(JSON.stringify(t.data)), | |
| data: e.data, | |
| tag: t.complement ? t.complement.tag : "howmany04-20" | |
| }) | |
| }, null), !0 | |
| }, o.openWindow = function(e, t, a) { | |
| var n = chrome.extension.getURL("pages/howmany.html"); | |
| chrome.tabs.create({ | |
| url: n + "?" + e.url | |
| }) | |
| }, o.openWindow6pm = function(e, t, a) { | |
| var n = chrome.extension.getURL("pages/6pm.html"); | |
| chrome.tabs.create({ | |
| url: n + "?" + e.openwindow6pm + "|||||" + e.title6pm + "|||||" + e.labels6pm + "|||||" + e.options6pm | |
| }) | |
| }, o | |
| }(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment