Skip to content

Instantly share code, notes, and snippets.

@riocampos
Last active August 29, 2015 14:08
Show Gist options
  • Save riocampos/423b5995de644e5b563d to your computer and use it in GitHub Desktop.
Save riocampos/423b5995de644e5b563d to your computer and use it in GitHub Desktop.
Web Icon Get bookmarklet (refer: http://superuser.com/a/517812)
javascript:(function(){var%20e%3d%5b%5d%3bvar%20t%3d%22%22%3bvar%20n%3ddocument%2egetElementsByTagName%28%22link%22%29%3bvar%20r%3ddocument%2egetElementsByTagName%28%22meta%22%29%3bif%28n%2elength%3e0%29%7bfor%28var%20i%3d0%3bi%3cn%2elength%3bi%2b%2b%29%7bif%28n%5bi%5d%2ehref%2elastIndexOf%28%22apple%2dtouch%2dicon%2epng%22%29%3e%2d1%7c%7cn%5bi%5d%2erel%2eindexOf%28%22apple%2dtouch%2dicon%22%29%3e%2d1%29%7be%2epush%28n%5bi%5d%2ehref%29%3bt%3d%22Web%20Clip%20Icon%22%7d%7dif%28e%2elength%3d%3d%3d0%29%7bfor%28var%20i%3d0%3bi%3cn%2elength%3bi%2b%2b%29%7bif%28typeof%20n%5bi%5d%2erel%21%3d%3d%22undefined%22%26%26n%5bi%5d%2erel%2eindexOf%28%22icon%22%29%3e%2d1%29%7be%2epush%28n%5bi%5d%2ehref%29%3bt%3d%22Favicon%22%7d%7d%7dif%28e%2elength%3d%3d%3d0%29%7bfor%28var%20i%3d0%3bi%3cr%2elength%3bi%2b%2b%29%7bif%28r%5bi%5d%2egetAttribute%28%22property%22%29%21%3dnull%26%26r%5bi%5d%2egetAttribute%28%22property%22%29%2eindexOf%28%22og%3aimage%22%29%3e%2d1%29%7be%2epush%28r%5bi%5d%2econtent%29%3bt%3d%22Open%20Graph%20Protocol%22%7d%7d%7dif%28e%2elength%3d%3d%3d0%29%7balert%28%22Any%20icon%20image%20is%20not%20found%22%29%7delse%7bvar%20s%3dt%2b%22%5cn%22%3bfor%28var%20i%3d0%3bi%3ce%2elength%3bi%2b%2b%29%7bs%2b%3de%5bi%5d%2b%22%5cn%22%7dalert%28s%29%7d%7delse%7balert%28%22Any%20icon%20image%20is%20not%20found%22%29%7d})()
(function() {
var icons = [];
var type = "";
var arrLink = document.getElementsByTagName('link');
var arrMeta = document.getElementsByTagName('meta');
if (arrLink.length > 0) {
for (var i=0; i < arrLink.length; i++) {
if (arrLink[i].href.lastIndexOf('apple-touch-icon.png') > -1 || arrLink[i].rel.indexOf('apple-touch-icon') > -1) {
icons.push(arrLink[i].href);
type = "Web Clip Icon";
}
}
if (icons.length === 0) {
for (var i=0; i < arrLink.length; i++) {
if (typeof arrLink[i].rel !== 'undefined' && arrLink[i].rel.indexOf('icon') > -1) {
icons.push(arrLink[i].href);
type = "Favicon";
}
}
}
if (icons.length === 0) {
for (var i=0; i < arrMeta.length; i++) {
if (arrMeta[i].getAttribute("property") != null && arrMeta[i].getAttribute("property").indexOf('og:image') > -1) {
icons.push(arrMeta[i].content);
type = "Open Graph Protocol";
}
}
}
if (icons.length === 0) {
alert('Any icon image is not found');
} else {
var hrefs = type + "\n"
for (var i=0; i < icons.length; i++) {
hrefs += (icons[i] + "\n");
}
alert(hrefs);
}
} else {
alert('Any icon image is not found');
}
})();
(function() {
var icons = [];
// var type = "";
var arrLink = document.getElementsByTagName('link');
var arrMeta = document.getElementsByTagName('meta');
if (arrLink.length > 0) {
for (var i=0; i < arrLink.length; i++) {
if (arrLink[i].href.lastIndexOf('apple-touch-icon.png') > -1 || arrLink[i].rel.indexOf('apple-touch-icon') > -1) {
icons.push("Web Clip Icon: "+arrLink[i].href);
}
}
for (var i=0; i < arrLink.length; i++) {
if (typeof arrLink[i].rel !== 'undefined' && arrLink[i].rel.indexOf('icon') > -1) {
icons.push("Favicon: "+arrLink[i].href);
}
}
}
var faviconUrl = "http://"+location.hostname+"/favicon.ico";
icons.push("Favicon(if exist): "+faviconUrl);
if (arrMeta.length > 0) {
for (var i=0; i < arrMeta.length; i++) {
if (arrMeta[i].getAttribute("property") != null && arrMeta[i].getAttribute("property").indexOf('og:image') > -1) {
icons.push("Open Graph Protocol: "+arrMeta[i].content);
}
}
}
console.log(icons.join("\n"));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment