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.