获取网站图标

2023-12-11 20:34:35 浏览数 (1)

获取网站图标

废话不多说,贴代码了。

代码语言: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;");
    }
});

0 人点赞