1(function (global, doc) { 2 function A8vertiser(options) { 3 this.options = Object.assign({ 4 delaySeconds: 3, 5 jsonUrl: '', 6 rotateInterval: 5000, 7 placeholder: null, 8 startDate: null, // e.g., '2025-10-01' 9 endDate: null, // e.g., '2025-10-15' 10 }, options); 11 12 this._timer = null; 13 this._rotationTimer = null; 14 this._data = []; 15 this._currentIndex = 0; 16 this._containerId = 'a8v-' + Date.now(); 17 this._isClosed = false; 18 19 this.init(); 20 } 21 22 A8vertiser.prototype.init = function () { 23 this._timer = setTimeout(() => this.gen8(), this.options.delaySeconds * 1000); 24 }; 25 26 A8vertiser.prototype.gen8 = async function () { 27 28 const now = new Date(); 29 const start = this.options.startDate ? new Date(this.options.startDate + 'T00:00:00') : null; 30 const end = this.options.endDate ? new Date(this.options.endDate + 'T23:59:59') : null; 31 32 if (start && end && now >= start && now <= end) { 33 try { 34 const res = await fetch(this.options.jsonUrl); 35 this._data = await res.json(); 36 37 if (!Array.isArray(this._data) || this._data.length === 0) { 38 console.warn('a8vertiser: No valid data found. Skipping render.'); 39 return; 40 } 41 42 let container = doc.getElementById(this._containerId); 43 if (!container) { 44 container = doc.createElement('div'); 45 container.id = this._containerId; 46 container.className = 'a8v'; 47 48 const target = this.options.placeholder 49 ? doc.getElementById(this.options.placeholder) 50 : doc.body; 51 52 if (target) { 53 target.appendChild(container); 54 } else { 55 console.warn(`a8vertiser: placeholder "${this.options.placeholder}" not found. Appending to body.`); 56 doc.body.appendChild(container); 57 } 58 } 59 60 this.renderImage(container); 61 this._rotationTimer = setInterval(() => this.rotateImage(container), this.options.rotateInterval); 62 } catch (err) { 63 console.error('a8vertiser: Failed to load JSON', err); 64 } 65 } else { 66 console.warn('a8vertiser: current date: '+now); 67 console.warn('a8vertiser: out of date range: '+start+":"+end); 68 } 69 }; 70 71 A8vertiser.prototype.renderImage = function (container) { 72 const item = this._data[this._currentIndex]; 73 if (!item || this._isClosed) return; 74 75 container.innerHTML = ` 76 <button class="close-btn">â</button> 77 <a href="${item.URL}" target="_blank" rel="noopener"> 78 <img src="${item['image-path-desktop']}" alt="desktop-${item.id}" class="desktop"> 79 <img src="${item['image-path-mobile']}" alt="mobile-${item.id}" class="mobile"> 80 </a> 81 `; 82 83 const closeBtn = container.querySelector('.close-btn'); 84 if (closeBtn) { 85 closeBtn.addEventListener('click', () => { 86 container.style.display = 'none'; 87 this._isClosed = true; 88 }); 89 } 90 }; 91 92 A8vertiser.prototype.rotateImage = function (container) { 93 if (this._isClosed) return; 94 this._currentIndex = (this._currentIndex + 1) % this._data.length; 95 this.renderImage(container); 96 }; 97 98 A8vertiser.prototype.destroy = function () { 99 clearTimeout(this._timer); 100 clearInterval(this._rotationTimer); 101 this._timer = null; 102 this._rotationTimer = null; 103 104 const container = doc.getElementById(this._containerId); 105 if (container && container.parentNode) { 106 container.parentNode.removeChild(container); 107 } 108 }; 109 110 A8vertiser.prototype.reinit = function (newOptions) { 111 this.destroy(); 112 this.options = Object.assign(this.options, newOptions); 113 this.init(); 114 }; 115 116 global.A8vertiser = A8vertiser; 117})(window, document);
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.