Избранное на отдельной странице на Тильде

Скрипт добавляет возможность разместить избранное на отдельной странице на Tilda
Добавьте этот код на отдельную страницу и укажите блок каталога куда выводить избранное и блок-заглушку если в избранном пусто
<script>
{
  const BLOCK_ID = "#rec1752539111";
  const EMPTY_BLOCK_ID = "#rec1752652041";
  const INSTANT_REMOVE = true;

  var cardListRef = null;
  var itemTemplateRef = null;
  var isEmptyState = false;

  function waitForCardList(callback, attempts) {
    attempts = attempts || 0;
    var cardList = $(BLOCK_ID).find(".t-store__card-list");
    var cards = cardList.find(".t-store__card");
    
    if (cardList.length > 0 && cards.length > 0) {
      callback(cardList, cards.first());
      return;
    }
    
    if (attempts < 100) {
      setTimeout(function() { waitForCardList(callback, attempts + 1); }, 100);
    }
  }

  function getActiveProducts() {
    var wishlistData = localStorage.getItem("twishlist");
    if (!wishlistData) return [];
    
    try {
      var wishlist = JSON.parse(wishlistData);
      var products = wishlist.products || [];
      return products.filter(function(p) {
        return p.deleted !== "yes";
      });
    } catch(e) {
      return [];
    }
  }

  function showEmpty() {
    isEmptyState = true;
    $(BLOCK_ID).attr("style", "display: none !important");
    $(EMPTY_BLOCK_ID).attr("style", "display: block !important");
  }

  function showCatalog() {
    isEmptyState = false;
    $(BLOCK_ID).attr("style", "display: block !important");
    $(EMPTY_BLOCK_ID).attr("style", "display: none !important");
  }

  $(document).ready(function() {
    $(EMPTY_BLOCK_ID).hide();
    
    var products = getActiveProducts();
    
    if (products.length === 0) {
      showEmpty();
      
      setInterval(function() {
        if (isEmptyState && $(BLOCK_ID).is(":visible")) {
          $(BLOCK_ID).attr("style", "display: none !important");
        }
      }, 200);
      
      return;
    }
    
    waitForCardList(initWishlist);
    
    window.addEventListener("storage", function(e) {
      if (e.key === "twishlist" && cardListRef && itemTemplateRef) {
        renderWishlist();
      }
    });
    
    setInterval(checkWishlistChanges, 500);
  });

  var lastWishlistHash = "";
  
  function checkWishlistChanges() {
    var data = localStorage.getItem("twishlist");
    var hash = data ? data.length + "_" + (JSON.parse(data).updated || 0) : "empty";
    
    if (hash !== lastWishlistHash && cardListRef && itemTemplateRef) {
      lastWishlistHash = hash;
      renderWishlist();
    }
  }

  function initWishlist(cardList, firstCard) {
    cardListRef = cardList;
    itemTemplateRef = firstCard.clone();
    
    var wishlistData = localStorage.getItem("twishlist");
    lastWishlistHash = wishlistData ? wishlistData.length + "_" + (JSON.parse(wishlistData).updated || 0) : "empty";
    
    renderWishlist();
  }

  function renderWishlist() {
    var products = getActiveProducts();

    if (products.length === 0) {
      showEmpty();
      return;
    }

    showCatalog();
    cardListRef.empty();

    products.forEach(function(p) {
      var card = itemTemplateRef.clone();

      card.attr({
        "data-product-lid": p.lid || p.uid,
        "data-product-uid": p.uid,
        "data-product-url": p.url || ""
      });

      card.find(".js-product-name, .t-store__card__title").text(p.name || "");

      if (p.price) {
        card.find(".js-product-price").text(p.price.toLocaleString("ru-RU"));
        card.find(".t-store__card__price-from").hide();
      }

      if (p.img) {
        card.find(".t-store__card__bgimg").first()
          .attr("data-original", p.img)
          .css("background-image", 'url("' + p.img + '")');
      }
      card.find(".t-store__card__bgimg_second").remove();

      if (p.sku) {
        card.find(".js-product-sku").text(p.sku);
      }

      if (p.options && p.options.length) {
        card.find(".t-store__card__descr, .js-store-prod-descr")
          .text(p.options.map(function(o) { return o.variant; }).join(", "));
      }

      card.find("a").each(function() {
        var href = $(this).attr("href");
        if (href && href.indexOf("#") !== 0) {
          $(this).attr("href", p.url || "#");
        }
      });

      var imgWrapper = card.find(".t-store__card__imgwrapper");
      var existingHeart = imgWrapper.find(".t1002__addBtn");
      if (existingHeart.length === 0) {
        var heartHtml = '<a href="#" class="wishlist-remove-btn t1002__addBtn t1002__addBtn_active" style="position:absolute;top:10px;right:10px;z-index:10;">' +
          '<svg width="21" height="18" viewBox="0 0 21 18" fill="none" xmlns="http://www.w3.org/2000/svg">' +
          '<path d="M20 6.32647C20 11.4974 10.5 17 10.5 17C10.5 17 1 11.4974 1 6.32647C1 -0.694364 10.5 -0.599555 10.5 5.57947C10.5 -0.599555 20 -0.507124 20 6.32647Z" stroke="black" fill="red" stroke-linejoin="round"></path>' +
          '</svg></a>';
        imgWrapper.css("position", "relative").append(heartHtml);
      }

      card.find(".wishlist-remove-btn, .t1002__addBtn").off("click").on("click", function(e) {
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();
        removeFromWishlist(p.uid, card);
        return false;
      });

      cardListRef.append(card);
    });

    $(window).trigger("resize");
    try { twishlist__addProductButtons(); } catch(e) {}
  }

  function updateGlobalWishlist(wishlist) {
    window.twishlist = wishlist;
    
    var counter = document.querySelector('.t1002__wishlisticon-counter');
    if (counter) {
      counter.textContent = wishlist.total;
    }
    
    var favTotals = document.querySelectorAll('.favorites_total .tn-atom');
    favTotals.forEach(function(el) {
      el.innerText = wishlist.total > 0 ? wishlist.total : '';
    });
    
    var favIcons = document.querySelectorAll('.favorites_icon');
    var favTotalEls = document.querySelectorAll('.favorites_total');
    
    if (wishlist.total <= 0) {
      favIcons.forEach(function(el) { el.classList.add('blkFav'); });
      favTotalEls.forEach(function(el) { el.classList.add('blkFav'); });
    } else {
      favIcons.forEach(function(el) { el.classList.remove('blkFav'); });
      favTotalEls.forEach(function(el) { el.classList.remove('blkFav'); });
    }
    
    favIcons.forEach(function(el) { 
      el.classList.add('favorites_icon_anim');
    });
    setTimeout(function() {
      favIcons.forEach(function(el) { 
        el.classList.remove('favorites_icon_anim');
      });
    }, 700);
  }

  function removeFromWishlist(uid, card) {
    var data = localStorage.getItem("twishlist");
    if (!data) return;
    
    var wishlist = JSON.parse(data);
    
    wishlist.products = wishlist.products.map(function(p) {
      if (p.uid === uid) {
        p.deleted = "yes";
      }
      return p;
    });
    
    var activeProducts = wishlist.products.filter(function(p) { return p.deleted !== "yes"; });
    wishlist.total = activeProducts.length;
    wishlist.prodamount = activeProducts.reduce(function(s, p) { return s + p.amount; }, 0);
    wishlist.amount = wishlist.prodamount;
    wishlist.updated = Math.floor(Date.now() / 1000);
    
    localStorage.setItem("twishlist", JSON.stringify(wishlist));
    
    updateGlobalWishlist(wishlist);
    
    try { twishlist__updateCounter(); } catch(e) {}
    
    if (INSTANT_REMOVE) {
      card.fadeOut(300, function() {
        card.remove();
        if (cardListRef.children().length === 0) {
          showEmpty();
        }
      });
    } else {
      location.reload();
    }
  }
}
</script>
Вам помогла эта модификация?