From 8045326a8575a36389acf7f24a5e36c1364ea36a Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Wed, 26 Oct 2022 23:10:59 +0800 Subject: [PATCH] linkcard --- source/js/plugins/linkcard.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/js/plugins/linkcard.js b/source/js/plugins/linkcard.js index f7b57d7..38da2f6 100644 --- a/source/js/plugins/linkcard.js +++ b/source/js/plugins/linkcard.js @@ -31,8 +31,9 @@ function renderer(el, obj) { if (obj.icon && obj.icon.length > 0) { el.querySelector('.img').style = 'background-image: url("' + obj.icon + '");'; } - if (obj.desc && obj.desc.length > 0) { - el.querySelector('.desc').innerHTML = obj.desc; + let desc = el.querySelector('.desc'); + if (desc && obj.desc && obj.desc.length > 0) { + desc.innerHTML = obj.desc; } } @@ -53,9 +54,12 @@ function getInfo(el, html, link) { title = title.textContent // Get the src of the first img tag in the body tag - // icon = doc.querySelector('body img') - // icon = icon && icon.getAttribute('src') - + let tmp = doc.querySelector('head link[rel="apple-touch-icon"]') + if (!tmp) { + tmp = doc.querySelector('head link[rel="icon"]') + } + icon = tmp && tmp.getAttribute('href') + if (/^data:image/.test(icon)) icon = '' // If there is no src then get the site icon