diff options
-rw-r--r-- | hovercard.js | 32 |
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 |