PageSourceSearch

https://wego.jp/cdn/shop/t/302/assets/vfa-product-detail-favorite-…=21604353870807306801772071596?v=1790273828

js wego.jp collected 2026-09-24 18:17:41 UTC 12,122 bytes, 2 lines download raw bytes

1(function(){"use strict";const API_BASE="/apps/wego-favorite/api/favorites",COUNT_API_BASE="/apps/wego-favorite/api/favorites-count";let originalCountMap={};const popupState={oldPosition:0};function isDevEnvironment(){const host=window.location.host;return host.includes("127.0.0.1")||host.includes("localhost")||host.includes("dev-thr-favorit")}function getCustomerId(){if(window.ShopifyCustomer&&window.ShopifyCustomer.id){const id=String(window.ShopifyCustomer.id);return/^\d+$/.test(id)?`gid://shopify/Customer/${id}`:id}if(window.__st&&window.__st.cid){const id=String(window.__st.cid);return/^\d+$/.test(id)?`gid://shopify/Customer/${id}`:id}const metaCustomerId=document.querySelector('meta[name="shopify-customer-id"]');if(metaCustomerId&&metaCustomerId.content){const id=metaCustomerId.content;return/^\d+$/.test(id)?`gid://shopify/Customer/${id}`:id}const button=document.querySelector("[data-customer-id]");if(button&&button.dataset.customerId){const id=button.dataset.customerId;return id==="dev-test-customer"?id:/^\d+$/.test(id)?`gid://shopify/Customer/${id}`:id}return isDevEnvironment()?"dev-test-customer":null}function getCachedCount(productId){const key=`favorite_count_${productId}`,cached=localStorage.getItem(key);if(!cached)return null;try{const data=JSON.parse(cached);return Date.now()-data.timestamp>3e5?(localStorage.removeItem(key),null):data}catch{return null}}function cacheCount(productId,count){const key=`favorite_count_${productId}`;localStorage.setItem(key,JSON.stringify({count,timestamp:Date.now()}))}function initProductDetailFavorites(){const productIdEl=document.querySelector("[data-product-id]")||document.getElementById("data"),productId=productIdEl?.dataset.productId||productIdEl?.dataset.id;productId&&(console.log("[WEGO Favorites] \u521D\u671F\u5316\u958B\u59CB - \u5546\u54C1ID:",productId),loadFavoriteStatus(productId),loadFavoriteCount(productId),setupEventListeners())}async function loadFavoriteStatus(productId){const customerId=getCustomerId();if(!customerId||isDevEnvironment())return;const buttons=document.querySelectorAll(".vfa-wego-favorite-btn[data-variant-id]");for(const button of buttons){const variantId=button.dataset.variantId;if(variantId)try{const response=await fetch(`${API_BASE}/check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({customerId,variantId})});if(!response.ok)continue;const data=await response.json();data.success&&data.isFavorited&&document.querySelectorAll(`.vfa-wego-favorite-btn[data-variant-id="${variantId}"]`).forEach(btn=>updateFavoriteButtonUI(btn,!0))}catch(error){console.error("[WEGO Favorites] \u304A\u6C17\u306B\u5165\u308A\u72B6\u614B\u78BA\u8A8D\u30A8\u30E9\u30FC:",error)}}}async function loadFavoriteCount(productId,retryCount=0){const cached=getCachedCount(productId);if(cached){updateFavoriteCountDisplay(productId,cached.count);return}try{const controller=new AbortController;setTimeout(()=>controller.abort(),3e3);const response=await fetch(`${COUNT_API_BASE}?productId=${encodeURIComponent(productId)}`,{signal:controller.signal});if(!response.ok)throw new Error(`HTTP ${response.status}`);const data=await response.json();if(data.success&&data.data){const count=data.data.totalCount||0;updateFavoriteCountDisplay(productId,count),cacheCount(productId,count)}}catch{if(retryCount<3)return await new Promise(resolve=>setTimeout(resolve,1e3*(retryCount+1))),loadFavoriteCount(productId,retryCount+1);updateFavoriteCountDisplay(productId,0)}}function updateFavoriteCountDisplay(productId,count){const displayValue=count===0||count===void 0||count===null?"0":count.toLocaleString();document.querySelectorAll(`.vfa-wego-favorite-count-wrapper[data-product-id="${productId}"] .vfa-wego-favorite-count-number`).forEach(el=>el.textContent=displayValue),document.querySelectorAll(`.vfa-wego-favorite-count-wrapper[data-product-id="${productId}"]`).forEach(el=>el.style.display="flex")}function setupEventListeners(){document.querySelectorAll(".vfa-wego-favorite-btn--sp.vfa-wego-favorite-btn--main").forEach(button=>{button.dataset.wegoInitialized||(button.dataset.wegoInitialized="true",button.addEventListener("click",handleSPMainButtonClick))}),document.querySelectorAll(".vfa-js-favorite-new").forEach(button=>{button.dataset.wegoInitialized||(button.dataset.wegoInitialized="true",button.addEventListener("click",handlePCFavoriteButtonClick))}),document.querySelectorAll(".p-item-slider__popup-button.favorite").forEach(button=>{button.dataset.wegoInitialized||(button.dataset.wegoInitialized="true",button.addEventListener("click",function(e){if(e.preventDefault(),e.stopPropagation(),!getCustomerId()){handleLoginRequiredClick(e);return}showFavoriteDrawer()}))}),document.querySelectorAll(".vfa-p-item-sku-list__favorite.vfa-wego-favorite-btn").forEach(button=>{button.dataset.wegoInitialized||(button.dataset.wegoInitialized="true",button.addEventListener("click",handleFavoriteClick))}),document.querySelectorAll(".vfa-wego-favorite-btn--login-required").forEach(button=>{button.dataset.wegoInitialized||(button.dataset.wegoInitialized="true",button.addEventListener("click",handleLoginRequiredClick))}),document.addEventListener("click",function(e){const button=e.target.closest(".vfa-p-item-sku-list__favorite.vfa-wego-favorite-btn:not([data-wego-initialized]
1)");button&&(button.dataset.wegoInitialized="true",handleFavoriteClick(e));const loginBtn=e.target.closest(".vfa-wego-favorite-btn--login-required:not([data-wego-initialized])");loginBtn&&(loginBtn.dataset.wegoInitialized="true",handleLoginRequiredClick(e))})}function handlePCFavoriteButtonClick(e){if(e.preventDefault(),e.stopPropagation(),e.currentTarget.classList.contains("vfa-wego-favorite-btn--login-required")){handleLoginRequiredClick(e);return}showFavoriteDrawer()}function handleSPMainButtonClick(e){if(e.preventDefault(),e.stopPropagation(),e.currentTarget.classList.contains("vfa-wego-favorite-btn--login-required")){handleLoginRequiredClick(e);return}showFavoriteDrawer()}function showFavoriteDrawer(){const popup=document.querySelector(".vfa-js-wego-favorite-popup");if(popup){popupState.oldPosition=window.scrollY||window.pageYOffset||0,document.body.style.top=`-${popupState.oldPosition}px`,document.body.classList.add("fixed-side"),popup.style.display="block",document.body.classList.add("vfa-popup-open"),setTimeout(function(){popup.classList.add("visible")},10),popup.querySelectorAll(".vfa-js-wego-favorite-close").forEach(closeBtn=>{closeBtn.addEventListener("click",closeFavoriteDrawer)}),popup.querySelectorAll(".vfa-p-item-sku-list__favorite.vfa-wego-favorite-btn").forEach(button=>{button.dataset.wegoInitialized||(button.dataset.wegoInitialized="true",button.addEventListener("click",handleFavoriteClick))});const productIdEl=document.querySelector("[data-product-id]")||document.getElementById("data"),productId=productIdEl?.dataset.productId||productIdEl?.dataset.id;getCustomerId()&&productId&&loadDrawerFavoriteStatus(productId,popup)}}async function loadDrawerFavoriteStatus(productId,drawer){const customerId=getCustomerId();if(!customerId||isDevEnvironment())return;const buttons=drawer.querySelectorAll(".vfa-wego-favorite-btn[data-variant-id]");for(const button of buttons){const variantId=button.dataset.variantId;if(variantId)try{const response=await fetch(`${API_BASE}/check`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({customerId,variantId})});if(!response.ok)continue;const data=await response.json();data.success&&data.isFavorited&&updateFavoriteButtonUI(button,!0)}catch(error){console.error("[WEGO Favorites] \u30C9\u30ED\u30EF\u30FC\u72B6\u614B\u78BA\u8A8D\u30A8\u30E9\u30FC:",error)}}}function closeFavoriteDrawer(){const popup=document.querySelector(".vfa-js-wego-favorite-popup");popup&&(document.body.classList.remove("fixed-side"),document.body.style.top="",popup.classList.remove("visible"),setTimeout(function(){window.scrollTo(0,popupState.oldPosition),popup.style.display="none",document.body.classList.remove("vfa-popup-open")},500))}async function handleFavoriteClick(e){e.preventDefault(),e.stopPropagation();const button=e.currentTarget||e.target.closest(".vfa-wego-favorite-btn");if(!button||button.classList.contains("vfa-wego-favorite-btn--login-required"))return;if(button.classList.contains("vfa-is-favorited")){alert("\u3059\u3067\u306B\u304A\u6C17\u306B\u5165\u308A\u767B\u9332\u3055\u308C\u3066\u3044\u307E\u3059");return}const customerId=button.dataset.customerId||getCustomerId();if(!customerId||customerId==="dev-test-customer"&&!isDevEnvironment()){handleLoginRequiredClick(e);return}if(button.dataset.loading==="true")return;button.dataset.loading="true",button.classList.add("vfa-is-loading");const productId=button.dataset.productId,variantId=button.dataset.variantId,action="add";updateFavoriteButtonUI(button,!0);try{const response=await fetch(`${API_BASE}/${action}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({customerId,productId,variantId,productName:button.dataset.productName||"",price:button.dataset.variantPrice||"",imageUrl:button.dataset.productImage||""})}),data=await response.json();if(!response.ok){updateFavoriteButtonUI(button,!1),showNotification("\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F","error");return}const cached=getCachedCount(productId);if(cached){originalCountMap[productId]=cached.count;const newCount=cached.count+1;updateFavoriteCountDisplay(productId,newCount),cacheCount(productId,newCount)}else loadFavoriteCount(productId);showNotification("\u304A\u6C17\u306B\u5165\u308A\u306B\u8FFD\u52A0\u3057\u307E\u3057\u305F","success")}catch{updateFavoriteButtonUI(button,!1),showNotification("\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F","error")}finally{button.dataset.loading="false",button.classList.remove("vfa-is-loading")}}function updateFavoriteButtonUI(button,isFavorited){button.classList.toggle("vfa-is-favorited",is
1Favorited);const defaultIcon=button.querySelector(".vfa-favorite-icon--default"),activeIcon=button.querySelector(".vfa-favorite-icon--active");if(defaultIcon&&activeIcon){isFavorited?(defaultIcon.style.display="none",activeIcon.style.display="block"):(defaultIcon.style.display="block",activeIcon.style.display="none");return}const path=button.querySelector(".vfa-wego-favorite-icon path");if(path){path.setAttribute("fill",isFavorited?"#fa7283":"none"),path.setAttribute("stroke","#fa7283");return}const img=button.querySelector('img[src*="heart"], .c-icon img, .vfa-c-icon img, .vfa-wego-favorite-heart-icon');if(img)if(isFavorited){const currentSrc=img.src;currentSrc.includes("heart.svg")&&!currentSrc.includes("heart-solid.svg")&&(img.src=currentSrc.replace("heart.svg","heart-solid.svg")),img.style.filter="none",img.style.opacity="1"}else{const currentSrc=img.src;currentSrc.includes("heart-solid.svg")&&(img.src=currentSrc.replace("heart-solid.svg","heart.svg")),img.style.filter="none",img.style.opacity="0.6"}}function handleLoginRequiredClick(e){e.preventDefault(),e.stopPropagation();const returnUrl=encodeURIComponent(window.location.pathname+window.location.search);window.location.href=`/account/login?return_url=${returnUrl}`}function showNotification(message,type="success"){const existing=document.querySelector(".vfa-wego-notification");existing&&existing.remove();const notification=document.createElement("div");notification.className=`vfa-wego-notification vfa-wego-notification--${type}`,notification.textContent=message;const bgColor={success:"#4caf50",error:"#f44336",info:"#2196f3"}[type]||"#4caf50";notification.style.cssText=`position:fixed;top:20px;right:20px;background:${bgColor};color:white;padding:16px 24px;border-radius:4px;box-shadow:0 2px 8px rgba(0,0,0,0.2);z-index:10000;font-size:14px;`,document.body.appendChild(notification),setTimeout(()=>notification.remove(),3e3)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",initProductDetailFavorites):initProductDetailFavorites()})();
2//# sourceMappingURL=/cdn/shop/t/302/assets/vfa-product-detail-favorite-button.js.map?v=21604353870807306801772071596%3Fv%3D1790273828

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.