1/** 2 * 产ååè¡¨é¡µä»·æ ¼æ¾ç¤ºåè½æ¨¡å - t120主é¢ä¸ç¨ 3 * ç¨äºå¤ç产åå表页é¢ä¸äº§åä»·æ ¼çæ¾ç¤ºé»è¾ï¼å æ¬ä¿éä»·ãåä»·åææ£è®¡ç® 4 * 5 * åè½å æ¬ï¼ 6 * - HTMLå®ä½è§£ç 7 * - ä»·æ ¼å符串æ°å¼æå 8 * - 产ååè¡¨ä»·æ ¼æ¾ç¤ºåå§å 9 * - ææ£è®¡ç®åæ¾ç¤º 10 * - æ¹éå¤çå¤ä¸ªäº§åçä»·æ ¼æ¾ç¤º 11 */ 12(function() { 13 'use strict'; 14 15 // ç¡®ä¿ä»·æ ¼å·¥å ·å·²å è½½ 16 if (typeof window.PriceUtils === 'undefined') { 17 return; 18 } 19 20 /** 21 * è·åä»·æ ¼å±ç¤ºé ç½® 22 * @returns {Object} ä»·æ ¼å±ç¤ºé 置对象 23 */ 24 function getPriceDisplayConfig() { 25 return window.PriceDisplayConfig || { 26 DisplayOrder: 'original,promotion,discount_amount,discount_percent', 27 ShowOriginalPrice: true, 28 ShowPromotionPrice: true, 29 ShowDiscountAmount: true, 30 ShowDiscountPercent: true, 31 ShowStrikethrough: true, 32 OriginalPriceFontSize: '16', 33 OriginalPriceColor: '#999999', 34 PromotionPriceFontSize: '24', 35 PromotionPriceColor: '#ff0000', 36 DiscountAmountFontSize: '14', 37 DiscountAmountColor: '#ff6600', 38 DiscountPercentFontSize: '14', 39 DiscountPercentColor: '#ff6600' 40 }; 41 } 42 43 /** 44 * ç¦ç¨äº§åçå è´åBuy Nowæé® 45 * @param {HTMLElement} productElement - 产åå ç´ 46 */ 47 function disableCartButtons(productElement) { 48 const addToCartBtn = productElement.querySelector('.btn-addto-cart'); 49 const buyNowBtn = productElement.querySelector('.btn-buy-now'); 50 51 if (addToCartBtn) { 52 addToCartBtn.classList.add('disabled'); 53 addToCartBtn.style.pointerEvents = 'none'; 54 addToCartBtn.style.opacity = '0.5'; 55 addToCartBtn.setAttribute('disabled', 'disabled'); 56 } 57 58 if (buyNowBtn) { 59 buyNowBtn.classList.add('disabled'); 60 buyNowBtn.style.pointerEvents = 'none'; 61 buyNowBtn.style.opacity = '0.5'; 62 buyNowBtn.setAttribute('disabled', 'disabled'); 63 } 64 } 65 66 /** 67 * 为å个产ååå§åä»·æ ¼æ¾ç¤º 68 * @param {HTMLElement} productElement - 产åå ç´ 69 */ 70 function initializeProductPriceDisplay(productElement) { 71 const priceContainerWithData = productElement.querySelector('.product-price[data-price-container]'); 72 const basicPriceContainer = productElement.querySelector('.product-price'); 73 74 if (priceContainerWithData) { 75 // å¤ç带æå®æ´ä»·æ ¼æ°æ®ç容å¨ï¼Shop页é¢ï¼ 76 initializeDataPriceContainer(priceContainerWithData); 77 } else if (basicPriceContainer) { 78 // å¤çåºæ¬ä»·æ ¼å®¹å¨ï¼é¦é¡µåå ¶ä»é¡µé¢ï¼ 79 initializeBasicPriceContainer(basicPriceContainer); 80 } 81 } 82 83 /** 84 * å¤ç带ædata-price-containerçä»·æ ¼å®¹å¨ 85 * @param {HTMLElement} priceContainer - ä»·æ ¼å®¹å¨ 86 */ 87 function initializeDataPriceContainer(priceContainer) { 88 const originalPriceStr = priceContainer.getAttribute('data-original-price'); 89 const currentPriceStr = priceContainer.getAttribute('data-current-price'); 90 const promotionPriceStr = priceContainer.getAttribute('data-promotion-price'); 91 92 const originalPrice = window.PriceUtils.extractPriceValue(originalPriceStr); 93 const currentPrice = window.PriceUtils.extractPriceValue(currentPriceStr); 94 const promotionPrice = window.PriceUtils.extractPriceValue(promotionPriceStr); 95 96 const config = getPriceDisplayConfig(); 97 98 // åå¤ä»·æ ¼é¡¹æ°æ® 99 const priceItems = {}; 100 101 // åä»·ï¼å线价ï¼- åªæå½å价大äºä¿éä»·æå½åä»·æ¶ææ¾ç¤º 102 const effectivePrice = promotionPrice > 0 ? promotionPrice : currentPrice; 103 if (config.ShowOriginalPrice && originalPrice > 0 && originalPrice > effectivePrice) { 104 const strikethroughStyle = config.ShowStrikethrough ? 'text-decoration: line-through !important;' : 'text-decoration: none !important;'; 105 priceItems.original = { 106 html: `<del class="price-old" style="font-size: ${config.OriginalPriceFontSize}px; color: ${config.OriginalPriceColor}; ${strikethroughStyle}">${originalPriceStr}</del>`, 107 order: 0 108 }; 109 } 110 111 // ä¿éä»·æå½åä»· 112 if (config.ShowPromotionPrice) { 113 // 妿ä¿éä»·æå½å价为0ï¼æ¾ç¤º"ä»·æ ¼å³å°å ¬å¸" 114 let displayPrice = promotionPrice > 0 ? promotionPriceStr : currentPriceStr; 115 if (effectivePrice <= 0) { 116 displayPrice = config.PricingRevealedSoonText || 'Pricing Revealed Soon'; 117 } 118 priceItems.promotion = { 119 html: `<span class="price-current" style="font-size: ${config.PromotionPriceFontSize}px; color: ${config.PromotionPriceColor};">${displayPrice}</span>`, 120 order: 1 121 }; 122 } 123 124 // æ ¹æ®é ç½®çæ¾ç¤ºé¡ºåºæåº 125 const displayOrder = config.DisplayOrder.split(','); 126 const sortedItems = []; 127 128 displayOrder.forEach((key, index) => { 129 if (priceItems[key]) { 130 priceItems[key].order = index; 131 sortedItems.push(priceItems[key]); 132 } 133 }); 134 135 // çæHTML
136 const html = sortedItems.map(item => item.html).join(' '); 137 priceContainer.innerHTML = html || `<span class="price-current">${currentPriceStr}</span>`; 138 139 // 妿ææä»·æ ¼ä¸º0ï¼ç¦ç¨å è´åBuy Nowæé® 140 if (effectivePrice <= 0) { 141 const productElement = priceContainer.closest('.product-card') || priceContainer.closest('.item') || priceContainer.closest('.product'); 142 if (productElement) { 143 disableCartButtons(productElement); 144 } 145 } 146 } 147 148 /** 149 * å¤çåºæ¬ä»·æ ¼å®¹å¨ï¼é¦é¡µçï¼ 150 * @param {HTMLElement} priceContainer - ä»·æ ¼å®¹å¨ 151 */ 152 function initializeBasicPriceContainer(priceContainer) { 153 const currentPriceElement = priceContainer.querySelector('.price-current, .price'); 154 const oldPriceElement = priceContainer.querySelector('.price-old, .old-price'); 155 156 if (!currentPriceElement) return; 157 158 const config = getPriceDisplayConfig(); 159 160 // åºç¨é ç½®æ ·å¼ 161 if (config && config.ShowPromotionPrice) { 162 currentPriceElement.style.fontSize = config.PromotionPriceFontSize + 'px'; 163 currentPriceElement.style.color = config.PromotionPriceColor; 164 } 165 166 if (oldPriceElement && config && config.ShowOriginalPrice) { 167 oldPriceElement.style.fontSize = config.OriginalPriceFontSize + 'px'; 168 oldPriceElement.style.color = config.OriginalPriceColor; 169 } 170 } 171 172 /** 173 * åå§åææäº§åçä»·æ ¼æ¾ç¤º 174 */ 175 function initializeAllProductsPriceDisplay() { 176 const productSelectors = [ 177 '.product-card', 178 '.item', 179 '.product-item', 180 '.product', 181 'td.item-row' // ProductCompare页é¢ç产åè¡ 182 ]; 183 184 productSelectors.forEach(selector => { 185 const productElements = document.querySelectorAll(selector); 186 productElements.forEach(productElement => { 187 if (productElement.querySelector('.product-price')) { 188 initializeProductPriceDisplay(productElement); 189 } 190 }); 191 }); 192 } 193 194 /** 195 * è§å¯DOMååï¼å¤ç卿å è½½ç产å 196 */ 197 function observeProductChanges() { 198 const observer = new MutationObserver(function(mutations) { 199 mutations.forEach(function(mutation) { 200 if (mutation.type === 'childList') { 201 mutation.addedNodes.forEach(function(node) { 202 if (node.nodeType === Node.ELEMENT_NODE) { 203 // æ£æ¥æ°æ·»å çèç¹æ¯å¦æ¯äº§åå ç´ æå å«äº§åå ç´ 204 if (node.classList && node.classList.contains('product-card')) { 205 initializeProductPriceDisplay(node); 206 } else { 207 // æ¥æ¾æ°æ·»å èç¹å ç产åå ç´ 208 const productElements = node.querySelectorAll && node.querySelectorAll('.product-card'); 209 if (productElements) { 210 productElements.forEach(productElement => { 211 initializeProductPriceDisplay(productElement); 212 }); 213 } 214 } 215 } 216 }); 217 } 218 }); 219 }); 220 221 // å¼å§è§å¯äº§ååè¡¨å®¹å¨ - t120主é¢ä½¿ç¨.product-gridä½ä¸ºäº§ååè¡¨å®¹å¨ 222 const productContainer = document.querySelector('.product-grid'); 223 if (productContainer) { 224 observer.observe(productContainer, { 225 childList: true, 226 subtree: true 227 }); 228 } 229 } 230 231 /** 232 * åå§å彿° 233 */ 234 function init() { 235 // DOMå è½½å®æååå§åä»·æ ¼æ¾ç¤º 236 if (document.readyState === 'loading') { 237 document.addEventListener('DOMContentLoaded', function() { 238 initializeAllProductsPriceDisplay(); 239 observeProductChanges(); 240 }); 241 } else { 242 // DOMå·²ç»å è½½å®æï¼ç´æ¥æ§è¡ 243 initializeAllProductsPriceDisplay(); 244 observeProductChanges(); 245 } 246 } 247 248 // å°å½æ°æ´é²å°å ¨å±ä½ç¨åï¼ä»¥ä¾¿å¤é¨è°ç¨ 249 window.PriceDisplayIndexT120 = { 250 initializeProductPriceDisplay: initializeProductPriceDisplay, 251 initializeAllProductsPriceDisplay: initializeAllProductsPriceDisplay, 252 initializeDataPriceContainer: initializeDataPriceContainer, 253 initializeBasicPriceContainer: initializeBasicPriceContainer, 254 init: init 255 }; 256 257 // èªå¨åå§å 258 init(); 259 260}
vendor: 5 bytes, line 260
260)();
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.