获取网站图标
代码语言:javascript复制废话不多说,贴代码了。
let links = document.querySelectorAll("link[rel*='icon']");
Array.prototype.filter.call(links, function(link) {
let url = link.getAttribute('href');
if (url.substring(0, 2) == '//') {
console.log(`%c图标地址:%chttp:${url}`,"line-height:28px;padding:4px;background:#a1afc9;color:#000;font-size:16px;margin-right:15px", "color:#3fa9f5;line-height:28px;font-size:16px;");
} else if (url.substring(0, 4) == 'http' || url.substring(0, 5) == 'https') {
console.log(url);
} else {
let allurl = (url.substring(0, 1) == '/') ?
'http://' window.location.host url :
'http://' window.location.host '/' url;
console.log(`%c图标地址:%c${allurl}`,"line-height:28px;padding:4px;background:#a1afc9;color:#000;font-size:16px;margin-right:15px", "color:#3fa9f5;line-height:28px;font-size:16px;");
}
});