PageSourceSearch

https://www.samaterials.es/js/footer.js?v=1789002534

js samaterials.es collected 2026-10-02 20:45:44 UTC 10,232 bytes, 334 lines download raw bytes

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.