Download tasks/curology/environment/reference/clone/static/app.js from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 13 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/curology/environment/reference/clone/static/app.js
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/curology/environment/reference/clone/static/app.js
-
curl -L -o app.js https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/curology/environment/reference/clone/static/app.js
13 kB
| (() => { | |
| const key = () => `web-${Date.now()}-${Math.random().toString(16).slice(2)}`; | |
| document.querySelectorAll('[data-idempotency]').forEach((input) => { | |
| if (!input.value) input.value = key(); | |
| }); | |
| const toast = (message) => { | |
| const node = document.querySelector('#toast'); | |
| if (!node) return; | |
| node.textContent = message; | |
| node.classList.add('visible'); | |
| window.setTimeout(() => node.classList.remove('visible'), 3500); | |
| }; | |
| const errorMessage = (detail) => { | |
| if (typeof detail === 'string' && detail.trim()) return detail; | |
| if (Array.isArray(detail)) { | |
| const messages = detail | |
| .map((item) => (item && typeof item.msg === 'string' ? item.msg : '')) | |
| .filter(Boolean); | |
| if (messages.length) return messages.join(' '); | |
| } | |
| return 'Check the required information and try again.'; | |
| }; | |
| document.querySelectorAll('form[data-api]').forEach((form) => { | |
| form.addEventListener('submit', async (event) => { | |
| event.preventDefault(); | |
| const button = form.querySelector('button[type="submit"]'); | |
| const error = form.querySelector('[data-error]'); | |
| if (error) error.textContent = ''; | |
| if (button) button.disabled = true; | |
| const payload = Object.fromEntries(new FormData(form).entries()); | |
| if (payload.quantity) payload.quantity = Number(payload.quantity); | |
| try { | |
| const response = await fetch(form.dataset.api, { | |
| method: 'POST', | |
| headers: {'Content-Type': 'application/json'}, | |
| body: JSON.stringify(payload), | |
| }); | |
| const data = await response.json(); | |
| if (!response.ok) throw new Error(errorMessage(data.detail)); | |
| if (data.local_preview_code) { | |
| const code = document.querySelector('#local-code'); | |
| if (code) code.textContent = `Local-only code: ${data.local_preview_code}`; | |
| } | |
| if (form.dataset.reveal) { | |
| const panel = document.getElementById(form.dataset.reveal); | |
| if (panel) { | |
| panel.hidden = false; | |
| const focusTarget = panel.querySelector('input:not([type="hidden"]), button, [tabindex]:not([tabindex="-1"])'); | |
| if (focusTarget) focusTarget.focus(); | |
| } | |
| } | |
| if (form.dataset.clear !== undefined) form.reset(); | |
| toast(data.message || 'Saved locally'); | |
| if (form.dataset.reload !== undefined) window.location.reload(); | |
| else if (data.redirect) window.location.assign(data.redirect); | |
| else if (form.dataset.redirect) window.location.assign(form.dataset.redirect); | |
| else if (form.dataset.successRedirect && data.ok) window.location.assign(form.dataset.successRedirect); | |
| } catch (caught) { | |
| if (error) error.textContent = caught.message; | |
| toast(caught.message); | |
| const idempotency = form.querySelector('[data-idempotency]'); | |
| if (idempotency) idempotency.value = key(); | |
| } finally { | |
| if (button) button.disabled = false; | |
| } | |
| }); | |
| }); | |
| const menu = document.querySelector('.menu-button'); | |
| const nav = document.querySelector('#primary-nav'); | |
| if (menu && nav) menu.addEventListener('click', () => { | |
| const open = nav.classList.toggle('open'); | |
| menu.setAttribute('aria-expanded', String(open)); | |
| }); | |
| const closeNavMenus = (except = null) => { | |
| document.querySelectorAll('.nav-trigger[aria-expanded="true"]').forEach((trigger) => { | |
| if (trigger === except) return; | |
| trigger.setAttribute('aria-expanded', 'false'); | |
| const panel = document.getElementById(trigger.getAttribute('aria-controls')); | |
| if (panel) panel.classList.remove('open'); | |
| }); | |
| }; | |
| document.querySelectorAll('.nav-trigger').forEach((trigger) => { | |
| trigger.addEventListener('click', (event) => { | |
| event.stopPropagation(); | |
| const willOpen = trigger.getAttribute('aria-expanded') !== 'true'; | |
| closeNavMenus(trigger); | |
| trigger.setAttribute('aria-expanded', String(willOpen)); | |
| const panel = document.getElementById(trigger.getAttribute('aria-controls')); | |
| if (panel) panel.classList.toggle('open', willOpen); | |
| }); | |
| }); | |
| document.addEventListener('click', (event) => { | |
| if (!event.target.closest('.has-menu')) closeNavMenus(); | |
| }); | |
| document.addEventListener('keydown', (event) => { | |
| if (event.key !== 'Escape') return; | |
| const active = document.querySelector('.nav-trigger[aria-expanded="true"]'); | |
| closeNavMenus(); | |
| if (active) active.focus(); | |
| }); | |
| const cartKey = 'curology-local-bag-v1'; | |
| const readCart = () => { | |
| try { | |
| const value = JSON.parse(localStorage.getItem(cartKey) || '[]'); | |
| return Array.isArray(value) ? value.filter((item) => item && item.id) : []; | |
| } catch (_) { | |
| return []; | |
| } | |
| }; | |
| let cart = readCart(); | |
| const cartDrawer = document.querySelector('#cart-drawer'); | |
| const cartScrim = document.querySelector('.cart-scrim'); | |
| const cartItems = document.querySelector('[data-cart-items]'); | |
| const formatMoney = (value) => `$${Number(value).toFixed(2)}`; | |
| const saveCart = () => { | |
| localStorage.setItem(cartKey, JSON.stringify(cart)); | |
| }; | |
| const renderCart = () => { | |
| const count = cart.reduce((total, item) => total + item.quantity, 0); | |
| document.querySelectorAll('[data-cart-count]').forEach((node) => { | |
| node.textContent = String(count); | |
| const button = node.closest('[data-cart-toggle]'); | |
| if (button) button.setAttribute('aria-label', `Shopping bag, ${count} item${count === 1 ? '' : 's'}`); | |
| }); | |
| const total = cart.reduce((sum, item) => sum + item.price * item.quantity, 0); | |
| const totalNode = document.querySelector('[data-cart-total]'); | |
| if (totalNode) totalNode.textContent = formatMoney(total); | |
| if (!cartItems) return; | |
| cartItems.replaceChildren(); | |
| if (!cart.length) { | |
| const empty = document.createElement('p'); | |
| empty.textContent = 'Your bag is empty.'; | |
| cartItems.append(empty); | |
| return; | |
| } | |
| cart.forEach((item) => { | |
| const row = document.createElement('article'); | |
| row.className = 'cart-row'; | |
| const copy = document.createElement('div'); | |
| const title = document.createElement('b'); | |
| title.textContent = item.name; | |
| const price = document.createElement('span'); | |
| price.textContent = formatMoney(item.price); | |
| copy.append(title, price); | |
| const controls = document.createElement('div'); | |
| controls.className = 'cart-row-controls'; | |
| [['−', -1], [String(item.quantity), 0], ['+', 1]].forEach(([label, delta]) => { | |
| if (!delta) { | |
| const output = document.createElement('span'); | |
| output.textContent = label; | |
| controls.append(output); | |
| return; | |
| } | |
| const button = document.createElement('button'); | |
| button.type = 'button'; | |
| button.textContent = label; | |
| button.dataset.cartDelta = String(delta); | |
| button.dataset.cartId = item.id; | |
| button.setAttribute('aria-label', delta > 0 ? `Add one ${item.name}` : `Remove one ${item.name}`); | |
| controls.append(button); | |
| }); | |
| row.append(copy, controls); | |
| cartItems.append(row); | |
| }); | |
| }; | |
| const openCart = () => { | |
| renderCart(); | |
| if (cartDrawer) cartDrawer.hidden = false; | |
| if (cartScrim) cartScrim.hidden = false; | |
| document.body.classList.add('cart-open'); | |
| const close = cartDrawer && cartDrawer.querySelector('[data-cart-close]'); | |
| if (close) close.focus(); | |
| }; | |
| const closeCart = () => { | |
| if (cartDrawer) cartDrawer.hidden = true; | |
| if (cartScrim) cartScrim.hidden = true; | |
| document.body.classList.remove('cart-open'); | |
| }; | |
| document.querySelectorAll('[data-cart-toggle]').forEach((button) => button.addEventListener('click', openCart)); | |
| document.querySelectorAll('[data-cart-close]').forEach((button) => button.addEventListener('click', closeCart)); | |
| document.querySelectorAll('[data-cart-add]').forEach((button) => button.addEventListener('click', () => { | |
| const quantityNode = button.closest('.detail-copy')?.querySelector('[data-quantity]'); | |
| const quantity = Math.max(1, Number(quantityNode?.textContent || 1)); | |
| const existing = cart.find((item) => item.id === button.dataset.cartAdd); | |
| if (existing) existing.quantity += quantity; | |
| else cart.push({id: button.dataset.cartAdd, name: button.dataset.productName, price: Number(button.dataset.productPrice), quantity}); | |
| saveCart(); | |
| toast(`${button.dataset.productName} added to your local bag`); | |
| openCart(); | |
| })); | |
| if (cartItems) cartItems.addEventListener('click', (event) => { | |
| const button = event.target.closest('[data-cart-delta]'); | |
| if (!button) return; | |
| const item = cart.find((candidate) => candidate.id === button.dataset.cartId); | |
| if (!item) return; | |
| item.quantity += Number(button.dataset.cartDelta); | |
| cart = cart.filter((candidate) => candidate.quantity > 0); | |
| saveCart(); | |
| renderCart(); | |
| }); | |
| const clearCart = document.querySelector('[data-cart-clear]'); | |
| if (clearCart) clearCart.addEventListener('click', () => { cart = []; saveCart(); renderCart(); }); | |
| renderCart(); | |
| const quantityOutput = document.querySelector('[data-quantity]'); | |
| const updateQuantity = (delta) => { | |
| if (!quantityOutput) return; | |
| quantityOutput.textContent = String(Math.min(9, Math.max(1, Number(quantityOutput.textContent) + delta))); | |
| }; | |
| const decrement = document.querySelector('[data-quantity-decrement]'); | |
| const increment = document.querySelector('[data-quantity-increment]'); | |
| if (decrement) decrement.addEventListener('click', () => updateQuantity(-1)); | |
| if (increment) increment.addEventListener('click', () => updateQuantity(1)); | |
| document.querySelectorAll('[data-product-image]').forEach((thumb) => thumb.addEventListener('click', () => { | |
| const image = document.querySelector('.product-photo'); | |
| if (image) image.src = thumb.dataset.productImage; | |
| document.querySelectorAll('[data-product-image]').forEach((item) => item.classList.toggle('selected', item === thumb)); | |
| })); | |
| document.querySelectorAll('[data-concern-tab]').forEach((tab) => tab.addEventListener('click', () => { | |
| document.querySelectorAll('[data-concern-tab]').forEach((item) => item.setAttribute('aria-selected', String(item === tab))); | |
| document.querySelectorAll('[data-concern-panel]').forEach((panel) => panel.classList.toggle('active', panel.dataset.concernPanel === tab.dataset.concernTab)); | |
| })); | |
| let reviewsExpanded = false; | |
| let reviewFilter = 'all'; | |
| const renderReviews = () => { | |
| document.querySelectorAll('[data-review-card]').forEach((card) => { | |
| const categoryMatches = reviewFilter === 'all' || card.dataset.reviewCard === reviewFilter; | |
| const expansionMatches = reviewsExpanded || !card.classList.contains('review-extra'); | |
| card.hidden = !(categoryMatches && expansionMatches); | |
| }); | |
| }; | |
| document.querySelectorAll('[data-review-filter]').forEach((button) => button.addEventListener('click', () => { | |
| reviewFilter = button.dataset.reviewFilter; | |
| document.querySelectorAll('[data-review-filter]').forEach((item) => item.classList.toggle('active', item === button)); | |
| renderReviews(); | |
| })); | |
| const reviewMore = document.querySelector('[data-review-more]'); | |
| if (reviewMore) reviewMore.addEventListener('click', () => { | |
| reviewsExpanded = !reviewsExpanded; | |
| reviewMore.textContent = reviewsExpanded ? 'Show fewer' : 'View more'; | |
| renderReviews(); | |
| }); | |
| const banner = document.querySelector('#cookie-banner'); | |
| const cookieOptions = [...document.querySelectorAll('[data-cookie-option]')]; | |
| const existingCookieChoice = localStorage.getItem('curology-cookie-choice'); | |
| if (banner && !existingCookieChoice) banner.hidden = false; | |
| if (existingCookieChoice) { | |
| try { | |
| const stored = JSON.parse(existingCookieChoice); | |
| cookieOptions.forEach((input) => { input.checked = Boolean(stored[input.dataset.cookieOption]); }); | |
| } catch (_) { | |
| // Legacy string choices remain valid as essential-only preferences. | |
| } | |
| } | |
| document.querySelectorAll('[data-cookie]').forEach((button) => button.addEventListener('click', () => { | |
| const choice = button.dataset.cookie; | |
| if (choice === 'all') cookieOptions.forEach((input) => { input.checked = true; }); | |
| if (choice === 'essential') cookieOptions.forEach((input) => { input.checked = false; }); | |
| const preferences = Object.fromEntries(cookieOptions.map((input) => [input.dataset.cookieOption, input.checked])); | |
| localStorage.setItem('curology-cookie-choice', JSON.stringify(preferences)); | |
| if (banner) banner.hidden = true; | |
| })); | |
| document.querySelectorAll('[data-manage-cookies]').forEach((button) => button.addEventListener('click', () => { | |
| if (banner) { | |
| banner.hidden = false; | |
| banner.querySelector('button')?.focus(); | |
| } | |
| })); | |
| document.querySelectorAll('[data-social]').forEach((button) => button.addEventListener('click', () => { | |
| toast(`${button.dataset.social} is external and stays closed in this offline clone.`); | |
| })); | |
| })(); | |