< script type = "text/javascript" >
$(function() {
const urlBlackFridayAPI = "https://script.google.com/macros/s/AKfycbzbB77n5OgakmQqn_FfYyvYChuTRN1mzxa-SRLhTZGSHzRVj0HeRnJSk5KtOrBcDbKK/exec";
var uniqueProduct;
var plpBlackFridayRibbon = {
init: function(data) {
$(".hlisting .product-col, .product-row").each(function() {
var item = $(this);
var formCol = item.find("form").attr("name");
var prodId = formCol.split('product_form_')[1];
var pcode = item.find("input[name='product_data[" + prodId + "][product_id]']").attr("data-product-code");
var bonusText = item.find(".product-info .product-highlight-text.bonus-text").text().trim();
var standoutText = item.find(".product-highlight-text.standout-text").text().trim();
if (bonusText.toLowerCase() === "black friday deals!" || standoutText.toLowerCase() === "black friday deals!") {
item.find(".overlay").addClass("black-friday");
if (item.find(".flag-wrapper").length > 0) {
item.find(".flag-wrapper").each(function(index) {
if ($(this).find(".flag").text().trim().toLowerCase() === "black friday") {
$(this).find(".flag").addClass("black-friday-flag");
}
});
} else {
item.find("form").append("
");
}
} else {
if (data.includes(pcode)) {
item.find(".overlay").addClass("black-friday");
if (item.find(".flag-wrapper").length > 0) {
item.find(".flag").addClass("black-friday-flag").text("Black Friday");
} else {
item.find("form").append("
");
}
}
}
});
}
};
var pdpBlackFridayRibbon = {
init: function(data) {
var pdpBonusText = $(".product-view-right .well .bonus-text").text().toLowerCase().trim();
var pdpStandOutText = $(".product-view-right .well .standout-text").text().toLowerCase().trim();
var pcode = $(".product-id").text().trim();
if (pdpBonusText === "black friday deals!" || pdpStandOutText === "black friday deals!") {
if ($(".product-view-right .well .flag-wrapper").length > 0) {
$(".flag").addClass("black-friday-flag").text("Black Friday");
} else {
$(".product-view-right .well").prepend("
");
}
} else {
for (i = 0; i <= data.length; i++) {
if (pcode === data[i]) {
if ($(".product-view-right .well .flag-wrapper").length > 0) {
$(".flag").addClass("black-friday-flag").text("Black Friday");
} else {
$(".product-view-right .well").prepend("
");
}
}
}
}
}
};
var productBlockRibbon = {
init: function() {
$(".product-col").each(function() {
var item = $(this);
var bonusText = item.find(".product-title").next().text().trim();
if (bonusText.toLowerCase() === "black friday deals!") {
item.find(".overlay").addClass("black-friday");
if (item.find(".flag").length > 0) {
item.find(".flag").each(function(index) {
if ($(this).text().trim().toLowerCase() === "black friday") {
$(this).addClass("black-friday-flag");
} else {
$(this).addClass("black-friday-flag").text("Black Friday");
}
});
} else {
item.find("form").append("
");
}
}
});
}
}
try {
if ($("body").hasClass("products-view")) {
$.getJSON(urlBlackFridayAPI, function(response) {
var data = response.data; // Assign the fetched JSON data to the variable
pdpBlackFridayRibbon.init(data);
});
}
if ($("body").hasClass("categories-view") || $("body").hasClass("products-search") || $("body").hasClass("product_features-view")) {
$.getJSON(urlBlackFridayAPI, function(response) {
var data = response.data; // Assign the fetched JSON data to the variable
plpBlackFridayRibbon.init(data);
$(document).ajaxComplete(function(a, i, e) {
(-1 != e.url.indexOf("?subcats=Y") || e.url.indexOf("pagination_contents")) && ($("body").hasClass("products-search") || $("body").hasClass("categories-view") || $("body").hasClass("index-index")) && plpBlackFridayRibbon.init(data);
});
});
}
$(window).on("load", function() {
if ($(".products-block-ie").length > 0) {
productBlockRibbon.init();
}
});
} catch (H) {
console.log(H)
}
});