Created
November 25, 2013 08:08
-
-
Save ToQoz/7637999 to your computer and use it in GitHub Desktop.
This file contains 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 favicon = { | |
retryCount: 0, | |
retryLimit: 10, | |
change: function(url, cond) { | |
if (cond()) { | |
if (this.node().href != url) { | |
this.node().href = url; | |
// 後で書き換えられることもあるので適当にリトライする | |
setTimeout(function() { | |
this.change(url, cond); | |
}.bind(this), 3000); | |
return; | |
} | |
} else { | |
// JavaScriptで設定してることもあるので、onload時に条件にあてはまらなくても、適当にリトライする | |
setTimeout(function() { | |
this.retryCount += 1; | |
if (this.retryCount > this.retryLimit) { | |
return; | |
} | |
this.change(url, cond); | |
}.bind(this), 200); | |
} | |
}, | |
node: function() { | |
return document.querySelector('link[type="image/x-icon"]'); | |
}, | |
}; | |
window.onload = function() { | |
Object.create(favicon).change("https://0.gravatar.com/avatar/0fc04021f02f1d38bd366d3ca8c7f8b4", function() { | |
return (/toqoz/.test(document.querySelector("title").innerText)); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment