Created
February 10, 2016 00:13
-
-
Save karlcow/031a0a23bb094e06b9a4 to your computer and use it in GitHub Desktop.
useless script detected on https://fabriceleven.com/design/moo-luxe-review-business-cards/ which changes the title of the tab when moving to another tab.
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
// found on https://fabriceleven.com/design/moo-luxe-review-business-cards/ | |
//add some cool text to the title | |
(function() { | |
var hidden = "hidden"; | |
var oldtitle = document.title; | |
var currenttitle; | |
// Standards: | |
if (hidden in document) | |
document.addEventListener("visibilitychange", onchange); | |
else if ((hidden = "mozHidden") in document) | |
document.addEventListener("mozvisibilitychange", onchange); | |
else if ((hidden = "webkitHidden") in document) | |
document.addEventListener("webkitvisibilitychange", onchange); | |
else if ((hidden = "msHidden") in document) | |
document.addEventListener("msvisibilitychange", onchange); | |
// IE 9 and lower: | |
else if ("onfocusin" in document) | |
document.onfocusin = document.onfocusout = onchange; | |
// All others: | |
else | |
window.onpageshow = window.onpagehide | |
= window.onfocus = window.onblur = onchange; | |
function onchange (evt) { | |
var v = "visible", h = "hidden", | |
evtMap = { | |
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h | |
}; | |
evt = evt || window.event; | |
if (evt.type in evtMap) { | |
currenttitle = oldtitle; | |
$(document).attr('title', currenttitle); | |
} | |
else { | |
currenttitle = this[hidden] ? "Miss You ︎:( " : oldtitle; | |
$(document).attr('title', currenttitle); | |
} | |
} | |
// set the initial state (but only if browser supports the Page Visibility API) | |
if( document[hidden] !== undefined ) | |
onchange({type: document[hidden] ? "blur" : "focus"}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment