From be78534e0327284378caf23752969eb0502f2744 Mon Sep 17 00:00:00 2001 From: Evgeny Kuznetsov Date: Mon, 30 Jan 2023 13:06:12 +0300 Subject: feat: add special treatment for h-cards --- README.md | 3 ++- hovercard.js | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 806ac4a..45c8d4a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,8 @@ Substitute the path of the script in the example above with the location of the ## Roadmap -[ ] Customized hovercards for H-Cards. +[x] Customized hovercards for H-Cards. +[ ] Show more information for H-Cards. ## License diff --git a/hovercard.js b/hovercard.js index a7f2c6d..c20220f 100644 --- a/hovercard.js +++ b/hovercard.js @@ -13,15 +13,23 @@ var hovercards = { if (hovercard_data) { var new_box = document.createElement("div"); new_box.classList.add("hovercard"); - if (hovercard_data["title"]) { - new_box.innerHTML = "" + hovercard_data["title"] + "" + if (hovercard_data["pname"]) { + new_box.innerHTML = "" + hovercard_data["pname"] + "" + } else { + if (hovercard_data["title"]) { + new_box.innerHTML = "" + hovercard_data["title"] + "" + } } if (hovercard_data["description"]) { new_box.innerHTML = new_box.innerHTML + "

" + hovercard_data["description"] + "

"; } // if image available, add it - if (hovercard_data["image"]) { - new_box.innerHTML = "" + hovercard_data["title"] + "
" + new_box.innerHTML; + if (hovercard_data["uphoto"]) { + new_box.innerHTML = "" + hovercard_data["pname"] + "
" + new_box.innerHTML; + } else { + if (hovercard_data["image"]) { + new_box.innerHTML = "" + hovercard_data["title"] + "
" + new_box.innerHTML; + } } new_box.style.top = window.scrollY + target_link.getBoundingClientRect().top + "px"; new_box.style.left = window.scrollX + target_link.getBoundingClientRect().left + "px"; @@ -67,6 +75,9 @@ var hovercards = { } } else { let req = 'https://indieweb-glue.evgenykuznetsov.org/api/pageinfo?url='; + if (Boolean(links[i].closest('.h-card'))) { + req = 'https://indieweb-glue.evgenykuznetsov.org/api/hcard?url='; + }; req += url; const r = encodeURI(req); var xmlhttp = new XMLHttpRequest(); -- cgit v1.2.3