aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2023-01-30 13:06:12 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2023-01-30 13:06:12 +0300
commitbe78534e0327284378caf23752969eb0502f2744 (patch)
treefc3ff8f7f993a5abfbd369d15eb53aff3c9c6d8c
parentd49c50792fb2c64e45e356b318eeaeca996e7ce9 (diff)
downloadhovercard.js-be78534e0327284378caf23752969eb0502f2744.tar.gz
hovercard.js-be78534e0327284378caf23752969eb0502f2744.zip
feat: add special treatment for h-cards
-rw-r--r--README.md3
-rw-r--r--hovercard.js19
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 = "<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();