diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | hovercard.js | 19 |
2 files changed, 17 insertions, 5 deletions
@@ -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 = "<strong>" + hovercard_data["title"] + "</strong>" + if (hovercard_data["pname"]) { + new_box.innerHTML = "<strong>" + hovercard_data["pname"] + "</strong>" + } else { + if (hovercard_data["title"]) { + new_box.innerHTML = "<strong>" + hovercard_data["title"] + "</strong>" + } } if (hovercard_data["description"]) { new_box.innerHTML = new_box.innerHTML + "<p>" + hovercard_data["description"] + "</p>"; } // if image available, add it - if (hovercard_data["image"]) { - new_box.innerHTML = "<img src='" + hovercard_data["image"] + "' alt='" + hovercard_data["title"] + "' /><br>" + new_box.innerHTML; + if (hovercard_data["uphoto"]) { + new_box.innerHTML = "<img src='" + hovercard_data["uphoto"] + "' alt='" + hovercard_data["pname"] + "' /><br>" + new_box.innerHTML; + } else { + if (hovercard_data["image"]) { + new_box.innerHTML = "<img src='" + hovercard_data["image"] + "' alt='" + hovercard_data["title"] + "' /><br>" + 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(); |