Created
January 6, 2016 10:20
-
-
Save towry/1dbaaa53dad85c5ca673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var __on = false; | |
var vis = (function(){ | |
var stateKey, eventKey, keys = { | |
hidden: "visibilitychange", | |
webkitHidden: "webkitvisibilitychange", | |
mozHidden: "mozvisibilitychange", | |
msHidden: "msvisibilitychange" | |
}; | |
for (stateKey in keys) { | |
if (stateKey in document) { | |
eventKey = keys[stateKey]; | |
break; | |
} | |
} | |
return function(c) { | |
if (c) document.addEventListener(eventKey, c); | |
return !document[stateKey]; | |
} | |
})(); | |
var or = document.title; | |
vis(function () { | |
if (!vis()) { | |
__on = true; | |
changeTitle(); | |
} else { | |
__on = false; | |
document.title = or; | |
} | |
}) | |
function changeTitle () { | |
if (!__on) return; | |
var a = '你有新消息'; | |
if (document.title == a) { | |
document.title = or; | |
} else { | |
document.title = a; | |
} | |
setTimeout(changeTitle, 500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment