开发者

Title-changing effect/window event listener does not work

开发者 https://www.devze.com 2022-12-21 19:29 出处:网络
I tried to search but cou开发者_运维百科ld not find out anything useful. This is a piece of code for my Greasemonkey script. Basically, I want to have the same effect as Gmail. When the page loads and

I tried to search but cou开发者_运维百科ld not find out anything useful. This is a piece of code for my Greasemonkey script. Basically, I want to have the same effect as Gmail. When the page loads and you have new messages, the title will change repeatedly and make you notice. The problem is it does not work for the first time.

For example, if the user opens the page on new tab and does not move to the page, it does not work. But if the user moves to the tab and then moves to another tab, the script works.

Can anyone point me the right direction?

function startBlink(){
    window.blinkInterval = setInterval(function(){
    if(document.title != "Message"){document.title = "Message";}
    else{document.title = "Application";}
   } , 1000);
}
function blink(){ 
    document.addEventListener("blur",function(){setTimeout(startBlink(),1000);},false);
    document.addEventListener("focus",function(){clearInterval(window.blinkInterval);},false);
}

window.addEventListener("load",blink,false);


have you thought about changing (iterating through multiple variants of) window title instead of blinking (blur/focus)? that also attracts an eye.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号