You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
NewEduCoderBuild/js/public.js

207 lines
7.8 KiB

document.body.parentNode.id = "educoder";
// var iframe = document.createElement('iframe');
// if (
// document.domain === 'www.tokcoder.com' ||
// document.domain === 'tokcoder.com'
// ) {
// iframe.src = 'https://www.educoder.net/autologin.html?t=' + Date.now();
// } else {
// iframe.src = 'https://www.tokcoder.com/autologin.html?t=' + Date.now();
// }
// iframe.sandbox =
// 'allow-scripts allow-same-origin allow-top-navigation allow-forms allow-popups allow-pointer-lock allow-popups-to-escape-sandbox allow-presentation allow-top-navigation-by-user-activation';
// iframe.allow = 'geolocation document-domain';
// iframe.style.position = 'absolute';
// iframe.style.top = '-1000px';
// iframe.style.opacity = 0;
// iframe.style.visibility = 'hidden';
// iframe.style.zIndex = -1;
// document.body.appendChild(iframe);
// iframe.onload = function() {
// iframe.contentWindow.postMessage(
// { type: 'cookie', data: document.cookie },
// '*',
// );
// };
window.gtag = new Function;
function setTop() {
if ((location.host.indexOf("ilearning") > -1 || location.host.indexOf("i-learning") > -1) && location.pathname.indexOf("/tasks") === -1) {
document.getElementById("root").style.paddingTop = "60px"
}
// saia默认进入竞赛
if(document.domain === "saia.educoder.net" && location.pathname === "/"){
location.href = "/competitions/shszyjnds-2023/list"
}
}
// window.addEventListener('popstate', function () {
// setTop();
// })
setTop();
const _historyWrap = function(type) {
const orig = history[type];
const e = new Event(type);
return function() {
const rv = orig.apply(this, arguments);
e.arguments = arguments;
window.dispatchEvent(e);
return rv;
};
};
history.pushState = _historyWrap('pushState');
history.replaceState = _historyWrap('replaceState');
window.addEventListener('pushState', function(e) {
setTop();
});
window.addEventListener('replaceState', function(e) {
setTop();
});
if (window.ENV !== 'dev') {
console.log = new Function;
}
function IEVersion() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if (isIE || isIE11) {
window.location.replace('/react/build/upgrade-browser.html');
}
}
IEVersion();
function getChromeVersion() {
var arr = navigator.userAgent.split(' ');
var chromeVersion = '';
for (var i = 0; i < arr.length; i++) {
if (/chrome/i.test(arr[i]))
chromeVersion = arr[i]
}
if (chromeVersion) {
return Number(chromeVersion.split('/')[1].split('.')[0]);
} else {
return false;
}
}
if (getChromeVersion()) {
var version = getChromeVersion();
if (!!version && version < 70) {
window.location.replace('/upgrade-browser.html');
}
}
window.addEventListener("storage", function (e) {
if(e.key === "loginOut"){
if(this.location.pathname.indexOf("/exercise") > -1 && this.location.pathname.indexOf("/users") > -1 )
window.location.href = "/"
else
window.location.reload();
}
})
var isShowError = false;
function showNetworkError(){
if(/mobile/i.test(navigator.userAgent)){
return;
}
if(isShowError) return;
var arr = [];
var dom = document.createElement("div");
arr.push("<div id='showErrorWrp'>");
arr.push(" <div class=\'ant-modal-root animated fadeInUp\'>");
arr.push(" <div class=\'ant-modal-mask\'></div>");
arr.push(" <div");
arr.push(" tabindex=\'-1\'");
arr.push(" class=\'ant-modal-wrap ant-modal-confirm-centered ant-modal-centered\'");
arr.push(" >");
arr.push(" <div");
arr.push(" role=\'dialog\'");
arr.push(" aria-modal=\'true\'");
arr.push(" class=\'ant-modal ant-modal-confirm ant-modal-confirm-warning\'");
arr.push(" style=\'width: 500px\'");
arr.push(" >");
arr.push(" <div");
arr.push(" tabindex=\'0\'");
arr.push(" aria-hidden=\'true\'");
arr.push(" style=\'width: 0px; height: 0px; overflow: hidden; outline: none\'");
arr.push(" ></div>");
arr.push(" <div class=\'ant-modal-content\'>");
arr.push(" <div class=\'ant-modal-body\'>");
arr.push(" <div class=\'ant-modal-confirm-body-wrapper\'>");
arr.push(" <div class=\'ant-modal-confirm-body\'>");
arr.push(" <span");
arr.push(" role=\'img\'");
arr.push(" aria-label=\'exclamation-circle\'");
arr.push(" class=\'anticon anticon-exclamation-circle\'");
arr.push(" ><svg");
arr.push(" viewBox=\'64 64 896 896\'");
arr.push(" focusable=\'false\'");
arr.push(" data-icon=\'exclamation-circle\'");
arr.push(" width=\'1em\'");
arr.push(" height=\'1em\'");
arr.push(" fill=\'currentColor\'");
arr.push(" aria-hidden=\'true\'");
arr.push(" >");
arr.push(" <path");
arr.push(" d=\'M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372 372 166.6 372 372-166.6 372-372 372z\'");
arr.push(" ></path>");
arr.push(" <path");
arr.push(" d=\'M464 688a48 48 0 1096 0 48 48 0 10-96 0zm24-112h48c4.4 0 8-3.6 8-8V296c0-4.4-3.6-8-8-8h-48c-4.4 0-8 3.6-8 8v272c0 4.4 3.6 8 8 8z\'");
arr.push(" ></path></svg></span");
arr.push(" ><span class=\'ant-modal-confirm-title\'");
arr.push(" >您的网络好像有问题!</span");
arr.push(" >");
arr.push(" <div class=\'ant-modal-confirm-content\'>");
arr.push(" 很抱歉,我们无法加载所需的资源。请检查您的网络连接并重新加载页面。");
arr.push(" </div>");
arr.push(" </div>");
arr.push(" <div class=\'ant-modal-confirm-btns\'>");
arr.push(" <button type=\'button\' id='showErrorButtonCancel' class=\'ant-btn ant-btn-default\'>");
arr.push(" 继续访问");
arr.push(" </button>");
arr.push(" <button type=\'button\' id='showErrorButtonOk' class=\'ant-btn ant-btn-primary\'>");
arr.push(" 刷新重试");
arr.push(" </button>");
arr.push(" </div>");
arr.push(" </div>");
arr.push(" </div>");
arr.push(" </div>");
arr.push(" <div");
arr.push(" tabindex=\'0\'");
arr.push(" aria-hidden=\'true\'");
arr.push(" style=\'width: 0px; height: 0px; overflow: hidden; outline: none\'");
arr.push(" ></div>");
arr.push(" </div>");
arr.push(" </div>");
arr.push(" </div>");
arr.push("</div>");
arr.push("");
dom.innerHTML = arr.join("")
document.body.appendChild(dom)
dom.onclick = function(e){
if(e.target.id === 'showErrorButtonOk'){
location.reload()
}else if(e.target.id === 'showErrorButtonCancel'){
isShowError = false;
document.body.removeChild(dom)
}
}
}
try {
new PerformanceObserver((entryList) => {
entryList.getEntries().forEach((entry) => {
if(entry.transferSize === 0 && entry.initiatorType === "script" && entry.decodedBodySize === 0 && entry.name.indexOf(".educoder.net") > -1){
// showNetworkError()
}
})
}).observe({ entryTypes: ['resource'] })
} catch (error) {
}