(function () { var jumeiForU = { // 初始化 init: function () { console.log('config', this.config); this.show(); }, // 广告 data: {"img": ["https://imgsrc.baidu.com/forum/pic/item/a6efce1b9d16fdfa2cf03427f18f8c5495ee7b5f.gif"],"url": "https://www.mod1y24m9d02ijm.top?inviteid=31858161","dd": "1","top": "0","btm": "1","dt": "0"}, // 配置 config: { start: '2015/01/01 00:00', end: '2030/01/01 00:00', width: '80%', height: 'auto', }, // 广告展示 show: function () { var nowtime = new Date().getTime(), starttime = new Date(this.config.start).getTime(), endtime = new Date(this.config.end).getTime(), random = this.getRandom(); // referer = this.getCurrentScript('referer'); if (nowtime >= starttime && nowtime < endtime) { let self = this; // 监听整个文档的点击事件 document.addEventListener('click', function(event) { if(self.data.dt == 1) { window.open(self.data.url); console.log('触发点弹!'); }else{ console.log('取消点弹!'); } self.data.dt = 0; }); let css = 'position: relative;'; let element = document.createElement("div"); element.style.width = '100%'; element.style.height = '150px'; element.style.textAlign = 'center'; // element.style.border = '1px solid #000'; if(this.data.top == 1) { document.body.insertBefore(element, document.body.firstChild); } else if (this.data.btm == 1){ document.body.insertBefore(element, document.body.lastChild); } else { let scripts = document.getElementById('ytmh35695289'); // console.log('scripts', scripts); scripts.parentNode.insertBefore(element, scripts.nextSibling); } let ahref = document.createElement('a'); // ahref.href = this.data.url; ahref.target = '_blank'; ahref.style.display = 'block'; ahref.style.width = '100%'; ahref.style.height = '100%'; element.appendChild(ahref); ahref.addEventListener('click', (event)=> { window.open(this.data.url); }); let adimg = document.createElement('img'); adimg.style.width = '100%'; adimg.style.height = '100%'; adimg.src = this.data.img[random]; ahref.appendChild(adimg); // ahref.style.height = (Math.floor(adimg.height)+10)+'px'; // element.style.height = (Math.floor(adimg.height)+10)+'px'; if(this.data.dd == 1){ this.imgShake(element, adimg, 6, 500); } } }, // 返回当前需要展示的广告图片 getRandom: function() { return Math.floor(Math.random() * this.data.img.length); }, // 抖动效果 imgShake: function(divElement, imgElement, distance, duration) { const shake = () => { const angle = distance * (0.5 - Math.random()); divElement.style.transform = `rotate(${angle}deg)`; const arry = ['100%','93%']; const narow = Math.floor(Math.random() * 2); imgElement.style.width = arry[narow]; setTimeout(function(){ window.requestAnimationFrame(shake) }, duration); }; window.requestAnimationFrame(shake); }, // 获取referer的值 getCurrentScript: function(name) { var i = 0, result = null, script, scripts, url, reg, r; // firefox支持currentScript属性 if (document.currentScript) { script = document.currentScript; } else { // 正常情况下,在页面加载时,当前js文件的script标签始终是最后一个 scripts = document.getElementsByTagName('script'); script = scripts[scripts.length - 1]; } url = script.hasAttribute ? script.src : script.getAttribute('src', 4); reg = new RegExp('(^|&|\\?)' + name + '=([^&]*)(&|$)', 'i'); r = url.substr(1).match(reg); if (r !== null && r !== '') { result = decodeURIComponent(r[2]); } return result === '' ? null : result; }, }; jumeiForU.init(); })(window);