adList.min.js 6.9 KB

1
  1. document.addEventListener("DOMContentLoaded",(function(){const t="http://"===location.origin?"http:":"https://"===location.origin?"https:":"http://",e=t+"10.30.160.129:8082/";function n(t={}){const e=t.slots||[],n=new Date,s=n.getTime();for(let t=0;t<e.length;t++){const r=e[t];if(!r.creativesList||!r.creativesList.length)continue;const l=document.querySelector("#sxtv-ad-"+r.slotId);if(!l){console.error("广告位置不存在:#sxtv-ad-"+r.slotId);continue}const a=document.createElement("div");a.innerHTML='<svg t="1734493782806" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9775" width="32" height="32"><path d="M560.88 658.8h69.68v15.44h-69.68z" p-id="9776" fill="#515151"></path><path d="M698.24 451.44V200h-46.56v251.44H372.32V200h-46.56v251.44H186V824h651.92V451.44zM505.12 600H396.16v90.72L352 700.08v-33.92l8-2.4V575.2h54.24l-1.84-8.8h45.84l1.68 8.8h44.88z m162.72 96.48H524.4v-60h143.44z m5.36-64.48H518.88v-23.36h61.12v-11.28h-22.16l-2.88 8.48H520V582.4h8.72l5.52-13.76H568l-2.32 6.64h14.32v-8h38.64v8h49.04v22h-49.04v11.36h54.56z" p-id="9777" fill="#515151"></path></svg>',a.style.position="absolute",a.style.top=0,a.style.right=3,a.style.zIndex=999999;const d=document.createElement("div");d.style.position="relative",d.appendChild(a);for(let t=0;t<r.creativesList.length;t++){const e=r.creativesList[t],l=new Date(e.startDate+" 00:00:00").getTime(),a=new Date(e.endDate+"").getTime();if(s<l||s>a||!Array.isArray(e.stuffsList))continue;let c=1===e.showType?o(e,n,r.slotId,r.width||0,r.height||0):i(e,n,r.slotId,r.width||0,r.height||0);if(-1==c)return;d.appendChild(c),d.style.width="100%",d.style.height="100%"}l.style.width=(r.width||0)+"px",l.style.height=(r.height||0)+"px",l.style.border="none",l.style.overflow="hidden",l.appendChild(d)}}const o=function(t={},n,o,i,s){const r=0===n.getDay()?7:n.getDay();if(0==(t.timeInterval||"").slice(24*r,24*r+25).split("")[n.getHours()])return-1;const l=1e3*(t.showIntervalTime||5);return function(t,n,o,i,s){const r=document.createElement("div");r.style="\n position: relative;\n width: 100%;\n height: 100%;\n margin: auto;\n overflow: hidden;\n ";const l=document.createElement("div");l.style=`\n width: ${t.length*i}px;\n height: ${s}px;\n display: flex;\n transition: transform 0.5s ease;\n `;const a=document.createElement("div");a.style="\n position: absolute;\n bottom: 10px;\n left: 50%;\n margin-right: 5px;\n transform: translateX(-50%);\n ",t.forEach(((t,n)=>{const s=document.createElement("img");s.src=t.addr,s.alt=`Image ${n+1}`,s.style=`\n flex: 1;\n width: ${i}px;\n height: 100%;\n `,s.addEventListener("click",(()=>{const n=localStorage.getItem("ad_id");fetch(`${e}ad/click?uuid=${n}&stuffId=${t.stuffId}&slotId=${o}`).then((t=>t.text())).then((()=>{window.open(t.landingPage)}))})),s.onload=()=>{const n=localStorage.getItem("ad_id");fetch(`${e}ad/show?uuid=${n}&stuffId=${t.stuffId}&slotId=${o}`).then((t=>t.text()))},l.appendChild(s);const r=document.createElement("button");r.style="\n border: none;\n background-color: #fff;\n cursor: pointer;\n padding: 5px;\n border-radius: 50%;\n width: 10px;\n height: 10px;\n margin-right: 5px;\n display: inline-block;\n ",0!==n&&(r.style.backgroundColor="#ccc"),r.dataset.target=n,a.appendChild(r)})),r.appendChild(l),r.appendChild(a);let d=0;const c=t.length;function h(t){l.style.transform=`translateX(-${t*i}px)`,a.querySelectorAll("button").forEach(((e,n)=>{e.style.backgroundColor=n===t?"#000":"#ccc"})),d=t}function u(){d=(d+1)%c,h(d)}a.addEventListener("click",(function(t){if("BUTTON"===t.target.tagName){h(parseInt(t.target.dataset.target))}}));let f=setInterval(u,n);return r.addEventListener("mouseenter",(()=>{clearInterval(f)})),r.addEventListener("mouseleave",(()=>{f=setInterval(u,n)})),r}(t.stuffsList,l,o,i,s)},i=function(t={},n,o,i,s){const r=0===n.getDay()?7:n.getDay(),l=(t.timeInterval||"").slice(24*r,24*r+24).split(""),a=n.getHours();if(0==l[a])return-1;const d=t.stuffsList[Math.floor((60*a+n.getMinutes())/(t.showIntervalTime||5))%t.stuffsList.length];if(!d)return-1;const c=d.addr.split(".").pop();if("jpg"===c||"png"===c||"gif"===c){const t=document.createElement("img");return t.src=d.addr,t.style.width=i+"px",t.style.height=s+"px",t.onload=()=>{const t=localStorage.getItem("ad_id");fetch(`${e}ad/show?uuid=${t}&stuffId=${d.stuffId}&slotId=${o}`).then((t=>t.text()))},t.addEventListener("click",(()=>{const t=localStorage.getItem("ad_id");fetch(`${e}ad/click?uuid=${t}&stuffId=${d.stuffId}&slotId=${o}`).then((t=>t.text())).then((()=>{window.open(d.landingPage)}))})),t}const h=document.createElement("video");h.setAttribute("loop","loop"),h.setAttribute("autoplay","autoplay"),h.setAttribute("muted","muted"),h.src=d.addr,h.style.width="100%",h.style.height="100%",h.oncanplay=()=>{h.play();const t=localStorage.getItem("ad_id");fetch(`${e}ad/show?uuid=${t}&stuffId=${src.stuffId}&slotId=${o}`).then((t=>t.text()))},h.addEventListener("click",(()=>{const t=localStorage.getItem("ad_id");fetch(`${e}ad/click?uuid=${t}&stuffId=${d.stuffId}&slotId=${o}`).then((t=>t.text())).then((()=>{window.open(d.landingPage)}))}));const u=()=>{h.play(),document.body.removeEventListener("click",u)};return document.body.addEventListener("click",u),h};function s(){return new Promise(((t,e)=>{(function(t){if(!(crypto&&crypto.subtle&&crypto.subtle.digest&&TextEncoder))return console.error("浏览器不支持创建哈希值"),Promise.reject();const e=(new TextEncoder).encode(t);return new Promise(((t,n)=>{crypto.subtle.digest("SHA-256",e).then((e=>{const n=Array.from(new Uint8Array(e)).map((t=>t.toString(16).padStart(2,"0"))).join("");t(n)})).catch((t=>{n(t)}))}))})(`${`${navigator.userAgent} ${window.screen.width}x${window.screen.height}`}|${Intl.DateTimeFormat().resolvedOptions().timeZone}|${function(){const t=document.createElement("canvas"),e=t.getContext("2d");if(!e)return"";e.fillStyle="#f60",e.fillRect(0,0,16,16),e.fillStyle="#069",e.font="11pt Arial",e.fillText("Cwm fjord!!",4,10),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("Cwm fjord!!",5,11),e.scale(2,2),e.fillStyle="#fff",e.font="24pt Arial",e.fillText("Cwm fjord!!",10,25),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("Cwm fjord!!",10,25);return t.toDataURL().replace(/data:image\/png;base64,/,"")}()}|${function(){const t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"";const n=e.getSupportedExtensions();if(!n)return"";const o=n.join(",");return e.getParameter(e.RENDERER)+"/"+e.getParameter(e.VENDOR)+o}()}`).then((e=>{t(e)})).catch((t=>{e(t)}))}))}const r=t+"cxzx.smcic.net/ad/catalog/"+document.querySelector("#sxtv-ad-id").getAttribute("ad_id")+".json";try{fetch(r+"?"+Date.now()).then((t=>t.json())).then((t=>{const e=t;localStorage.getItem("ad_id")?n(e):s().then((t=>{localStorage.setItem("ad_id",t+""),n(e)}))}))}catch(t){console.error(t)}}));