JS
<script type="text/javascript" language="javascript">
var time;
var normar_title=document.title;
document.addEventListener('visibilitychange', function () {
if (document.visibilityState == 'hidden') {
clearTimeout(time);
document.title = '客官请留步ε=ε=ε=┏(゜ロ゜;)┛';
} else {
document.title = '你终于回来了(。・∀・)ノ';
time=setTimeout(function(){ document.title = normar_title; }, 3000);
}
});
</script>
或者
var OriginTitle = document.title;
var titleTime;
document.addEventListener('visibilitychange', function () {
if (document.hidden) {
//$('[rel="icon"]').attr('href', "/img/trhx2.png");
document.title = 'ヽ(●-`Д´-)ノ你丑你就走!';
clearTimeout(titleTime);
}
else {
//$('[rel="icon"]').attr('href', "/img/trhx2.png");
document.title = 'ヾ(Ő∀Ő3)ノ你帅就回来!' + OriginTitle;
titleTime = setTimeout(function () {
document.title = OriginTitle;
}, 2000);
}
});
再或者
window.onload = function () {
let hour = new Date().getHours()
let str = ''
if (hour < 6) {
str = '修仙中……'
} else if (hour < 9) {
str = '早上好!'
} else if (hour < 12) {
str = '上午好!'
} else if (hour < 14) {
str = '中午好!'
} else if (hour < 17) {
str = '下午好!'
} else if (hour < 19) {
str = '傍晚好!'
} else if (hour < 22) {
str = '晚上好!'
} else {
str = '夜深了,要早点休息哦!'
}
function c () {
document.title = document[a] ? '㋡ Hi,小伙伴,' + str + '好! [' + d + ']' : d
}
let a = document.title
let b = document.title
let d = document.title
typeof document.hidden !== 'undefined' ? (a = 'hidden', b = 'visibilitychange')
: typeof document.mozHidden !== 'undefined' ? (a = 'mozHidden', b = 'mozvisibilitychange')
: typeof document.webkitHidden !== 'undefined' && (a = 'webkitHidden', b = 'webkitvisibilitychange')
typeof document.addEventListener === 'undefined' && typeof document[a] === 'undefined' || document.addEventListener(b, c, !1)
}