forked from ao5357/development_favicon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
35 lines (31 loc) · 1.51 KB
/
content.js
File metadata and controls
35 lines (31 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (!message.favIconUrl) {
// Set a default to pass back.
var favIconUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3gEVFSYuu6K2kgAAAMxJREFUOMu9UssOgjAQnK0PYvw35M4Nvwmu6IJ8oikm7HpQkFIeQRMn2WS3mU5mugV+BLVNURQ6RYrj+AjAvvkbY8zDIzGzWmu9yrJMmVlF5CAiOxHZ9e+ZthF5GbC27qpFGJ7AXNwBNAB0VEBVZ7NGUYTrlZt+bADYfhwIAAIReU9UVbfuJM8vj77IdslBkpyduSxLzDhwUde1MwdB4PEcASLASTDcOWFeYPA1RjEUMHMRVgksrXGK50UgWudgsEbCfh9860CRphn+jifEvoLrs8T+3wAAAABJRU5ErkJggg==';
// Find an existing favicon to use as the URL.
var links = document.head.getElementsByTagName("link");
for (var i=0; i<links.length; i++) {
if (links[i].getAttribute("rel").match(/^(shortcut )?icon$/i)) {
favIconUrl = links[i].href;
}
}
// Send either the URL or the default.
sendResponse({'favIconUrl': favIconUrl});
}
else {
// Create a new favicon link.
var favicon = document.createElement("link");
favicon.setAttribute("rel", "icon");
favicon.type = "image/x-icon";
favicon.href = message.favIconUrl;
// Remove existing favicon links.
var links = document.head.getElementsByTagName("link");
for (var i=0; i<links.length; i++) {
if (links[i].getAttribute("rel").match(/^(shortcut )?icon$/i)) {
document.head.removeChild(links[i]);
}
}
// Append the new favicon.
document.head.appendChild(favicon);
}
});