PageSourceSearch

https://www.ec-store.net/campaign/news/js/news.js?20240305

js ec-store.net collected 2026-09-25 18:39:11 UTC 5,649 bytes, 164 lines download raw bytes

1/**
2 * news.js: ver 1.0.2
3 * ニュースページ
4 * URLパラメータ, JSONを使用
5 * 上記の内容からHTMLを描画
6 *
7 * Last Modified - 2023.05.01
8 * 記事IDが存在しない場合、NEWS一覧にリダイレクト
9 * div#news内のanchorタグに対して特定のクラス(.isCopy)が付与されている場合、リンクをコピー
10 */
11 (function (global) {
12	'use strict';
13
14	var device		= Flgs.device;
15	var d			= document,
16		root		= d.querySelector('#news'),
17		json		= '/campaign/news/json/echo.json',
18		newsRoot	= '/sws/secure/news.aspx';
19
20	var NEWS		= {
21		init: function () {
22			return new Promise(function (resolve) {
23				NEWS.getJSON(json);
24				resolve();
25			});
26		},
27		getJSON: function (arg) {
28			fetch(arg).then(function (r) {
29				return (r.ok) ? r.json() : CONFIG.error();
30			}).then(function (res) {
31				if (CONFIG.result(CONFIG.getSRCH('article'))) {
32					NEWS.parsePage(res, CONFIG.getSRCH('article'));
33				} else {
34					if (CONFIG.getSRCH('article') === '') return CONFIG.redirect(newsRoot);
35					NEWS.parseList(res);
36				}
37			}).catch(function (err) {
38				console.log(err);
39			});
40		},
41		parseList: function (arg) {
42			root.insertAdjacentHTML('beforeend', '<h1 class="title" style="margin-bottom: 0; border: none;"><span>ニュース</span></h1>');
43			var ul = d.createElement('ul');
44			arg.forEach(function (e) {
45				if (!(e.shop === 'all' || e.shop === 'sws')) return;
46				var startDate = NEWS.startDate(e.startdate),
47					endDate = NEWS.endDate(e.enddate);
48
49				if (!CONFIG.getTimed(startDate, endDate)) return;
50				ul.insertAdjacentHTML('beforeend', '<li>'+
51					'<a href="'+newsRoot+'?article='+e.name+'">'+
52						'<ul>'+
53							'<li>'+e.update.replace(/\//g,'.')+'</li>'+
54							'<li><span>'+e.title+'</span></li>'+
55						'</ul>'+
56					'</a>'+
57				'</li>');
58			});
59			root.appendChild(ul);
60		},
61		parsePage: function (arg, id) {
62			var arr = [];
63			for (var i=0; i<arg.length; i++) {
64				if (id == arg[i].name) {
65					arr.push(arg[i]);
66					break;
67				}
68			}
69			if (arr.length > 0) {
70				arr = arr[0];
71				var startDate = NEWS.startDate(arr.startdate), endDate = NEWS.endDate(arr.enddate);
72				if (CONFIG.getTimed(startDate, endDate)) {
73					switch (device) {
74						case 'pc': root.insertAdjacentHTML('beforeend', '<h1 class="title" style="padding: 0;"><span>'+arr.title+'</span></h1>'); break;
75						case 'sp': root.insertAdjacentHTML('beforeend', '<h1 class="title"><span>'+arr.title+'</span></h1>'); break;
76						default: break;
77					}
78					var div = d.createElement('div');
79					div.className = 'pages';
80					arr.items.forEach(function (e) {
81						switch (e.fieldId) {
82							case 'text': div.insertAdjacentHTML('beforeend', '<p>'+e.text.join('<br>')+'</p>'); break;
83							case 'image': div.insertAdjacentHTML('beforeend', NEWS.modified(e.link, 'anchor', 'start')+'<img class="fadeInElement" src="/campaign/asset/img/noimage.png" data-src="'+e.image+'" alt="'+e.title+'">'+NEWS.modified(e.link, 'anchor', 'end')); break;
84							default: break;
85						}
86					});
87					div.insertAdjacentHTML('beforeend', '<div class="update"><span>掲載日付 : </span><span>'+arr.update+'</span></div>');
88					div.insertAdjacentHTML('beforeend', '<div class="buttons" data-column="2"><a class="button-style" href="/sws/r/rSWS/">トップページへ</a><a class="button-style" href="'+newsRoot+'">ニュース一覧ページに戻る</a></div>');
89					root.appendChild(div);
90				} else {
91					return CONFIG.redirect(newsRoot);
92				}
93			} else {
94				return CONFIG.redirect(newsRoot);
95			}
96		},
97		startDate: function (e) { return (CONFIG.result(e)) ? e : '20210101000000'; },
98		endDate: function (e) { return (CONFIG.result(e)) ? e : '29991231235959'; },
99		modified: function (a, b, c) {
100			if (!CONFIG.result(a)) return '';
101			var r;
102			switch (b) {
103				case 'anchor': r = c === 'start' ? '<a href="'+a+'">' : '</a>'; break;
104				default: r = '<li>'+a+'</li>'; break;
105			}
106			return r;
107		},
108		getImageSrc: function (e) {
109			var image = new Image();
110			image.onload = function () {
111				e.src = e.dataset.src;
112				e.dataset.src = '';
113				delete e.dataset.src;
114			}
115			image.src = e.src;
116		},
117		visible: function () {
118			var options = {
119				root: null,
120				rootMargin: '0px',
121				threshold: 0,
122			}
123			var observer = new IntersectionObserver(function (entries) {
124				Array.prototype.forEach.call(entries, function (entry) {
125					if (!entry.isIntersecting) return;
126					if (entry.target.dataset.hasOwnProperty('src')) {
127						NEWS.getImageSrc(entry.target);
128						var fadeInElement = CONFIG.closest(entry.target, '.fadeInElement');
129						if (fadeInElement.className.indexOf('visible') === -1) fadeInElement.className = fadeInElement.className+' visible';
130					}
131					observer.unobserve(entry.target);
132				});
133			}, options);
134			Array.prototype.forEach.call(root.querySelectorAll('img[data-src]'), function (e) { observer.observe(e); });
135		},
136		isCopy: function (_) {
137			if (!_.length) return;
138			Array.prototype.forEach.call(_, function (e) {
139				e.addEventListener('click', function (ev) {
140					ev.preventDefault();
141					var href = ev.target.getAttribute('href');
142					var ele = d.createElement('input');
143					ele.value = href;
144					d.body.appendChild(ele);
145					ele.select();
146					d.execCommand('copy');
147					d.body.removeChild(ele);
148					alert('リンクをコピーしました。'+'\n'+href);
149				})
150			});
151		}
152	}
153	global.NEWS = NEWS;
154})((this || 0).self || global);
155
156/** ////////////////////////////////////////
157 * 実行
158 * /////////////////////////////////////// */
159NEWS.init().then(function () {
160	CONFIG.sleep(1000).then(function () {
161		NEWS.visible();
162		NEWS.isCopy(document.querySelectorAll('a.isCopy'));
163	});
164});

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.