PageSourceSearch

https://www.eprice.com.hk/js/web/common.trigger.js?v=202707141738

js eprice.com.hk collected 2026-10-02 04:06:48 UTC 23,348 bytes, 733 lines download raw bytes

1$(function () {
2	$.Parser = (typeof $.Parser == 'undefined') ? {} : $.Parser;
3	$.Parser.numberWithCommas = function (x) {
4		return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
5	};
6	$.Parser.parseInt = function (x) {
7		if (typeof x === 'string') {
8			x = x.replace(',', '');
9		}
10		return parseInt(x, 10);
11	};
12	$.Api = (typeof $.Api == 'undefined') ? {} : $.Api;
13	$.Api.Compare = (typeof $.Api.Compare == 'undefined') ? {} : $.Api.Compare;
14	$.Api.Compare.List = (typeof $.Api.Compare.List == 'undefined') ? {} : $.Api.Compare.List;
15	$.Api.Compare.List.updateData = function (a, t) {
16		$.Api.sendRequest({
17			url: "/api/web/compare/update",
18			data: a,
19			type: "POST"
20		}, t);
21	};
22	$.Api.Compare.List.removeData = function (a, t) {
23		$.Api.sendRequest({
24			url: "/api/web/compare/remove",
25			data: a,
26			type: "POST"
27		}, t);
28	};
29	$.Api.Compare.List = (typeof $.Api.Compare.List == 'undefined') ? {} : $.Api.Compare.List;
30	$.Api.Compare.List.loadData = function (a, t) {
31		$.Api.sendRequest({
32			url: "/api/web/compare/list",
33			data: a,
34			type: "GET"
35		}, t);
36	};
37	$.Api.Compare.Product = (typeof $.Api.Compare.Product == 'undefined') ? {} : $.Api.Compare.Product;
38	$.Api.Compare.Product.loadData = function (a, t) {
39		$.Api.sendRequest({
40			url: "/api/web/compare/products/detail",
41			data: a,
42			type: "GET"
43		}, t);
44	};
45	$.Api.ePriceAds = (typeof $.Api.ePriceAds == 'undefined') ? {} : $.a.ePriceAds;
46	$.Api.ePriceAds.loadData = (a, t) => {
47		//_ept = "/api/web/ad/"+$.gv.page+"/"+_cpw+'?poped='+_pop+'&mpoped='+_mpop;
48		$.Api.sendRequest({
49			url: "/api/web/ad/" + $.gv.page + "/" + a.size,
50			data: a,
51			type: "GET"
52		}, t);
53	};
54	$.Api.PopupAd = (typeof $.Api.PopupAd == 'undefined') ? {} : $.Api.PopupAd;
55	$.Cookie = (typeof $.Cookie == 'undefined') ? {} : $.Cookie;
56	$.Cookie.getData = function (name) {
57		// let regx = new RegExp('^' + name + '=');
58		let regx = new RegExp('^\s*' + name + '=');
59		let value = null;
60		document.cookie.split(';')
61			.forEach(function (data) {
62				if (regx.test(data)) {
63					let tmpAry = data.split('=');
64					value = (tmpAry.length > 1) ? tmpAry[1] : value;
65					value = value.replace(/\s+$/g, '');
66					return false;
67				}
68			});
69		return value;
70	};
71	$.Layout = (typeof $.Layout == 'undefined') ? {} : $.Layout;
72	$.Layout.GoogleAds = (typeof $.Layout.GoogleAds == 'undefined') ? {} : $.Layout.GoogleAds;
73	$.Layout.GoogleAds.init = () => {
74		if (typeof window.googletag == 'undefined') {
75			return setTimeout(() => $.Layout.GoogleAds.init(), 300);
76		}
77		if (typeof $.gv == 'undefined' || !$.gv.ePriceAdsLoaded) {
78			return setTimeout(() => $.Layout.GoogleAds.init(), 300);
79		}
80
81		let width = window.innerWidth;
82		let vsb = width <= 768
83			? "xs"
84			: width <= 992 ? "sm" : "lg";
85
86		googletag = window.googletag || { cmd: [] };
87		if (typeof googletag.cmd == 'undefined') {
88			googletag.cmd = [];
89		}
90		$('[id^="div-gpt-ad-"][data-width][data-height][data-visible="' + vsb + '"]')
91			.each(function (i, gpt) {
92				$(gpt).removeAttr('data-visible');
93				googletag.cmd.push(function () {
94					var slot = googletag.defineSlot(
95						$(gpt).data('slot'),
96						[$(gpt).data('width'), $(gpt).data('height')],
97						$(gpt).attr('id')
98					).addService(googletag.pubads())
99						.addService(googletag.companionAds().setRefreshUnfilledSlots(true));
100
101					if (typeof $(gpt).data('pos') !== 'undefined') {
102						slot.setTargeting('position', $(gpt).data('pos').split(','));
103					}
104
105					if (typeof $(gpt).data('sec') !== 'undefined') {
106						slot.setTargeting('section', $(gpt).data('sec').split(','));
107					}
108					googletag.pubads().enableSingleRequest();
109					googletag.pubads().collapseEmptyDivs();
110					// googletag.pubads().enableVideoAds();
111					googletag.companionAds().setRefreshUnfilledSlots(true);
112					googletag.enableServices();
113				});
114				googletag.cmd.push(function () {
115					googletag.display($(gpt).attr('id'));
116				});
117			});
118		$('[id^="div-ads-native-"][data-ad-slot][data-visible="' + vsb + '"]')
119			.each(function (i, w) {
120				$(w).removeAttr('data-visible');
121				$("<ins />").addClass("adsbygoogle")
122					.css('display', 'block')
123					.attr("data-ad-format", $(w).data('ad-format'))
124					.attr("data-ad-layout-key", $(w).data('ad-layout-key'))
125					.attr("data-ad-client", $(w).data('ad-client'))
126					.attr("data-ad-slot", $(w).data('slot'))
127					.appendTo($(w));
128				(adsbygoogle = window.adsbygoogle || []).push({});
129			});
130	};
131
132	$.Layout.GoogleAds.load = () => {
133		if (typeof window.googletag == 'undefined') {
134			return setTimeout(() => $.Layout.GoogleAds.load(), 300);
135		}
136		if (typeof $.gv == 'undefined' || !$.gv.ePriceAdsLoaded) {
137			return setTimeout(() => $.Layout.GoogleAds.load(), 300);
138		}
139		var vsb = "lg";
140		var st = $(document).scrollTop();
141		var threshold = st + window.innerHeight * 3;
142		if (window.innerWidth <= 768) {
143			vsb = "xs";
144			threshold = st + window.innerHeight * 2;
145		}
146		else if (window.innerWidth <= 992) {
147			vsb = "sm";
148		}
149		$('[id^="div-gpt-ad-"][data-width][data-height][data-visible="' + vsb + '"]')
150			.each(function (i, gpt) {
151				if ($(gpt).offset().top < threshold) {
152					$(gpt).removeAttr('data-visible');
153					googletag.cmd.push(function () {
154						var slot = googletag.defineSlot(
155							$(gpt).data('slot'),
156							[$(gpt).data('width'), $(gpt).data('height')],
157							$(gpt).attr('id')
158						).addService(googletag.pubads());
159						// .addService(googletag.companionAds());
160						if (typeof $(gpt).data('pos') !== 'undefined') {
161							slot.setTargeting('position', $(gpt).data('pos').split(','));
162						}
163						googletag.pubads().enableSingleRequest();
164						googletag.pubads().collapseEmptyDivs();
165						// googletag.pubads().enableVideoAds();
166						// googletag.companionAds().setRefreshUnfilledSlots(true);
167						googletag.enableServices();
168					});
169					googletag.cmd.push(function () {
170						googletag.display($(gpt).attr('id'));
171					});
172				}
173			});
174		$('[id^="div-adsbygoogle-native-"][data-visible="' + vsb + '"]')
175			.each(function (i, gpt) {
176				if ($(gpt).offset().top < threshold) {
177					$(gpt).removeAttr('data-visible');
178					$ins = $("<ins />").addClass("adsbygoogle")
179						.css('display', 'block')
180						.appendTo($(gpt));
181					if (typeof $(gpt).data('ad-format') !== 'undefined') {
182						$ins.attr("data-ad-format", $(gpt).data('ad-format'));
183					}
184					if (typeof $(gpt).data('ad-layout-key') !== 'undefined') {
185						$ins.attr("data-ad-layout-key", $(gpt).data('ad-layout-key'));
186					}
187					if (typeof $(gpt).data('ad-client') !== 'undefined') {
188						$ins.attr("data-ad-client", $(gpt).data('ad-client'));
189					}
190					if (typeof $(gpt).data('ad-slot') !== 'undefined') {
191						$ins.attr("data-ad-slot", $(gpt).data('ad-slot'));
192					}
193					(adsbygoogle = window.adsbygoogle || []).push({});
194				}
195			});
196	};
197	$.Layout.PopupAd = (typeof $.Layout.PopupAd == 'undefined') ? {} : $.Layout.PopupAd;
198	$.Layout.PopupAd.timer = null;
199	$.Layout.PopupAd.pageCate = 'unknown';
200	$.Layout.PopupAd.ePriceAdsCountDown = 10;
201	$.Layout.PopupAd.GoogleAdsCountDown = 6;
202	$.Layout.PopupAd.init = (slotId, slotData) => {
203		switch (slotData.type) {
204			case 'google':
205				if ($.Layout.ePriceAds.mainCrazyXs !== null && $.Layout.ePriceAds.mainCrazyXs.type !== 'google') {
206					console.log('has self popup ads, skip showing google popup adv');
207					return false;
208				}
209				let $s = $.Layout.PopupAd.findAdvWrapper();
210				if ($s == undefined || $s.length <= 0) {
211					return false;
212				}
213				const $popAd = $.Layout.PopupAd.createElement({
214					seconds: $.Layout.PopupAd.GoogleAdsCountDown
215				});
216				const wh = $(window).height();
217				$s.children().filter((index, element) => {
218					const st = $(element).offset().top;
219					return (st > (wh * 150 / 100)) ? true : false;
220				}).each((index, element) => {
221					$popAd.css('float', $(element).css('float'))
222						.insertBefore($(element));
223					const a = document.querySelector(".popup-adv");
224					new IntersectionObserver(function (entries) {
225						if (entries[0]["isIntersecting"] === true) {
226							$.Layout.PopupAd.showUp(slotData);
227						}
228					}, {
229						root: null,
230						threshold: 0,
231					}).observe(a);
232					console.info('Google popupAdv replaced');
233					return false;
234				});
235				break;
236			default: {
237				const $s = $('#' + slotId);
238				if ($s.length <= 0) {
239					return false;
240				}
241				const $popAd = $.Layout.PopupAd.createElement({
242					seconds: $.Layout.PopupAd.ePriceAdsCountDown
243				});
244				$popAd.css('float', $s.css('float')).insertBefore($s);
245				$.Layout.PopupAd.showUp(slotData);
246				console.info('ePrice popupAdv replaced');
247			}
248				break;
249		}
250	};
251	$.Layout.PopupAd.findAdvWrapper = function () {
252		var tmpAry = location.href.split('/');
253		let pageCate = 'main';
254		if (tmpAry.length > 4) {
255			pageCate = (tmpAry[4] == '') ? tmpAry[3] : tmpAry[4];
256		}
257		else if (tmpAry.length > 3) {
258			pageCate = (tmpAry[3] == '') ? tmpAry[2] : tmpAry[3];
259		}
260		pageCate = (pageCate.length <= 0) ? 'main' : pageCate;
261		$.Layout.PopupAd.pageCate = (pageCate == 'news') ? pageCate : pageCate.replace(/s$/, '');
262		// console.log($.Layout.PopupAd.pageCate);
263		let $w = [];
264		switch ($.Layout.PopupAd.pageCate) {
265			case 'talk':
266				$w = $('.article__content').first();
267				$.Layout.PopupAd.pageCate = 'article';
268				return $w;
269				break;
270			case 'all':
271			case 'news':
272				$w = $('.list-group.article-list[data-layout=feed] > li:nth-of-type(3)').first();
273				return $w;
274				break;
275			default:
276				let $s = $('.main-section-right:not(.hidden-xs)');
277				if ($s.length <= 0) {
278					$s = $('.main-section-center:not(.hidden-xs)');
279				}
280				if ($s.find('.home-news-article')) {
281					$w = $s.find('.home-news-article .list-group').last();
282				}
283				else {
284					$w = $s.find('.list-group').first();
285				}
286				break;
287		}
288		return $w;
289	};
290	$.Layout.PopupAd.createElement = (args) => {
291		const { seconds } = args;
292		let $d = $('<div />').addClass('popup-adv').css("z-index", "999");
293		let $w = $('<div />')
294			.addClass('popup-adv-wrapper hidden')
295			.appendTo($d);
296		$('<div />').addClass('popup-adv-back').appendTo($d);
297		$('<div />').addClass('btn btn-default btn-md countdown my-1')
298			.attr('data-time', seconds)
299			.text(seconds)
300			.appendTo($w);
301		let $b = $('<a />').attr('href', '#')
302			.addClass('btn btn-default btn-md btn-hide my-1 hidden')
303			.appendTo($w);
304		$("<i />").addClass('fas fa-times')
305			.appendTo($b);
306		$('<span />').addClass('text px-2')
307			.text('關閉廣告')
308			.appendTo($b);
309		$("<div />").attr('id', 'crazy-popup-container').appendTo($w);
310		return $d;
311	};
312
313	$.Layout.PopupAd.showUp = (slotData) => {
314		let $adv = $('.popup-adv').first();
315		if ($adv.length <= 0) {
316			return false;
317		}
318		$adv.addClass('show')
319			.children('.popup-adv-wrapper')
320			.removeClass('hidden');
321
322		$adv.find('.btn-hide')
323			.removeAttr('data-type')
324			.attr('data-type', slotData.type);
325
326		var slotElm = document.getElementById('crazy-popup-container');
327		switch (slotData.type) {
328			case 'jpg':
329			case 'png':
330				$.Layout.ePriceAds.createAssetElementAsImage(slotElm, { slotData });
331				break;
332			case 'html':
333				$.Layout.ePriceAds.createAssetElementAsHtml5(slotElm, Object.assign({}, slotData, { width: 320, height: 480 }));
334				break;
335			case 'google':
336			default:
337				$adv.addClass('show')
338					.children('.popup-adv-wrapper')
339					.removeClass('hidden');
340
341				if (slotData.slot) {
342					googletag.cmd.push(function () {
343						googletag.defineSlot(
344							slotData.slot,
345							slotData.size,
346							'crazy-popup-container'
347						).addService(googletag.pubads())
348							.addService(googletag.companionAds().setRefreshUnfilledSlots(true))
349							.setTargeting('position', [$.Layout.PopupAd.pageCate, 'popup', 'xs']);
350						googletag.pubads().enableSingleRequest();
351						googletag.enableServices();
352					});
353					googletag.cmd.push(function () { googletag.display('crazy-popup-container'); });
354				}
355				break;
356		}
357		setTimeout(() => $.Layout.PopupAd.countDown(), 1000);
358	};
359
360	$.Layout.PopupAd.hide = () => {
361		let $adv = $('.popup-adv').first();
362		if ($adv.length <= 0) {
363			return false;
364		}
365		if (!document.cookie.split(";").find((row) => row.startsWith("mpoped"))) {
366			document.cookie = "mpoped=1;path=/;domain=eprice.com.hk;max-age=14400;samesite=lax;secure;";
367		}
368		$adv.remove();
369	};
370	$.Layout.PopupAd.countDown = () => {
371		let $bar = $('.popup-adv-wrapper .countdown').first();
372		if ($bar.length > 0) {
373			let time = $bar.data('time');
374			if ($bar.data('time') > 1) {
375				time--;
376				$bar.removeAttr('data-time')
377					.removeData('time')
378					.attr('data-time', time)
379					.text(time);
380				if ($.Layout.PopupAd.timer == null) {
381					$.Layout.PopupAd.timer = setInterval(function () {
382						$.Layout.PopupAd.countDown();
383					}, 1000);
384				}
385			}
386			else {
387				$bar.addClass('hidden')
388					.siblings('.btn-hide')
389					.removeClass('hidden');
390				clearInterval($.Layout.PopupAd.timer);
391			}
392		}
393	};
394
395	$.Layout.ePriceAds = (typeof $.Layout.ePriceAds == 'undefined') ? {} : $.Layout.ePriceAds;
396	$.Layout.ePriceAds.mainCrazyXs = null;
397	$.Layout.ePriceAds.checkCookie = (cookieName) => {
398		return document.cookie.split(';').some((item) => item.trim().startsWith(cookieName));
399	};
400	$.Layout.ePriceAds.createAssetElementAsImage = (slotElm, args) => {
401		const { slotData } = args;
402		const adElm = document.createElement("a");
403		adElm.setAttribute("href", slotData.url);
404		adElm.setAttribute("rel", "nofollow");
405		adElm.setAttribute("target", "_blank");
406
407		const adImg = document.createElement("img");
408		adImg.setAttribute("src", slotData.filename);
409		adElm.appendChild(adImg);
410		slotElm.appendChild(adElm);
411	};
412
413	$.Layout.ePriceAds.createAssetElementAsHtml5 = (slotElm, args) => {
414		const { slotData } = args;
415		const htmlElm = document.createElement("iframe");
416		htmlElm.setAttribute("src", slotData.filename);
417		htmlElm.setAttribute("frameborder", "0");
418		htmlElm.setAttribute("allowtransparency", "true");
419		htmlElm.setAttribute("scrolling", "no");
420		htmlElm.setAttribute("sandbox", "allow-same-origin allow-scripts allow-top-navigation allow-popups");
421		if (slotData.width) {
422			htmlElm.setAttribute('width', slotData.width);
423		}
424		if (slotData.height) {
425			htmlElm.setAttribute('height', slotData.height);
426		}
427		slotElm.appendChild(htmlElm);
428	};
429
430	$.Layout.ePriceAds.createAssetElementAsGoogle = (slotElm, args) => {
431		const { slotId, slotData } = args;
432		slotElm.setAttribute("id", slotId);
433		slotElm.setAttribute("data-slot", slotData.slot);
434		slotElm.setAttribute("data-width", slotData.size[0]);
435		slotElm.setAttribute("data-height", slotData.size[1]);
436		slotElm.style.minWidth = slotData.size[0];
437		slotElm.style.minHeight = slotData.size[1];
438
439		googletag.cmd.push(function () {
440			googletag.defineSlot(slotData.slot, slotData.size, slotId)
441				.addService(googletag.pubads())
442				.addService(googletag.companionAds().setRefreshUnfilledSlots(true));
443		});
444		googletag.cmd.push(function () {
445			googletag.display(slotId);
446			console.info(`googletag.display('${slotId}')`);
447		});
448	};
449
450	$.Layout.ePriceAds.createAssetElementAsAdsense = (slotElm, args) => {
451		const { slotData } = args;
452		const assetElm = document.createElement("ins");
453		assetElm.setAttribute("id", slotData.id);
454		assetElm.setAttribute("class", "adsbygoogle");
455		assetElm.setAttribute("data-ad-client", "ca-pub-2614970773838551");
456		assetElm.setAttribute("data-ad-slot", slotData.slot);
457		assetElm.style.display = 'block';
458
459		slotElm.appendChild(assetElm);
460		(adsbygoogle = window.adsbygoogle || []).push({});
461	};
462
463	$.Layout.ePriceAds.loadAds = (slotId, slotData) => {
464		let slotElm = document.getElementById(slotId);
465		if (null === slotElm) {
466			console.log('slot ' + slotId + ' not configured.');
467			return false;
468		}
469		slotElm.classList.remove('hidden');
470		if (slotId === "main-crazy-xs" && typeof slotData.type !== 'undefined') {
471			const width = window.innerWidth;
472			const vsb = width <= 768 ? "xs" : (width <= 992 ? "sm" : "lg");
473			if ($.gv.isPopUp == '0' && vsb == 'xs') {
474				$.Layout.ePriceAds.mainCrazyXs = slotData;
475				$.Layout.PopupAd.init('main-crazy-xs', slotData);
476			}
477			return true;
478		}
479
480		switch (slotData.type) {
481			case 'jpg':
482			case 'png':
483				$.Layout.ePriceAds.createAssetElementAsImage(slotElm, { slotData });
484				break;
485			case 'html':
486				if (/\.html$/.test(slotData.filename)) {
487					$.Layout.ePriceAds.createAssetElementAsHtml5(slotElm, { slotData });
488				} else {
489					$.Layout.ePriceAds.createAssetElementAsImage(slotElm, { slotData });
490				}
491				break;
492			case 'google':
493				$.Layout.ePriceAds.createAssetElementAsGoogle(slotElm, { slotId, slotData });
494				break;
495			case 'adsense':
496				$.Layout.ePriceAds.createAssetElementAsAdsense(slotElm, { slotData });
497				break;
498			default:            // unspecified ad type
499				slotElm.remove();
500				break;
501		}
502		if (slotId === "main-crazy-lg" && slotData.crazyfile) { // handle CrazyAds
503			slotElm.classList.add('hidden');
504			//console.log("not configured.");
505			$.Layout.ePriceAds.loadAds('main-crazy-lg-popup', Object.assign({}, slotData, {
506				filename: slotData.crazyfile,
507				width: 1200,
508				height: 629
509			}));
510		}
511	};
512	$.Layout.ePriceAds.init = () => {
513		if (typeof $.gv == 'undefined') {
514			return setTimeout(() => {
515				$.Layout.ePriceAds.init()
516			}, 300);
517		}
518		if ($.gv.hasEpriceAds === undefined || $.gv.hasEpriceAds === false) {
519			console.log('skip ePriceAds init.');
520			return false;
521		}
522		const args = {
523			size: (window.innerWidth >= 992) ? "lg" : "xs",
524			poped: $.Layout.ePriceAds.checkCookie('poped') ? '1' : '0',
525			mpoped: $.Layout.ePriceAds.checkCookie('mpoped') ? '1' : '0'
526		};
527		$.Api.ePriceAds.loadData(args, {
528			success: (jsonData) => {
529				const data = jsonData.data;
530				Object.entries(data).forEach((entry) => {
531					$.Layout.ePriceAds.loadAds(entry[0], entry[1]);
532				});
533				$.gv.ePriceAdsLoaded = true;
534			}
535		});
536	};
537	$.Layout.ePriceAds.closeCrazyAdv = () => {
538		$('#main-crazy-lg-popup').addClass('hidden');
539		$('#main-crazy-lg').removeClass('hidden');
540		if (!document.cookie.split(";").find((row) => row.startsWith("poped"))) {
541			document.cookie = "poped=1;path=/;domain=eprice.com.hk;max-age=14400;samesite=lax;secure;";
542		}
543	};
544
545	$.Layout.Lazyload = (typeof $.Layout.Lazyload == 'undefined') ? {} : $.Layout.Lazyload;
546	$.Layout.Lazyload.load = function () {
547		$(".img-wrapper[data-image]").each(function (t, o) {
548			$(o).css("background-image", "url('" + $(o).data("image") + "')")
549				.removeAttr("data-lazyload")
550				.removeData("lazyload")
551				.removeAttr("data-image")
552				.removeData("image");
553		});
554	};
555	$.Layout.Gallery = (typeof $.Layout.Gallery == 'undefined') ? {} : $.Layout.Gallery;
556	$.Layout.Gallery.resize = function () {
557		ww = window.innerWidth;
558		$('.list-group.product-list[data-layout="feed"]').each(function (i, a) {
559			if (ww <= 768) {
560				if ($(a).children().length > $(a).data('row')) {
561					w = 0,
562						$(a).children().each(function (j, c) {
563							w += $(c).outerWidth(true);
564						});
565					$(a).css('width', w);
566				}
567				else {
568					$(a).css('width', '100%');
569				}
570			}
571			else {
572				$(a).css('width', '100%');
573			}
574		});
575	};
576	$.Layout.Compare = (typeof $.Layout.Compare == 'undefined') ? {} : $.Layout.Compare;
577	$.Layout.Compare.PopupMenu = (typeof $.Layout.Compare.PopupMenu == 'undefined') ? {} : $.Layout.Compare.PopupMenu;
578	$.Layout.Compare.PopupMenu.init = function () {
579		a = {},
580			$.Api.Compare.List.loadData(a, {
581				'success': function (oRes) {
582					$.Layout.Compare.PopupMenu.refreshData(oRes);
583					result = oRes.res;
584					$.each(result, function (i, t) {
585						$('.btn.btn-compare')
586							.filter('[data-lib="' + t.lib + '"]')
587							.filter('[data-value="' + t.prodId + '"]')
588							.addClass('active')
589							.text('取消比拼');
590					});
591				}
592			});
593	};
594	$.Layout.Compare.PopupMenu.refreshData = function (oRes) {
595		document.querySelectorAll(".icon-button.compare-button .count[data-value]")
596			.forEach((element) => {
597				element.setAttribute("data-value", oRes.total);
598				element.innerText = oRes.total;
599				if (oRes.total > 0) {
600					element.parentElement.classList.add("active");
601				} else {
602					element.parentElement.classList.remove("active");
603				}
604			});
605	};
606	$(document).on('click', '.btn.btn-compare[data-value]', function (e) {
607		e.preventDefault();
608		b = $(this);
609		a = { lib: b.data('lib'), modelId: b.data('value') };
610		_callback = function () {
611			$.Api.Compare.List.loadData(a, {
612				'success': $.Layout.Compare.PopupMenu.refreshData
613			});
614		};
615		if (b.hasClass('active')) {
616			$.Api.Compare.List.removeData(a, {
617				'success': function (oRes) {
618					b.removeClass('active')
619						.text('加入比拼');
620					_callback && _callback();
621				}
622			});
623		}
624		else {
625			$.Api.Compare.List.updateData(a, {
626				'success': function (oRes) {
627					b.addClass('active')
628						.text('取消比拼');
629
630					_callback && _callback();
631				}
632			});
633		}
634	})
635		.on('click', '.navbar-fixed-top .btn-search', function (e) {
636			e.preventDefault();
637			var $w = $("<div />");
638			var $d = $("<div />")
639				.addClass('text-center')
640				.appendTo($w);
641			var $f = $("<form />")
642				.attr('method', 'get')
643				.attr('action', '/search')
644				.appendTo($d);
645			$("<input />")
646				.addClass('form-control')
647				.attr('name', 'q')
648				.attr('placeholder', '我想搜尋...')
649				.appendTo($f);
650			var _callback = function () {
651				var $frm = $('#dialog-search form').first();
652				if ($frm.length > 0) {
653					$frm.trigger('submit');
654				}
655			};
656			$.Dialog.showAlertDialog({
657				id: 'dialog-search',
658				html: $w.html(),
659				buttons: [{
660					'text': '取消',
661					'className': 'btn-dismiss',
662					'click': function () {
663						$.Dialog.closeDialog('dialog-search');
664					}
665				}, {
666					'text': '開始搜尋',
667					'className': 'btn-success',
668					'click': function () {
669						_callback && _callback();
670					}
671				}]
672			});
673		})
674		.on("click", ".btn-back2top", function (a) {
675			a.preventDefault(),
676				(window.opera ? "CSS1Compat" == document.compatMode ? $("html") : $("body") : $("html,body")).animate({ scrollTop: 0 }, 200);
677		})
678		.on('click', '.btn-fixed-tab.fixed-left', function (e) {
679			e.preventDefault();
680			var $p = $('.main-section-left').first();
681			if ($p.hasClass('expanded')) {
682				$p.removeClass('expanded');
683				$(this).removeClass('expanded');
684			}
685			else {
686				$p.addClass('expanded');
687				$(this).addClass('expanded');
688			}
689		})
690		.on('click', '.btn-fixed-tab.fixed-right', function (e) {
691			e.preventDefault();
692			var $p = $('.main-section-right').first();
693			if ($p.hasClass('expanded')) {
694				$p.removeClass('expanded');
695			}
696			else {
697				$p.addClass('expanded');
698			}
699		})
700		.on('click', '.popup-adv-wrapper .btn-hide', function (e) {
701			e.preventDefault();
702			$.Layout.PopupAd.hide();
703		});
704
705	$.Layout.ePriceAds.init();
706	$.Layout.GoogleAds.init();
707	$.Layout.Compare.PopupMenu.init();
708});
709
710
711window.addEventListener("load", () => {
712	window.addEventListener("scroll", () => {
713		let t = document.scrollingElement.scrollTop,
714			b = document.querySelector(".btn-back2top");
715		t > 126
716			? b.classList.add("available")
717			: b.classList.remove("available");
718		$.Layout.Lazyload.load();
719		$.Layout.GoogleAds.load();
720	});
721});
722
723// Create IE + others compatible event handler
724const eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
725const eventer = window[eventMethod];
726const messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
727
728// Listen to message from child window
729eventer(messageEvent, (e) => {
730	if (e.data == 'close-crazy-ad') {
731		$.Layout.ePriceAds.closeCrazyAdv();
732	}
733}, false);

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.