let googleAdsID = "4504259433"; let titleData = { CN: "", //中文 CHT: "", //繁体 EN: "", //英文 KOR: "", //韩文 JP: "", //日文 TH: "" //泰语 } /** 版本号 第一次 不用填写 如果出现缓存问题而打不开游戏 填写 1 2 3 等 */ var versionCode = ""; let loadProgre; //假的游戏加载进度 let loadText; //加载load 文本 let loadImg; //loading gif 图片 let bgColor; //背景图片 var adBreak; //谷歌广告对象 let tiao; let webText; initWeSane(); /** 初始化相关内容 */ function initWeSane() { //版本号不为 空 并且链接与版本号不符 将给链接加版本号重新刷新网页 if (versionCode != "" && location.href.indexOf(("#=" + versionCode)) == -1) { let href = ""; if (location.href.indexOf("#=") != -1) { href = (location.href).slice(0, location.href.indexOf("#=")) } else { href = location.href; } location.href = href + "#=" + versionCode; location.reload(); } languageTitle(); tiao = document.getElementById('splash'); loadText = document.getElementById('loadingText'); loadImg = document.getElementById('loadingImg'); webText = document.getElementById('webText'); var httpMid = window.location.host; var curWebMoreGame = httpMid; var urlG = curWebMoreGame.substring(0, 2); if (urlG == 'g.') { var newMoreUrl = curWebMoreGame.replace(urlG, "www."); curWebMoreGame = newMoreUrl; } webText.innerHTML = curWebMoreGame; loadProgre = 20; updateLoadText(0.02); initGooleAds(); } /** 修改标题 */ function languageTitle() { if (window.navigator.language == "zh-CN" || window.navigator.language == "zh-cn") { document.title = titleData.CN; } else if (window.navigator.language == "zh-TW" || window.navigator.language == "zh-HK") { document.title = titleData.CHT; } else if (window.navigator.language == "ko-KR") { document.title = titleData.KOR } else if (window.navigator.language == "ja-JP") { document.title = titleData.JP; } else if (window.navigator.language == "th-TH") { document.title = titleData.TH; } else { document.title = titleData.EN; } } /** 进入场景 */ function loadInScene() { loadProgre = 100; loadText.innerHTML = 'loading......' + parseInt(100) + '%'; var progressBar = tiao.querySelector('.progress-bar span'); progressBar.style.width = loadProgre.toFixed(2) + '%'; setTimeout(() => { loadImg.remove(); tiao.remove(); loadText.remove(); webText.remove(); }, 0.1 * 1000); }; /** 初始化 谷歌广告 */ function initGooleAds() { var googleJs = document.createElement("script"); googleJs.setAttribute("async", ""); googleJs.src = "//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"; document.body.appendChild(googleJs); var googleAds = document.createElement("script"); googleAds.setAttribute("async", ""); googleJs.setAttribute("data-ad-client", "ca-pub-1822513820197776"); googleJs.setAttribute("data-ad-channel", googleAdsID); googleJs.setAttribute("data-ad-frequency-hint", "15s"); document.body.appendChild(googleAds); window.adsbygoogle = window.adsbygoogle || []; adBreak = function (o) { adsbygoogle.push(o); } adBreak({ preloadAdBreaks: 'on', onReady: () => { console.log('onReady'); }, }); } /** 刷新加载进度条 假的 t:多长时间进度+1 */ function updateLoadText(t) { setTimeout(() => { loadProgre++; if (loadProgre >= 100) { return; } loadText.innerHTML = 'loading......' + parseInt(loadProgre) + '%'; var progressBar = tiao.querySelector('.progress-bar span'); progressBar.style.width = loadProgre.toFixed(2) + '%'; switch (loadProgre) { case 20: updateLoadText(0.05); break; case 40: updateLoadText(0.1); break; case 60: updateLoadText(0.2); break; case 80: updateLoadText(0.5); break; case 96: updateLoadText(5); break; case 98: updateLoadText(10); break; case 99: updateLoadText(1000); break; default: updateLoadText(t); break; } }, t * 1000); } /** 新建一个html 文本 */ function newHtmlText(id = "", style = "") { var loadingText = document.createElement("div"); loadingText.style = style; loadingText.id = id; loadingText.type = "text"; document.body.appendChild(loadingText); return loadingText; } /** 新建一个html 图像 */ function newHtmlImg(id = "", style = "", url = "", width = 100, height = 100) { var imgdiv = document.createElement("div"); imgdiv.style = style; imgdiv.id = id; var img = document.createElement("img"); img.src = url img.height = height; img.width = width; imgdiv.appendChild(img); document.body.appendChild(imgdiv); return imgdiv; }