Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ToQoz/7637999 to your computer and use it in GitHub Desktop.
Save ToQoz/7637999 to your computer and use it in GitHub Desktop.
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