aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2022-12-01 00:08:48 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2022-12-01 00:08:48 +0300
commit6c0724ac273746addd4aa322bb2cc2c6f7bba7c2 (patch)
tree12a846fc80211e862c9bed1577968ee48abab192
parentb7f376656951b837d1f3c766734a0049afe86b44 (diff)
downloadhovercard.js-6c0724ac273746addd4aa322bb2cc2c6f7bba7c2.tar.gz
hovercard.js-6c0724ac273746addd4aa322bb2cc2c6f7bba7c2.zip
feat: handle footnotes
-rw-r--r--hovercard.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/hovercard.js b/hovercard.js
index f9de005..a4b7506 100644
--- a/hovercard.js
+++ b/hovercard.js
@@ -13,7 +13,9 @@ var hovercards = {
if (hovercard_data) {
var new_box = document.createElement("div");
new_box.classList.add("hovercard");
- new_box.innerHTML = "<strong>" + hovercard_data["title"] + "</strong>"
+ 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>";
}
@@ -57,17 +59,25 @@ var hovercards = {
});
let url = links[i].href.replace(/\/+$/, "");
if (!hovercards[url]) {
- let req = 'https://indieweb-glue.evgenykuznetsov.org/api/opengraph?url=';
- req += url;
- const r = encodeURI(req);
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- hovercards[url] = JSON.parse(this.responseText);
+ if (links[i].hostname == window.location.hostname && links[i].pathname == window.location.pathname) {
+ if (links[i].hash) {
+ // this is an achor somewhere on the same page, give a peek in case it's a footnote
+ let desc = document.getElementById(links[i].hash.replace("#", "")).innerText
+ hovercards[url] = {"description": desc}
}
- };
- xmlhttp.open("GET", r, true);
- xmlhttp.send();
+ } else {
+ let req = 'https://indieweb-glue.evgenykuznetsov.org/api/opengraph?url=';
+ req += url;
+ const r = encodeURI(req);
+ var xmlhttp = new XMLHttpRequest();
+ xmlhttp.onreadystatechange = function() {
+ if (this.readyState == 4 && this.status == 200) {
+ hovercards[url] = JSON.parse(this.responseText);
+ }
+ };
+ xmlhttp.open("GET", r, true);
+ xmlhttp.send();
+ }
}
}
} \ No newline at end of file