PageSourceSearch

https://vapingcheap.com/wp-content/plugins/wp-coupon-deals/assets/js/frontend.js?ver=1.12.0

js vapingcheap.com collected 2026-10-02 12:41:11 UTC 12,750 bytes, 316 lines download raw bytes

1(function () {
2	function ajax(action, data) {
3		var body = new URLSearchParams(Object.assign({ action: action }, data));
4		return fetch(WCD.ajaxUrl, {
5			method: 'POST',
6			headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
7			body: body.toString()
8		}).then(function (r) { return r.json(); });
9	}
10
11	/* ---------------- Interstitial popup ---------------- */
12	var modalEl = null;
13
14	function closeModal() {
15		if (!modalEl) return;
16		modalEl.hidden = true;
17		document.body.classList.remove('wcd-modal-open');
18	}
19
20	function getModal() {
21		if (modalEl) return modalEl;
22		modalEl = document.createElement('div');
23		modalEl.id = 'wcd-interstitial';
24		modalEl.className = 'wcd-modal-overlay';
25		modalEl.hidden = true;
26		modalEl.innerHTML =
27			'<div class="wcd-modal" role="dialog" aria-modal="true">' +
28			'<button type="button" class="wcd-modal-close" aria-label="Close">&times;</button>' +
29			'<div class="wcd-modal-brand"></div>' +
30			'<h3 class="wcd-modal-title"></h3>' +
31			'<div class="wcd-modal-code-box" hidden><span class="wcd-modal-code"></span><button type="button" class="wcd-modal-copy">Copy</button></div>' +
32			'<p class="wcd-modal-hint"></p>' +
33			'<a class="wcd-modal-continue" target="_blank" rel="nofollow sponsored noopener">Continue to Store &rarr;</a>' +
34			'<div class="wcd-modal-verify-slot"></div>' +
35			'<div class="wcd-modal-social-slot"></div>' +
36			'</div>';
37		document.body.appendChild(modalEl);
38
39		modalEl.addEventListener('click', function (e) { if (e.target === modalEl) closeModal(); });
40		modalEl.querySelector('.wcd-modal-close').addEventListener('click', closeModal);
41		modalEl.querySelector('.wcd-modal-copy').addEventListener('click', function () {
42			var code = modalEl.querySelector('.wcd-modal-code').textContent;
43			if (navigator.clipboard) { navigator.clipboard.writeText(code).catch(function () {}); }
44			this.textContent = 'Copied!';
45		});
46		document.addEventListener('keydown', function (e) {
47			if (e.key === 'Escape' && modalEl && !modalEl.hidden) { closeModal(); }
48		});
49		return modalEl;
50	}
51
52	function openInterstitial(card, code, url) {
53		if (!card) return;
54		var modal = getModal();
55
56		var brandText = '';
57		var brandEl = card.querySelector('.wcd-brand');
58		if (brandEl) {
59			var clone = brandEl.cloneNode(true);
60			var teaser = clone.querySelector('.wcd-brand-teaser');
61			if (teaser) { teaser.remove(); }
62			brandText = clone.textContent.trim();
63		}
64		modal.querySelector('.wcd-modal-brand').textContent = brandText;
65
66		var titleEl = card.querySelector('.wcd-title');
67		modal.querySelector('.wcd-modal-title').textContent = titleEl ? titleEl.textContent : '';
68
69		var codeBox = modal.querySelector('.wcd-modal-code-box');
70		if (code) {
71			modal.querySelector('.wcd-modal-code').textContent = code;
72			modal.querySelector('.wcd-modal-copy').textContent = 'Copy';
73			codeBox.hidden = false;
74		} else {
75			codeBox.hidden = true;
76		}
77
78		var hint = modal.querySelector('.wcd-modal-hint');
79		var continueLink = modal.querySelector('.wcd-modal-continue');
80		if (url) {
81			var domain = url;
82			try { domain = new URL(url).hostname.replace(/^www\./, ''); } catch (err) {}
83			hint.textContent = 'Opening ' + domain + ' in a new tab...';
84			continueLink.href = url;
85			continueLink.style.display = '';
86		} else {
87			hint.textContent = '';
88			continueLink.style.display = 'none';
89		}
90
91		var verifySlot = modal.querySelector('.wcd-modal-verify-slot');
92		verifySlot.innerHTML = '';
93		var verifyEl = card.querySelector('.wcd-verify');
94		if (verifyEl) { verifySlot.appendChild(verifyEl.cloneNode(true)); }
95
96		var socialSlot = modal.querySelector('.wcd-modal-social-slot');
97		socialSlot.innerHTML = '';
98		var socialEl = card.querySelector('.wcd-social');
99		if (socialEl) { socialSlot.appendChild(socialEl.cloneNode(true)); }
100
101		modal.hidden = false;
102		document.body.classList.add('wcd-modal-open');
103	}
104
105	/* ---------------- Click delegation ---------------- */
106	document.addEventListener('click', function (e) {
107		var revealBtn = e.target.closest('.wcd-reveal-btn');
108		if (revealBtn) {
109			e.preventDefault();
110			var card = revealBtn.closest('.wcd-card');
111
112			if (revealBtn.classList.contains('revealed')) {
113				// Already revealed (e.g. "always visible" mode) - clicking again just acts.
114				var maskedEl = revealBtn.querySelector('.wcd-code-masked');
115				var codeNow = maskedEl ? maskedEl.textContent : '';
116				var urlNow = revealBtn.dataset.url;
117				if (navigator.clipboard) { navigator.clipboard.writeText(codeNow).catch(function () {}); }
118				if (WCD.interstitial) {
119					openInterstitial(card, codeNow, urlNow);
120					if (urlNow) { window.open(urlNow, '_blank'); }
121				} else if (urlNow) {
122					window.open(urlNow, '_blank');
123				}
124				return;
125			}
126
127			var id = revealBtn.dataset.id, nonce = revealBtn.dataset.nonce;
128			// Open a blank tab synchronously, within this click handler, so the
129			// browser doesn't block window.open() once the AJAX response 
129(async)
130			// comes back and we know the real URL.
131			var newTab = WCD.interstitial ? window.open('', '_blank') : null;
132
133			ajax('wcd_reveal_code', { post_id: id, nonce: nonce }).then(function (res) {
134				if (!res.success) { if (newTab) { newTab.close(); } return; }
135				var codeEl = revealBtn.querySelector('.wcd-code-masked');
136				var labelEl = revealBtn.querySelector('.wcd-reveal-label');
137				if (codeEl) codeEl.textContent = res.data.code;
138				if (labelEl) labelEl.textContent = 'Copied!';
139				revealBtn.classList.add('revealed');
140				if (navigator.clipboard) { navigator.clipboard.writeText(res.data.code).catch(function () {}); }
141
142				if (WCD.interstitial) {
143					if (newTab) {
144						if (res.data.url) { newTab.location.href = res.data.url; } else { newTab.close(); }
145					}
146					openInterstitial(card, res.data.code, res.data.url);
147				} else if (res.data.url) {
148					setTimeout(function () { window.open(res.data.url, '_blank'); }, 400);
149				}
150			});
151			return;
152		}
153
154		var dealBtn = e.target.closest('.wcd-deal-btn');
155		if (dealBtn) {
156			var did = dealBtn.dataset.id, dnonce = dealBtn.dataset.nonce;
157
158			if (!WCD.interstitial) {
159				if (did && dnonce) { ajax('wcd_track_click', { post_id: did, nonce: dnonce }); }
160				return; // allow the normal target="_blank" anchor navigation
161			}
162
163			e.preventDefault();
164			var dealUrl = dealBtn.getAttribute('href');
165			var dealCard = dealBtn.closest('.wcd-card');
166			var dealTab = window.open('', '_blank'); // synchronous, within this click handler
167			if (did && dnonce) { ajax('wcd_track_click', { post_id: did, nonce: dnonce } ); }
168			if (dealTab) { dealTab.location.href = dealUrl; }
169			openInterstitial(dealCard, null, dealUrl);
170			return;
171		}
172
173		var toggle = e.target.closest('.wcd-details-toggle');
174		if (toggle) {
175			e.preventDefault();
176			toggle.classList.toggle('open');
177			var panel = toggle.closest('.wcd-card').querySelector('.wcd-details-panel');
178			if (panel) { panel.classList.toggle('open'); }
179			return;
180		}
181
182		var verifyBtn = e.target.closest('.wcd-verify-yes, .wcd-verify-no');
183		if (verifyBtn) {
184			e.preventDefault();
185			var wrap = verifyBtn.closest('.wcd-verify');
186			if (wrap.classList.contains('voted')) return;
187			var vote = verifyBtn.dataset.vote;
188			ajax('wcd_verify_vote', { post_id: wrap.dataset.id, nonce: wrap.dataset.nonce, vote: vote }).then(function (res) {
189				wrap.classList.add('voted');
190				var label = wrap.querySelector('.wcd-verify-label');
191				var text = res.success ? (res.data.rate + '% worked (' + res.data.total + ')') : ((res.data && res.data.message) || 'Thanks!');
192				if (label) { label.textContent = text; }
193				// Keep any other copy of this same coupon's verify widget in sync
194				// (e.g. the card behind an open interstitial modal).
195				document.querySelectorAll('.wcd-verify[data-id="' + wrap.dataset.id + '"]').forEach(function (other) {
196					if (other === wrap) return;
197					other.classList.add('voted');
198					var otherLabel = other.querySelector('.wcd-verify-label');
199					if (otherLabel) { otherLabel.textContent = text; }
200				});
201			});
202			return;
203		}
204
205		var shareBtn = e.target.closest('.wcd-share-btn');
206		if (shareBtn) {
207			e.preventDefault();
208			var network = shareBtn.dataset.network, url = shareBtn.dataset.url, title = shareBtn.dataset.title;
209			var shareUrls = {
210				facebook: 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(url),
211				twitter: 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(url) + '&text=' + encodeURIComponent(title),
212				whatsapp: 'https://wa.me/?text=' + encodeURIComponent(title + ' ' + url),
213				email: 'mailto:?subject=' + encodeURIComponent(title) + '&body=' + encodeURIComponent(url)
214			};
215			if (network === 'copy') {
216				if (navigator.clipboard) { navigator.clipboard.writeText(url); }
217				shareBtn.setAttribute('aria-label', 'Copied!');
218			} else if (shareUrls[network]) {
219				window.open(shareUrls[network], '_blank', 'width=600,height=400');
220			}
221			return;
222		}
223
224		var notesToggle = e.target.closest('.wcd-notes-toggle');
225		if (notesToggle) {
226			e.preventDefault();
227			notesToggle.closest('.wcd-notes').classList.toggle('open');
228		}
229	});
230
231	function showMsg(el, text, isError) {
232		if (!el) return;
233		el.textContent = text;
234		el.hidden = false;
235		el.classList.toggle('wcd-msg-error', !!isError);
236	}
237
238	document.addEventListener('submit', function (e) {
239		var noteForm = e.target.closest('.wcd-note-form');
240		if (noteForm) {
241			e.preventDefault();
242			var msg = noteForm.querySelector('.wcd-note-msg');
243			var submitBtn = noteForm.querySelector('.wcd-note-submit');
244			submitBtn.disabled = true;
245			ajax('wcd_submit_note', {
246				post_id: noteForm.dataset.id,
247				nonce: noteForm.dataset.nonce,
248				author_name: noteForm.author_name.value,
249				comment_content: noteForm.comment_content.value,
250				wcd_hp: noteForm.wcd_hp.value
251			}).then(function (res) {
252				submitBtn.disabled = false;
253				if (!res.success) { showMsg(msg, (res.data && res.data.message) || 'Something went wrong.', true); return; }
254				if (res.data.approved) {
255					var list = noteForm.closest('.wcd-notes').querySelector('.wcd-notes-list');
256					var empty = list.querySelector('.wcd-empty');
257					if (empty) empty.remove();
258					var div = document.createElement('div');
259					div.className = 'wcd-note';
260					div.innerHTML = '<strong class="wcd-note-author"></strong> <span class="wcd-note-date"></span><p class="wcd-note-body"></p>';
261					div.querySelector('.wcd-note-author').textContent = res.data.author;
262					div.querySelector('.wcd-note-date').textContent = res.data.date;
263					div.querySelector('.wcd-note-body').textContent = res.data.content;
264					list.insertBefore(div, list.firstChild);
265					showMsg(msg, 'Posted!', false);
266				} else {
267					showMsg(msg, res.data.message || 'Thanks!', false);
268				}
269				noteForm.reset();
270			});
271			return;
272		}
273
274		var reviewForm = e.target.closest('.wcd-review-form');
275		if (reviewForm) {
276			e.preventDefault();
277			var rmsg = reviewForm.querySelector('.wcd-review-msg');
278			var rBtn = reviewForm.querySelector('.wcd-review-submit');
279			var ratingInput = reviewForm.querySelector('input[name="rating"]:checked');
280			if (!ratingInput) { showMsg(rmsg, 'Please choose a star rating.', true); return; }
281			rBtn.disabled = true;
282			ajax('wcd_submit_brand_review', {
283				term_id: reviewForm.dataset.termId,
284				nonce: reviewForm.dataset.nonce,
285				author_name: reviewForm.author_name.value,
286				review_text: reviewForm.review_text.value,
287				rating: ratingInput.value,
288				wcd_hp: reviewForm.wcd_hp.value
289			}).then(function (res) {
290				rBtn.disabled = false;
291				if (!res.success) { showMsg(rmsg, (res.data && res.data.message) || 'Something went wrong.', true); return; }
292				if (res.data.approved) {
293					var wrap = document.querySelector('.wcd-brand-reviews[data-term-id="' + reviewForm.dataset.termId + '"]');
294					if (wrap) {
295						var list = wrap.querySelector('.wcd-brand-reviews-list');
296						var empty = list.querySelector('.wcd-empty');
297						if (empty) empty.remove();
298						var div = document.createElement('div');
299						div.className = 'wcd-review';
300						var stars = '★'.repeat(res.data.rating) + '☆'.repeat(5 - res.data.rating);
301						div.innerHTML = '<div class="wcd-review-head"><strong class="wcd-review-author"></strong> <span class="wcd-stars"></span> <span class="wcd-review-date"></span></div><p class="wcd-review-body"></p>';
302						div.querySelector('.wcd-review-author').textContent = res.data.author;
303						div.querySelector('.wcd-stars').textContent = stars;
304						div.querySelector('.wcd-review-date').textContent = res.data.date;
305						div.querySelector('.wcd-review-body').textContent = res.data.text;
306						list.insertBefore(div, list.firstChild);
307					}
308					showMsg(rmsg, 'Thanks for your tip!', false);
309				} else {
310					showMsg(rmsg, res.data.message || 'Thanks!', false);
311				}
312				reviewForm.reset();
313			});
314		}
315	});
316})();

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.