oak-cli/plugins/injects/version-check.js

102 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function() {
var sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/firefox\/([\d.]+)/))
? (sys.firefox = s[1])
: (s = ua.match(/chrome\/([\d.]+)/))
? (sys.chrome = s[1])
: (s = ua.match(/opera.([\d.]+)/))
? (sys.opera = s[1])
: (s = ua.match(/rv:([\d.]+)/))
? (sys.ie = s[1])
: (s = ua.match(/msie ([\d.]+)/))
? (sys.ie = s[1])
: (s = ua.match(/version\/([\d.]+).*safari/))
? (sys.safari = s[1])
: 0;
var browser = 'Unknown';
var tip = document.createElement('div');
var closeBtn = document.createElement('img');
var contentHTML =
'您当前使用的浏览器可能会出现界面显示异常或功能无法正常使用等问题建议下载使用谷歌火狐edge等新版本浏览器。';
var handleClickClose = function (event) {
document.body.removeChild(tip);
};
var startAppend = function () {
document.body.appendChild(tip);
tip.appendChild(closeBtn);
};
// closeBtn.style.position = 'absolute';
// closeBtn.style.right = '20px';
// closeBtn.style.bottom = '7px';
// closeBtn.style.cursor = 'pointer';
// closeBtn.style.width = '15px';
// closeBtn.style.height = '15px';
// closeBtn.src = '../assets/images/icon-close.png';
// closeBtn.alt = '关闭';
// if (closeBtn.addEventListener) {
// closeBtn.addEventListener('click', handleClickClose);
// } else {
// // IE8 及以下
// closeBtn.attachEvent('onclick', handleClickClose);
// }
tip.style.position = 'relative';
tip.style.backgroundColor = 'yellow';
tip.style.color = 'red';
tip.style.position = 'fixed';
tip.style.top = 0;
tip.style.right = 0;
tip.style.left = 0;
tip.style.padding = '5px 20px';
tip.style.fontSize = '14px';
if (sys.ie) {
browser = 'IE';
tip.innerHTML = contentHTML;
startAppend();
}
if (sys.firefox) {
browser = 'Firefox';
}
if (sys.chrome) {
browser = 'Chrome';
var getChromeVersion = function () {
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();
// 如果 360 极速浏览器并切换到极速模式低于86版本
if (version < 87) {
tip.innerHTML =
'您当前使用的浏览器版本过低使用可能会出现界面显示异常或功能无法正常使用等问题建议下载使用谷歌火狐edge等新版本浏览器。';
startAppend();
}
}
}
if (sys.opera) {
browser = 'Opera';
tip.innerHTML = contentHTML;
startAppend();
}
if (sys.safari) {
browser = 'Safari';
}
})();