Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. "use strict";
  2.  
  3. function getUserInfo() {
  4.     return new Promise(function(e, n) {
  5.         $.ajax({
  6.             type: "POST",
  7.             url: URL_CONFIG.GETUSERINFO,
  8.             contentType: "application/json",
  9.             success: function(n) {
  10.                 e(n)
  11.             },
  12.             error: function(e) {
  13.                 n(1)
  14.             }
  15.         })
  16.     })
  17. }
  18.  
  19. function updateUserBox() {
  20.     getUserInfo().then(function(e) {
  21.         localStorage.setItem("amz_isSubscriber", e.isSubscriber ? "1" : "-1"), $(".amz_notSubscribe_table_data").hide(), e.isSubscriber ? ($(".btn-amz-upgrade").hide(), $("#check-sponsored").attr("disabled", !1), $("#check-sponsored").attr("checked", "checked"), $(".tips-unlogin-box").hide(), $(".tips-login-unsubscriber-box").hide(), $(".tips-login-subscriber-box").show()) : ($(".btn-amz-upgrade").hide(), $("#check-sponsored").attr("disabled", "disabled"), $("#check-sponsored").attr("checked", !1), $(".tips-unlogin-box").hide(), $(".tips-login-unsubscriber-box").show(), $(".tips-login-subscriber-box").hide()), localStorage.setItem("kw_status", e.status), $("#userinfo-box #userinfo-box-username").text(e.username), $("#userinfo-box").css("display", "inline-block"), $("#login-box").hide(), 1 !== e.status && $("#pay-btn").show()
  22.     })["catch"](function(e) {
  23.         $(".btn-amz-upgrade").hide(), $("#check-sponsored").attr("disabled", "disabled"), $("#check-sponsored").attr("checked", !1), $("#userinfo-box").hide(), $("#login-box").css("display", "inline-block"), $(".tips-unlogin-box").show(), $(".tips-login-unsubscriber-box").hide(), $(".tips-login-subscriber-box").hide()
  24.     })
  25. }
  26.  
  27. function login(e) {
  28.     return new Promise(function(n, t) {
  29.         $.ajax({
  30.             type: "POST",
  31.             url: URL_CONFIG.LOGIN,
  32.             contentType: "application/json",
  33.             data: JSON.stringify(e),
  34.             success: function(e) {
  35.                 n(e)
  36.             },
  37.             error: function(e) {
  38.                 t(1)
  39.             }
  40.         })
  41.     })
  42. }
  43.  
  44. function loginInGoogle(e) {
  45.     return new Promise(function(n, t) {
  46.         $.ajax({
  47.             type: "POST",
  48.             url: URL_CONFIG.LOGININGOOGLE,
  49.             contentType: "application/json",
  50.             data: JSON.stringify(e),
  51.             success: function(e) {
  52.                 n(e)
  53.             },
  54.             error: function(e) {
  55.                 t(1)
  56.             }
  57.         })
  58.     })
  59. }
  60.  
  61. function logout() {
  62.     return new Promise(function(e, n) {
  63.         $.ajax({
  64.             type: "POST",
  65.             url: URL_CONFIG.LOGOUT,
  66.             contentType: "application/json",
  67.             success: function(n) {
  68.                 e(n)
  69.             },
  70.             error: function(e) {
  71.                 n(1)
  72.             }
  73.         })
  74.     })
  75. }
  76. var _typeof8 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
  77.         return typeof e
  78.     } : function(e) {
  79.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  80.     },
  81.     _typeof7 = "function" == typeof Symbol && "symbol" === _typeof8(Symbol.iterator) ? function(e) {
  82.         return "undefined" == typeof e ? "undefined" : _typeof8(e)
  83.     } : function(e) {
  84.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof8(e)
  85.     },
  86.     _typeof6 = "function" == typeof Symbol && "symbol" === _typeof7(Symbol.iterator) ? function(e) {
  87.         return "undefined" == typeof e ? "undefined" : _typeof7(e)
  88.     } : function(e) {
  89.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof7(e)
  90.     },
  91.     _typeof5 = "function" == typeof Symbol && "symbol" === _typeof6(Symbol.iterator) ? function(e) {
  92.         return "undefined" == typeof e ? "undefined" : _typeof6(e)
  93.     } : function(e) {
  94.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof6(e)
  95.     },
  96.     _typeof4 = "function" == typeof Symbol && "symbol" === _typeof5(Symbol.iterator) ? function(e) {
  97.         return "undefined" == typeof e ? "undefined" : _typeof5(e)
  98.     } : function(e) {
  99.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof5(e)
  100.     },
  101.     _typeof3 = "function" == typeof Symbol && "symbol" === _typeof4(Symbol.iterator) ? function(e) {
  102.         return "undefined" == typeof e ? "undefined" : _typeof4(e)
  103.     } : function(e) {
  104.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof4(e)
  105.     },
  106.     _typeof2 = "function" == typeof Symbol && "symbol" === _typeof3(Symbol.iterator) ? function(e) {
  107.         return "undefined" == typeof e ? "undefined" : _typeof3(e)
  108.     } : function(e) {
  109.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof3(e)
  110.     },
  111.     _typeof = "function" == typeof Symbol && "symbol" === _typeof2(Symbol.iterator) ? function(e) {
  112.         return "undefined" == typeof e ? "undefined" : _typeof2(e)
  113.     } : function(e) {
  114.         return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : "undefined" == typeof e ? "undefined" : _typeof2(e)
  115.     },
  116.     concat = function(e, n) {
  117.         return e.concat(n)
  118.     },
  119.     flatMap = function(e, n) {
  120.         return n.map(e).reduce(concat, [])
  121.     };
  122. Array.prototype.flatMap = function(e) {
  123.     return flatMap(e, this)
  124. }, jQuery.extend(jQuery.fn.dataTableExt.oSort, {
  125.     "numeric-pre": function(e) {
  126.         var n = String(e).replace(/<[\s\S]*?>/g, "");
  127.         return n = n.replace(/Not in top 300/g, "100000"), n = parseInt(n) || 0, parseInt(n)
  128.     },
  129.     "numeric-asc": function(e, n) {
  130.         return e < n ? -1 : e > n ? 1 : 0
  131.     },
  132.     "numeric-desc": function(e, n) {
  133.         return e < n ? 1 : e > n ? -1 : 0
  134.     }
  135. }), jQuery.extend(jQuery.fn.dataTableExt.oSort, {
  136.     "html-percent-pre": function(e) {
  137.         var n = String(e).replace(/<[\s\S]*?>/g, "");
  138.         if (n = n.replace(/Not in top 300/g, "100000"), n = n.replace(/ /gi, ""), n.indexOf("Page") !== -1 && n.indexOf("No") !== -1) {
  139.             var t = n.substring(n.indexOf("Page") + 4, n.indexOf("No"));
  140.             t = parseInt(t) || 0;
  141.             var o = n.substr(n.indexOf("No") + 2, 2);
  142.             return o = parseInt(o) || 0, 20 * t + o
  143.         }
  144.         return parseInt(n)
  145.     },
  146.     "html-percent-asc": function(e, n) {
  147.         return e < n ? -1 : e > n ? 1 : 0
  148.     },
  149.     "html-percent-desc": function(e, n) {
  150.         return e < n ? 1 : e > n ? -1 : 0
  151.     }
  152. });
  153. var BASE_SERVER = "https://amzdatastudio.com",
  154.     BASE_API_SERVER = "https://amzdatastudio.com",
  155.     URL_CONFIG = {
  156.         LOGIN: BASE_API_SERVER + "/api/user/login",
  157.         LOGININGOOGLE: BASE_API_SERVER + "/api/user/loginByGoogleInChromeExtension",
  158.         LOGOUT: BASE_API_SERVER + "/api/user/logout",
  159.         GETUSERINFO: BASE_API_SERVER + "/api/chrome-extension-kw-index/userinfo",
  160.         KWSUGGEST: BASE_API_SERVER + "/api/chrome-extension-kw-index/relevant-kw"
  161.     };
  162. $("#userinfo-box-username").attr("href", BASE_SERVER + "/user"), $("a.amz-subscriber-page").attr("href", BASE_SERVER + "/user/pricing?type=subscription"), $("a.kwindex-pricing-page").attr("href", BASE_SERVER + "/user/kwindex-extension-pricing"), $("a.kwindex-intro-page").attr("href", "https://amzdatastudio.com/amazon-keyword-relevance-score/"), $(document).ready(function() {
  163.     $(function() {
  164.         $('[data-toggle="tooltip"]').tooltip()
  165.     }), $("#google-login").click(function() {
  166.         chrome.identity.getAuthToken({
  167.             interactive: !0
  168.         }, function(e) {
  169.             return chrome.runtime.lastError ? void callback(chrome.runtime.lastError) : void loginInGoogle({
  170.                 access_token: e
  171.             }).then(function(e) {
  172.                 "error" === e.result ? alert(e.message) : (updateUserBox(), $("#loginModal").modal("hide"))
  173.             })["catch"](function(e) {
  174.                 alert("Login failed: you have no permission for it"), console.error("failed to login, please try again")
  175.             })
  176.         })
  177.     }), updateUserBox();
  178.     var e = $("#datatable").DataTable({
  179.         dom: "Bfrtip",
  180.         buttons: ["excelHtml5", "csvHtml5"],
  181.         data: [],
  182.         columnDefs: [{
  183.             targets: 4,
  184.             orderable: !1
  185.         }],
  186.         aoColumnDefs: [{
  187.             sType: "html-percent",
  188.             aTargets: [5]
  189.         }],
  190.         paging: !1,
  191.         rowCallback: function(e) {
  192.             "Y" === data[2] ? $(e).css("background-color", "#dff0d8") : $(e).css("background-color", "#f2dede")
  193.         }
  194.     });
  195.     $("#datatable").dataTable().fnSetColumnVis(8, !1), $("#datatable").css("width", "60rem");
  196.     var n = $("#progress-bar"),
  197.         t = $("#progress-bar-text"),
  198.         o = [],
  199.         r = function(e) {
  200.             return new Promise(function(n, t) {
  201.                 0 === e.length ? n([]) : $.ajax({
  202.                     type: "GET",
  203.                     url: "https://www.amazon." + $("#country").val() + "/dp/" + encodeURIComponent(e),
  204.                     success: function(t) {
  205.                         var o = [];
  206.                         try {
  207.                             var r = t.match(/asinVariationValues" :(.*)\n/)[1];
  208.                             r = r.substring(0, r.length - 1);
  209.                             var a = JSON.parse(r);
  210.                             o = Object.keys(a);
  211.                             var i = t.match(/parentAsin" : "(.*)",\n/)[1];
  212.                             i && o.push(i)
  213.                         } catch (s) {}
  214.                         o.push(e), n(o)
  215.                     },
  216.                     error: function(e) {
  217.                         e && e.responseText.indexOf("amazon") !== -1 && $("#search-btn").prop("disabled") && (window.alert("Please input a valid ASIN, or leave the ASIN field empty to retrieve the keywords' data only."), $("#search-btn").prop("disabled", !1), $("#search-btn").html("Check Now")), t([])
  218.                     }
  219.                 })
  220.             })
  221.         },
  222.         a = function() {
  223.             var e = !(arguments.length > 0 && void 0 !== arguments[0]) || arguments[0],
  224.                 a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
  225.             getUserInfo().then(function() {
  226.                 $("#kw-btn").prop("disabled", !0), $("#kw-btn").html("Loading"), $(".amz_notSubscribe_table_data").hide(), l([], e);
  227.                 var c = $("#asin").val().trim(),
  228.                     u = 0 === c.length && $("#check-volume").is(":checked") || null !== c.match(/(?:[0-9A-Z]{10})/i),
  229.                     d = "" !== $("#keywords").val();
  230.                 if (d)
  231.                     if (u) {
  232.                         o = [];
  233.                         var f = $("#keywords").val().split(/\n/).map(function(e) {
  234.                                 return e.trim()
  235.                             }).filter(function(e) {
  236.                                 return e.length > 0
  237.                             }),
  238.                             p = [];
  239.                         if ($.each(f, function(e, n) {
  240.                                 $.inArray(n, p) === -1 && p.push(n)
  241.                             }), p.length > 200) return alert("Please don’t put more that 200 lines for one search"), $("#kw-btn").prop("disabled", !1), void $("#kw-btn").html("Relevant KW");
  242.                         $("#search-btn").prop("disabled", !0), $("#search-btn").html("Loading"), t.html("0%"), n.width("0%");
  243.                         var y = $("#check-rank").is(":checked"),
  244.                             m = {};
  245.                         r(c).then(function(r) {
  246.                             p.forEach(function(a, u) {
  247.                                 function d(e, o) {
  248.                                     m[e] = o;
  249.                                     var r = 0;
  250.                                     for (var a in m) r += m[a] || 0;
  251.                                     var i = Math.round(100 * r / p.length / 20);
  252.                                     i = i > 99 ? 99 : i, t.html(i + "%"), n.width(i + "%")
  253.                                 }
  254.  
  255.                                 function f(e) {
  256.                                     $.ajax({
  257.                                         type: "GET",
  258.                                         url: "https://www.amazon." + $("#country").val() + "/s/",
  259.                                         data: "field-keywords=" + encodeURIComponent(a) + "&page=1",
  260.                                         success: function(n) {
  261.                                             var t = $($.parseHTML(n)).find("#s-result-count").length > 0 ? $($.parseHTML(n)).find("#s-result-count") : $($.parseHTML(n)).find(".rush-component .s-desktop-toolbar .sg-row-align-items-center .a-spacing-small SPAN"),
  262.                                                 o = "0";
  263.                                             if (t && t.length > 0) {
  264.                                                 var r = t[0].innerText.toLowerCase();
  265.                                                 if ($("#country").val().indexOf("jp") === -1) {
  266.                                                     var a = /([\d,.\s]+) (result|résult|risult|ergebnissen|ergebnisse)/i;
  267.                                                     try {
  268.                                                         o = a.exec(r.toLowerCase())[1]
  269.                                                     } catch (i) {}
  270.                                                 } else o = r.indexOf("以上") !== -1 ? r.substring(r.indexOf("検索結果"), r.indexOf("以上")) : r.substring(r.indexOf("検索結果") === -1 ? 0 : r.indexOf("検索結果"), r.indexOf("のうち"))
  271.                                             }
  272.                                             o = o.replace(/[^0-9]/g, ""), o = parseInt(o) || 0, o > 0 && o % 1e3 === 0 && (o += "+"), e(o)
  273.                                         }
  274.                                     })
  275.                                 }
  276.  
  277.                                 function b(n, t, r, c, d, f) {
  278.                                     var y = c,
  279.                                         m = "https://www.amazon." + $("#country").val() + "/dp/" + encodeURIComponent(y),
  280.                                         b = y ? "<a href='" + m + "' target='_blank'>" + y + "</a>" : "-",
  281.                                         h = null === d ? "-" : d ? "Y" : "N",
  282.                                         g = r;
  283.                                     if (r.indexOf("Page") !== -1) {
  284.                                         var w = parseInt(r.substring(r.indexOf("page") + 5, r.indexOf("<br"))) || 1,
  285.                                             v = "https://www.amazon." + $("#country").val() + "/s/?field-keywords=" + encodeURIComponent(a) + "&page=" + w;
  286.                                         g = '<a href="' + v + '" target="_blank">' + r + "</a>"
  287.                                     }
  288.                                     var S = i[a] || "-";
  289.                                     S = '<span style="color: #FFA500;">' + S + "</span>", o.push([u + 1, a, n, b, t, g, h, f, S, "", ""]), p.length >= 10 ? o.length % 10 === 0 && l(o, e) : l(o, e), o.length === p.length && s(o, e)
  290.                                 }
  291.  
  292.                                 function h(e, n, t, o, r) {
  293.                                     var i = "Not in top 300" !== n;
  294.                                     i ? (i = i ? "Y" : "N", b(i, n, t, e, o, r)) : $.ajax({
  295.                                         type: "GET",
  296.                                         url: "https://www.amazon." + $("#country").val() + "/s/",
  297.                                         data: "field-keywords=" + encodeURIComponent(c) + "+" + encodeURIComponent(a),
  298.                                         success: function(s) {
  299.                                             i = 0 === $($.parseHTML(s)).find("#noResultsTitle").length, i ? (i = i ? "Y" : "N", b(i, n, t, e, o, r)) : $.ajax({
  300.                                                 type: "GET",
  301.                                                 url: "https://www.amazon." + $("#country").val() + "/s/",
  302.                                                 data: "field-keywords=" + encodeURIComponent(a) + "+" + encodeURIComponent(c),
  303.                                                 success: function(a) {
  304.                                                     i = 0 === $($.parseHTML(a)).find("#noResultsTitle").length, i = i ? "Y" : "N", b(i, n, t, e, o, r)
  305.                                                 }
  306.                                             })
  307.                                         },
  308.                                         error: function() {
  309.                                             console.error("Server Error")
  310.                                         }
  311.                                     })
  312.                                 }
  313.  
  314.                                 function g(e, n, t, o) {
  315.                                     var r = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : null;
  316.                                     $.ajax({
  317.                                         type: "GET",
  318.                                         url: "https://www.amazon." + $("#country").val() + "/s/",
  319.                                         data: "field-keywords=" + encodeURIComponent(n) + "&page=" + t,
  320.                                         success: function(a) {
  321.                                             if (null === r) {
  322.                                                 var i = $($.parseHTML(a)).find("#s-result-count").length > 0 ? $($.parseHTML(a)).find("#s-result-count") : $($.parseHTML(a)).find(".rush-component .s-desktop-toolbar .sg-row-align-items-center .a-spacing-small SPAN"),
  323.                                                     s = "0";
  324.                                                 if (i && i.length > 0) {
  325.                                                     var l = i[0].innerText.toLowerCase();
  326.                                                     if ($("#country").val().indexOf("jp") === -1) {
  327.                                                         var c = /([\d,.\s]+) (result|résult|risult|ergebnissen|ergebnisse)/i;
  328.                                                         try {
  329.                                                             s = c.exec(l.toLowerCase())[1]
  330.                                                         } catch (u) {}
  331.                                                     } else s = l.indexOf("以上") !== -1 ? l.substring(l.indexOf("検索結果"), l.indexOf("以上")) : l.substring(l.indexOf("検索結果") === -1 ? 0 : l.indexOf("検索結果"), l.indexOf("のうち"))
  332.                                                 }
  333.                                                 s = s.replace(/[^0-9]/g, ""), s = parseInt(s) || 0, s > 0 && s % 1e3 === 0 && (s += "+"), r = s
  334.                                             }
  335.                                             var f = !1,
  336.                                                 p = 1,
  337.                                                 y = null,
  338.                                                 m = null,
  339.                                                 b = null,
  340.                                                 h = null;
  341.                                             if ($("#check-sponsored").is(":checked")) {
  342.                                                 var w = $($.parseHTML(a)).find(".s-result-item").get().filter(function(e) {
  343.                                                     return 0 === $(e).find(".acs-showcase-result-item-amazons-choice").length && $(e).attr("data-asin") && $(e).attr("class").indexOf("acs-private-brands-container-background") === -1
  344.                                                 });
  345.                                                 w.forEach(function(n) {
  346.                                                     var o = $(n).attr("data-asin");
  347.                                                     f || (e.includes(o) && (f = !0, y = o, m = $(n).find(".s-sponsored-header").length > 0 || $(n).text().toLowerCase().match(/Sponsored|Gesponsert|Gesponsord|Sponsorowane|Sponsorlu|Sponzorováno|Sponsorisé|Patrocinado|Sponsorizzato|Patrocinado/gi) || $(n).text().toLowerCase().indexOf("商品推广") !== -1 || $(n).text().toLowerCase().indexOf("スポンサー プロダクト") !== -1, b = (t - 1) * w.length + p, h = "Page " + t + "<br>No " + p), p++)
  348.                                                 })
  349.                                             } else {
  350.                                                 var w = $($.parseHTML(a)).find(".s-result-item").get().filter(function(e) {
  351.                                                     var n = 0 === $(e).find(".s-sponsored-header").length && !$(e).text().toLowerCase().match(/Sponsored|Gesponsert|Gesponsord|Sponsorowane|Sponsorlu|Sponzorováno|Sponsorisé|Patrocinado|Sponsorizzato|Patrocinado/gi) && $(e).text().toLowerCase().indexOf("商品推广") === -1 && $(e).text().toLowerCase().indexOf("スポンサー プロダクト") === -1 && 0 === $(e).find(".acs-showcase-result-item-amazons-choice").length && $(e).attr("data-asin") && $(e).attr("class").indexOf("acs-private-brands-container-background") === -1;
  352.                                                     return n
  353.                                                 }).map(function(e) {
  354.                                                     return $(e).attr("data-asin")
  355.                                                 });
  356.                                                 w.forEach(function(n) {
  357.                                                     f || (e.includes(n) && (f = !0, y = n, b = (t - 1) * w.length + p, h = "Page " + t + "<br>No " + p), p++)
  358.                                                 })
  359.                                             }
  360.                                             d(n, t), f ? (d(n, 20), o(y, b, h, m, r)) : t >= 20 ? o(y, "Not in top 300", "Not in top 300", m, r) : g(e, n, t + 1, o, r)
  361.                                         },
  362.                                         error: function() {
  363.                                             console.error("Server Error")
  364.                                         }
  365.                                     })
  366.                                 }
  367.  
  368.                                 function w() {
  369.                                     if (0 === c.length) f(function(e) {
  370.                                         b("", "", "", "", null, e)
  371.                                     });
  372.                                     else {
  373.                                         var e = y ? r : [c];
  374.                                         g(e, a, 1, function(e, n, t, o, r) {
  375.                                             h(e, n, t, o, r)
  376.                                         })
  377.                                     }
  378.                                 }
  379.                                 w()
  380.                             })
  381.                         })
  382.                     } else window.alert("Please input a valid ASIN, or leave the ASIN field empty to retrieve the keywords' data only."), $("#kw-btn").prop("disabled", !1), $("#kw-btn").html("Relevant KW");
  383.                 else a.reverseTips ? window.alert(a.reverseTips) : window.alert("Please put keywords in the keywords field."), $("#kw-btn").prop("disabled", !1), $("#kw-btn").html("Relevant KW")
  384.             })["catch"](function(e) {
  385.                 $("#loginModal").modal("show")
  386.             })
  387.         },
  388.         i = {};
  389.     $("#logout-btn").click(function() {
  390.         logout().then(function(e) {
  391.             updateUserBox()
  392.         })
  393.     }), $("#login-btn").click(function() {
  394.         $("#form-username").val().length > 0 && $("#form-password").val().length > 0 ? login({
  395.             username: $("#form-username").val(),
  396.             password: $("#form-password").val()
  397.         }).then(function(e) {
  398.             "error" === e.result ? alert(e.message) : (updateUserBox(), $("#loginModal").modal("hide"))
  399.         })["catch"](function(e) {
  400.             alert("Login failed: Wrong Username or Password"), console.error("failed to login, please try again")
  401.         }) : alert("Invalid Username or Password")
  402.     }), $("#pay-btn").click(function() {
  403.         window.open(BASE_SERVER + "/user/kwindex-extension-pricing")
  404.     }), $("#signup-btn").click(function() {
  405.         window.open(BASE_SERVER + "/user/signup")
  406.     }), $("#kw-btn").click(function() {
  407.         getUserInfo().then(function() {
  408.             return $("#asin").val().length < 10 ? void alert("Please input a valid ASIN") : void chrome.cookies.getAll({
  409.                 domain: ".amazon." + $("#country").val()
  410.             }, function(e, n) {
  411.                 var t = e.map(function(e) {
  412.                         if (e.domain == ".amazon." + $("#country").val()) return e.name + "=" + e.value
  413.                     }),
  414.                     o = t.join(";").split("").reverse().join(""),
  415.                     r = $("#asin").val(),
  416.                     s = $("#country").val();
  417.                 $("#keywords").val(""), $.ajax({
  418.                     type: "POST",
  419.                     url: URL_CONFIG.KWSUGGEST,
  420.                     contentType: "application/json",
  421.                     data: JSON.stringify({
  422.                         asin: r,
  423.                         amzdatastudio_key: o,
  424.                         region: s
  425.                     }),
  426.                     success: function(e) {
  427.                         if (e.error) e.isSubscriber ? $("#subscriberTipsModal").modal("show") : $("#unsubscriberTipsModal").modal("show"), $("#kw-btn").prop("disabled", !1), $("#kw-btn").html("Relevant KW");
  428.                         else {
  429.                             var n = e.result;
  430.                             e.needLogin ? alert("Please sign into your SellerCentral to get the relevant keywords.") : 0 === n.length ? alert("No relevant keywords found. Please make sure you have input a valid ASIN.") : (n.forEach(function(e) {
  431.                                 i[e.keyword] = e.score
  432.                             }), $("#keywords").val(n.map(function(e) {
  433.                                 return e.keyword
  434.                             }).join("\n")), a(!0))
  435.                         }
  436.                     },
  437.                     error: function(e) {
  438.                         $("#loginTipsModal").modal("show")
  439.                     }
  440.                 })
  441.             })
  442.         })["catch"](function() {
  443.             $("#loginModal").modal("show")
  444.         })
  445.     }), $("#show-reversekw-tips").click(function(e) {
  446.         $("#reversekwTipsModal").modal("show")
  447.     }), $("#show-sponsor-tips").click(function(e) {
  448.         $("#sponsorTipsModal").modal("show")
  449.     }), $(".btn-sign-in").click(function() {
  450.         $("#loginTipsModal").modal("hide"), $("#reversekwTipsModal").modal("hide"), $("#sponsorTipsModal").modal("hide"), $("#loginModal").modal("show")
  451.     }), $("#reset-btn").click(function() {
  452.         $("#asin").val(""), $("#keywords").val("")
  453.     }), $("#search-btn").click(function() {
  454.         i = {}, a(!1)
  455.     });
  456.     var s = function(e, o) {
  457.             if ($("#check-volume").is(":checked")) $.ajax({
  458.                 type: "POST",
  459.                 url: "https://sellercentral.amazon." + $("#country").val() + "/sspa/hsa/cm/keywords/power",
  460.                 contentType: "application/json",
  461.                 data: JSON.stringify({
  462.                     pageId: "https://www.amazon." + $("#country").val() + "/HSA/pages/default",
  463.                     keywordList: e.flatMap(function(e) {
  464.                         return [{
  465.                             key: e[1],
  466.                             matchType: "EXACT"
  467.                         }, {
  468.                             key: e[1],
  469.                             matchType: "BROAD"
  470.                         }]
  471.                     })
  472.                 }),
  473.                 success: function(r) {
  474.                     "object" === ("undefined" == typeof r ? "undefined" : _typeof(r)) && 0 !== r.length || alert("Please sign into your SellerCentral to get the Search Volume data.");
  475.                     var a = !0,
  476.                         i = !1,
  477.                         s = void 0;
  478.                     try {
  479.                         for (var c, u = e[Symbol.iterator](); !(a = (c = u.next()).done); a = !0) {
  480.                             var d = c.value,
  481.                                 f = null,
  482.                                 p = null;
  483.                             try {
  484.                                 f = r.find(function(e) {
  485.                                     return e.keyword.toLowerCase() === d[1].toLowerCase() && "EXACT" === e.matchType
  486.                                 }), p = r.find(function(e) {
  487.                                     return e.keyword.toLowerCase() === d[1].toLowerCase() && "BROAD" === e.matchType
  488.                                 })
  489.                             } catch (y) {}
  490.                             d[d.length - 2] = f ? Math.round(30 * f.impression) : "NONE", d[d.length - 1] = p ? Math.round(30 * p.impression) : "NONE"
  491.                         }
  492.                     } catch (m) {
  493.                         i = !0, s = m
  494.                     } finally {
  495.                         try {
  496.                             !a && u["return"] && u["return"]()
  497.                         } finally {
  498.                             if (i) throw s
  499.                         }
  500.                     }
  501.                     $("#search-btn").prop("disabled", !1), $("#search-btn").html("Check Now"), $("#kw-btn").prop("disabled", !1), $("#kw-btn").html("Relevant KW"), "1" !== localStorage.getItem("amz_isSubscriber") && o && $(".amz_notSubscribe_table_data").show(), n.width("100%"), t.html("Finished!"), l(e, o)
  502.                 }
  503.             });
  504.             else {
  505.                 var r = !0,
  506.                     a = !1,
  507.                     i = void 0;
  508.                 try {
  509.                     for (var s, c = e[Symbol.iterator](); !(r = (s = c.next()).done); r = !0) {
  510.                         var u = s.value;
  511.                         u.push(""), u.push("")
  512.                     }
  513.                 } catch (d) {
  514.                     a = !0, i = d
  515.                 } finally {
  516.                     try {
  517.                         !r && c["return"] && c["return"]()
  518.                     } finally {
  519.                         if (a) throw i
  520.                     }
  521.                 }
  522.                 $("#search-btn").prop("disabled", !1), $("#search-btn").html("Check Now"), $("#kw-btn").prop("disabled", !1), $("#kw-btn").html("Relevant KW"), n.width("100%"), t.html("Finished!"), l(e, o)
  523.             }
  524.         },
  525.         l = function(n) {
  526.             var t = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
  527.             e = $("#datatable").DataTable({
  528.                 destroy: !0,
  529.                 dom: "Bfrtip",
  530.                 buttons: [{
  531.                     extend: "excelHtml5",
  532.                     title: $("#asin").val()
  533.                 }, {
  534.                     extend: "csvHtml5",
  535.                     title: $("#asin").val()
  536.                 }],
  537.                 data: n,
  538.                 aoColumnDefs: [{
  539.                     sType: "numeric",
  540.                     aTargets: [4]
  541.                 }, {
  542.                     sType: "html-percent",
  543.                     aTargets: [5]
  544.                 }, {
  545.                     sType: "numeric",
  546.                     aTargets: [7]
  547.                 }],
  548.                 paging: !1,
  549.                 rowCallback: function(e, n, t) {
  550.                     "Y" === n[2] ? $(e).css("background-color", "#dff0d8") : "N" === n[2] && $(e).css("background-color", "#f2dede")
  551.                 }
  552.             }), $("#datatable").dataTable().fnSetColumnVis(8, t), t ? ($("#mainTable").removeClass("main-container"), $("#datatable").css("width", "72rem")) : ($("#datatable").css("width", "60rem"), $("#mainTable").addClass("main-container"))
  553.         }
  554. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement