PageSourceSearch

https://shop.sporecyte.com/wp-content/themes/twentytwentythree-child/script.js?ver=1770761057

js sporecyte.com collected 2026-10-05 07:01:49 UTC 5,372 bytes, 133 lines download raw bytes

1'use strict';
2
3function initializeForms() {
4    let forms = document.querySelectorAll('form.sporecyte-add-to-cart-button')
5
6    forms.forEach(form => {
7        form.dataset.product_id = form.querySelector('[name=add-to-cart]').value
8	
9	form.querySelector('.icon-container').innerHTML = `
10            <svg aria-hidden="true" class="e-font-icon-svg e-fas-shopping-cart" viewBox="0 0 576 512"
11                xmlns="http://www.w3.org/2000/svg">
12                <path
13                    d="M528.12 301.319l47.273-208C578.806 78.301 567.391 64 551.99 64H159.208l-9.166-44.81C147.758 8.021 137.93 0 126.529 0H24C10.745 0 0 10.745 0 24v16c0 13.255 10.745 24 24 24h69.883l70.248 343.435C147.325 417.1 136 435.222 136 456c0 30.928 25.072 56 56 56s56-25.072 56-56c0-15.674-6.447-29.835-16.824-40h209.647C430.447 426.165 424 440.326 424 456c0 30.928 25.072 56 56 56s56-25.072 56-56c0-22.172-12.888-41.332-31.579-50.405l5.517-24.276c3.413-15.018-8.002-29.319-23.403-29.319H218.117l-6.545-32h293.145c11.206 0 20.92-7.754 23.403-18.681z" />
14            </svg>
15        `;
16
17	if (form.dataset.noQuantity !== '') {
18		let quantityGroup = document.createElement('fieldset');
19
20		let decrementer = document.createElement('button')
21		decrementer.name = 'decrement'
22		decrementer.type = 'button';
23		decrementer.textContent = '–';
24		quantityGroup.appendChild(decrementer);
25
26		let quantity = document.createElement('input')
27		quantity.name = 'quantity'
28		quantity.type = 'text'
29		quantity.inputMode = 'numeric'
30		quantity.min = '1'
31		quantity.step = '1';
32		quantity.value = '1';
33		quantityGroup.appendChild(quantity);
34
35		let incrementer = document.createElement('button')
36		incrementer.name = 'increment'
37		incrementer.type = 'button';
38		incrementer.textContent = '+';
39		quantityGroup.appendChild(incrementer);
40
41		form.prepend(quantityGroup);
42
43		form.addEventListener('click', event => {
44		    if (event.target.name === 'increment') {
45			quantity.value = parseInt(quantity.value) + 1
46		    } else if (event.target.name === 'decrement') {
47			quantity.value = Math.max(parseInt(quantity.value) - 1, 1)
48		    }
49
50		    form.dataset.quantity = quantity.value
51		})
52	}
53
54
55        if (typeof fetch !== 'undefined' && typeof URL !== 'undefined' && typeof FormData !== 'undefined' && typeof window.wc_add_to_cart_params !== 'undefined') {
56            form.addEventListener('submit', event => {
57                event.preventDefault();
58
59                form.classList.remove('added');
60                form.classList.add('loading');
61                let originalLabel = form.querySelector('.label').textContent;
62                form.querySelector('.label').textContent = 'Adding…';
63
64                form.querySelectorAll('input, button, select, textarea').forEach(element => {
65                    element.disabled = true
66                });
67
68                let requestBody = new FormData();
69                for (const [key, value] of Object.entries(form.dataset)) {
70                    requestBody.set(key, value)
71                }
72
73                let targetUrl = wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'add_to_cart');
74		let minDelay = new Promise(resolve => setTimeout(resolve, 1500))
75                fetch(targetUrl, { method: 'POST', body: requestBody }).then(response => {
76                    if (response.ok) {
77                        return response.json();
78                    }
79                    return Promise.reject(response);
80                }).then(response => {
81                    if (!response) {
82                        return;
83                    }
84
85                    if (response.error && response.product_url) {
86                        window.location = response.product_url;
87                        return;
88                    }
89
90                    // Redirect to cart option
91                    if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') {
92                        window.location = wc_add_to_cart_params.cart_url;
93                        return;
94                    }
95			//
96		    // Trigger event so themes can refresh other areas.
97		    let $thisbutton = jQuery(form);
98			console.log($thisbutton);
99		    jQuery( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
100		    return;
101                }).then(() => {
102                    form.classList.add('added');
103                    form.querySelector('.label').textContent = 'Added!';
104		    return minDelay;
105                }).then(() => {
106                    form.classList.remove('loading');
107                    form.querySelector('.label').textContent = originalLabel;
108                    form.querySelectorAll('input, button, select, textarea').forEach(element => {
109                        element.disabled = false;
110                    });
111                })
112            })
113        }
114    })
115}
116
117
118if (document.readyState === "loading") {
119    // Loading hasn't finished yet
120    document.addEventListener("DOMContentLoaded", initializeForms);
121} else {
122    // `DOMContentLoaded` has already fired
123    initializeForms();
124}
125document.addEventListener('DOMContentLoaded', function () {
126    const notices = document.querySelectorAll('.woocommerce-mini-cart .woocommerce-message');
127    notices.forEach(function(notice) {
128        if (notice.textContent.includes('removed from your cart')) {
129            notice.remove();
130        }
131    });
132});
133

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.