1// æ·»å è´ç©è½¦äº§å 2function addCart(data) { 3 if (!data || !data.title) { 4 return false 5 } 6 7 let historyData = localStorage.getItem('sam-cart') 8 let cartData = 9 historyData && historyData !== 'null' && historyData !== '' ? JSON.parse(historyData) : [] 10 11 let title = data.title.trim() 12 13 // ==================== æ ¸å¿å¤çï¼æ¸ çåç¼å¹¶æå num ==================== 14 title = cleanTitlePrefix(title) // å»é¤ [xxx] åç¼ 15 16 const num = extractProductNum(title) // æå产åç¼å· 17 const product = title.replace(num, '').trim() // å©ä½é¨åä½ä¸ºäº§ååç§° 18 19 cartData.push({ 20 num: num || title, // 产åç¼å·ï¼å»éå ³é®ï¼ 21 product: product || title, // 产ååç§° 22 feature: data.feature || '', 23 url: data.url || '', 24 img: data.img || '', 25 qty: 1, 26 unit: 'lb', 27 originalTitle: data.title, // ä¿ååå§æ é¢ï¼å¯éï¼ 28 }) 29 30 // æ num å»éï¼æ¨èä½¿ç¨ num å»éï¼æ´ç²¾ç¡®ï¼ 31 const res = cartData.reduce((all, next) => { 32 if (all.some((item) => item.num === next.num)) { 33 return all 34 } 35 return [...all, next] 36 }, []) 37 38 localStorage.setItem('sam-cart', JSON.stringify(res)) 39 refreshCart() 40} 41 42/** æ¸ çåç¼ [trans sam_in] ç */ 43function cleanTitlePrefix(title) { 44 // ç§»é¤å¼å¤´ç [ä»»æå 容] æ (ä»»æå 容) 45 return title.replace(/^\s*[\[\(].*?[\]\)]\s*/i, '').trim() 46} 47 48/** æå产åç¼å· */ 49function extractProductNum(title) { 50 if (!title) return '' 51 52 // ä¼å å¹é è§åï¼å¯ç»§ç»æ©å±ï¼ 53 const patterns = [ 54 /\b(PI\d{4,})\b/i, // PI15186 55 /\b([A-Z]{2,5}\d{4,10})\b/, // å ¶ä»åå·å¦ CASåé¢ç忝æ°å 56 /\b(\d{5,7}-\d{2,4}-\d{1,2})\b/, // CAS å· 57 ] 58 59 for (let regex of patterns) { 60 const match = title.match(regex) 61 if (match) { 62 return match[1] ? match[1].trim() : match[0].trim() 63 } 64 } 65 66 // å¤ç¨ï¼å第ä¸ä¸ªçèµ·æ¥åç¼å·çè¯ 67 const words = title.split(/\s+/) 68 for (let word of words) { 69 if (word.length > 3 && /[A-Z0-9]/.test(word)) { 70 return word 71 } 72 } 73 74 return '' 75} 76// å·æ°åæ¥è´ç©è½¦äº§åä¿¡æ¯ 77function refreshCart() { 78 // éè¦å°ç¼åä¸ç产åä¿¡æ¯æ¿è¿æ¥ç¶åè¿è¡æ¼æ¥è¿½å 79 var historyData = localStorage.getItem('sam-cart') 80 var cartData = JSON.parse(historyData) || [] 81 var len = cartData.length 82 if (parseInt(len) > 0) { 83 document.getElementsByClassName('cart-number-icon')[0].innerHTML = len 84 document.getElementsByClassName('cart-number-icon')[1].innerHTML = len 85 } else { 86 document.getElementsByClassName('cart-number-icon')[0].innerHTML = 0 87 document.getElementsByClassName('cart-number-icon')[1].innerHTML = 0 88 } 89} 90// 宿¶å·æ°è´ç©è½¦ 91var cartIntval = setInterval(function () { 92 refreshCart() 93}, 500) 94// clearInterval(cartIntval) 95 96//询ç 97$(document).ready(function () { 98 var $homeModal = $('.oc-main-sam-modal-home') 99 var homeCaptchaTries = 0 100 var homeRecaptchaApiLoading = false 101 102 function getHomeRecaptchaResponse() { 103 var box = document.getElementById('recaptcha-box-home') 104 if (!box) { 105 return '' 106 } 107 var ta = box.querySelector('textarea.g-recaptcha-response') 108 if (ta && ta.value) { 109 return ta.value 110 } 111 var id = box.getAttribute('data-widget-id') 112 if (id !== null && id !== '' && typeof grecaptcha !== 'undefined' && typeof grecaptcha.getResponse === 'function') { 113 try { 114 return grecaptcha.getResponse(Number(id)) || '' 115 } catch (e) { 116 return '' 117 } 118 } 119 return '' 120 } 121 122 function homeCaptchaIframeOk(box) { 123 var iframe = box.querySelector('iframe') 124 return !!(iframe && iframe.offsetWidth > 0 && iframe.offsetHeight > 0) 125 } 126 127 function remountHomeCaptchaHost(box) { 128 var host = document.createElement('div') 129 host.className = 'recaptcha-widget-host' 130 box.innerHTML = '' 131 box.appendChild(host) 132 box.removeAttribute('data-widget-id') 133 return host 134 } 135 136 function renderHomeCaptcha(force) { 137 var box = document.getElementById('recaptcha-box-home') 138 if (!box) { 139 return true 140 } 141 if (!force && (box.getAttribute('data-widget-id') !== null || homeCaptchaIframeOk(box)
141)) { 142 return true 143 } 144 if (typeof grecaptcha === 'undefined' || typeof grecaptcha.render !== 'function') { 145 return false 146 } 147 var host = box.querySelector('.recaptcha-widget-host') 148 if (!host || force || host.querySelector('iframe')) { 149 host = remountHomeCaptchaHost(box) 150 } 151 try { 152 var widgetId = grecaptcha.render(host, { 153 sitekey: box.getAttribute('data-sitekey'), 154 }) 155 box.setAttribute('data-widget-id', String(widgetId)) 156 return true 157 } catch (e) { 158 return homeCaptchaIframeOk(box) 159 } 160 } 161 162 function waitAndRenderHomeCaptcha(force) { 163 var run = function () { 164 var box = document.getElementById('recaptcha-box-home') 165 if (!box) { 166 return 167 } 168 if (!$homeModal.hasClass('is-open') || !$homeModal.is(':visible')) { 169 homeCaptchaTries += 1 170 if (homeCaptchaTries > 50) { 171 return 172 } 173 setTimeout(function () { 174 waitAndRenderHomeCaptcha(force) 175 }, 80) 176 return 177 } 178 if (renderHomeCaptcha(!!force)) { 179 return 180 } 181 if ( 182 !homeRecaptchaApiLoading && 183 (typeof grecaptcha === 'undefined' || typeof grecaptcha.render !== 'function') 184 ) { 185 homeRecaptchaApiLoading = true 186 $.getScript('https://www.google.com/recaptcha/api.js?hl=es').always(function () { 187 homeRecaptchaApiLoading = false 188 setTimeout(function () { 189 waitAndRenderHomeCaptcha(force) 190 }, 100) 191 }) 192 return 193 } 194 homeCaptchaTries += 1 195 if (homeCaptchaTries > 50) { 196 return 197 } 198 setTimeout(function () { 199 waitAndRenderHomeCaptcha(force) 200 }, 200) 201 } 202 if (typeof grecaptcha !== 'undefined' && typeof grecaptcha.ready === 'function') { 203 grecaptcha.ready(run) 204 return 205 } 206 run() 207 } 208 209 $(document).on('click', '.open-modal-btn-home', function () { 210 $homeModal.css('display', 'block').addClass('is-open') 211 var box = document.getElementById('recaptcha-box-home') 212 if (box) { 213 remountHomeCaptchaHost(box) 214 homeCaptchaTries = 0 215 requestAnimationFrame(function () { 216 requestAnimationFrame(function () { 217 waitAndRenderHomeCaptcha(true) 218 }) 219 }) 220 } 221 }) 222 223 $(document).on('click', '.oc-main-sam-modal-home .close-modal-btn', function () { 224 $homeModal.css('display', 'none').removeClass('is-open') 225 }) 226 227 $(document).on('click', '.oc-main-sam-modal-home .modal-mask', function () { 228 $homeModal.css('display', 'none').removeClass('is-open') 229 }) 230 231 $('#submitMsg').on('click', function () { 232 if ($(this).hasClass('disable')) { 233 return false 234 } 235 let valid = validateForm([ 236 { 237 key: 'username', 238 value: $('#name-f').val(), 239 message: TextPrompt.name, 240 }, 241 { 242 key: 'email', 243 value: $('#email-f').val(), 244 message: TextPrompt.email, 245 }, 246 { 247 key: 'phone', 248 value: $('#phone-f').val(), 249 message: TextPrompt.phone, 250 }, 251 { 252 key: 'product', 253 value: $('#product-f').val(), 254 message: TextPrompt.productName, 255 }, 256 { 257 key: 'message', 258 value: $('#comments-f').val(), 259 message: TextPrompt.comment, 260 }, 261 { 262 required: typeof ENV !== 'undefined' && ENV.googleVerification, 263 key: 'robot', 264 value: getHomeRecaptchaResponse(), 265 message: TextPrompt.checkCode, 266 }, 267 ]) 268 $('#errorMessages').text(valid.message || '') 269 if (valid.isValid) { 270 $('#submitMsg').addClass('disable') 271 $.ajax({
272 url: Apis.Inquiry, 273 type: 'post', 274 data: { 275 website: 'sam_es', 276 product: valid.values.product, 277 email: valid.values.email, 278 username: valid.values.username, 279 message: valid.values.message, 280 phone: valid.values.phone, 281 traderemail: '[email protected]', 282 tracking: window.location.href, 283 referrer: document.referrer, 284 robot: valid.values.robot, 285 }, 286 success: function (res) { 287 if (res.code == '200') { 288 $('#successMessage').text(TextPrompt.success) 289 location.href = res.msg 290 } else { 291 $('#submitMsg').removeClass('disable') 292 $('#errorMessages').text(res.msg ? res.msg : TextPrompt.fail) 293 } 294 }, 295 }) 296 } 297 return true 298 }) 299}) 300 301var myDate = new Date() 302myDate.getFullYear() //è·åå½å年份(2ä½) 303var nowDomData = parseInt(document.getElementById('year').innerHTML) 304if (nowDomData < myDate.getFullYear()) { 305 document.getElementById('year').innerHTML = myDate.getFullYear() 306} 307 308// 忢æ¾ç¤ºéè 309function toggleFooterInfo(dom) { 310 // è·å h2 å ç´ 311 let h2Element = dom.parentElement 312 // è·å h2 å ç´ çä¸ä¸ä¸ªå å¼å ç´ ï¼å³ .oc-main-sam-lineï¼ 313 let lineElement = h2Element.nextElementSibling 314 // è·ååå²çº¿å ç´ çä¸ä¸ä¸ªå å¼å ç´ ï¼å³ .footer-info-showoff-boxï¼ 315 let footerInfoShowoffBox = lineElement.nextElementSibling 316 // è·å SVG å ç´ 317 let svgElement = dom.querySelector('svg') 318 if ( 319 footerInfoShowoffBox.style.height === '' || 320 footerInfoShowoffBox.style.height === '0px' || 321 parseInt(footerInfoShowoffBox.style.height) === 0 322 ) { 323 // 临æ¶è®¾ç½®ä¸º auto 以è·åèªç¶é«åº¦ 324 footerInfoShowoffBox.style.height = 'auto' 325 let autoHeight = footerInfoShowoffBox.scrollHeight 326 footerInfoShowoffBox.style.height = autoHeight + 'px' 327 // å±å¼æ¶ SVG æè½¬ 180° 328 svgElement.style.transform = 'rotate(180deg)' 329 } else { 330 footerInfoShowoffBox.style.height = '0px' 331 // æå æ¶ SVG åå½åæ · 332 svgElement.style.transform = 'rotate(0deg)' 333 } 334}
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.