diff --git a/handler.php b/handler.php
index e85130a..30f2a74 100644
--- a/handler.php
+++ b/handler.php
@@ -53,6 +53,17 @@ else if (isset($_POST['action']))
}
break;
+ case 'title':
+ $result = array();
+ $str = file_get_contents($_POST['data']);
+ if(strlen($str) > 0)
+ {
+ preg_match("/\
(.*)\<\/title\>/", $str, $title);
+ $result['title'] = $title[1];
+ }
+ echo json_encode($result);
+ break;
+
default:
echo '{"error": "unknown action ' . $action . '"}';
break;
diff --git a/main.js b/main.js
index 3620092..cf2a0f6 100644
--- a/main.js
+++ b/main.js
@@ -40,6 +40,7 @@ var pending = false;
var settings = null;
var tags = null;
var linkpopupid = null;
+var titlemap = {};
var stat =
{
@@ -806,12 +807,36 @@ function showlinkdialog(link)
var a = document.createElement("a");
a.setAttribute("id", "linkelt");
- if (link.startsWith("https://"))
+ if (link.startsWith("http"))
{
a.setAttribute("href", link);
a.setAttribute("target", "_blank");
- a.innerText = link;
div.onclick = removelinkdialog;
+
+ if (settings.sync)
+ {
+ if (titlemap[link])
+ {
+ a.innerText = titlemap[link];
+ }
+ else
+ {
+ a.innerText = link;
+ queryremote({action: "title", data: link})
+ .then(res =>
+ {
+ if (res.title)
+ {
+ a.innerText = res.title;
+ titlemap[link] = res.title;
+ }
+ });
+ }
+ }
+ else
+ {
+ a.innerText = link;
+ }
}
else
{
@@ -854,7 +879,7 @@ function clickeditor()
searchinlist(tags[tag.toLowerCase()])
.then(loadnote);
}
- else if (word.startsWith("https://"))
+ else if (word.startsWith("http"))
{
window.open(word, '_blank');
}
@@ -870,7 +895,7 @@ function clickeditor()
else
{
var word = wordatpos();
- if (word.startsWith("https://"))
+ if (word.startsWith("http"))
{
showlinkdialog(word);
}
@@ -2569,6 +2594,10 @@ function esc(event)
filter.placeholder = "Search...";
md.focus();
}
+ else if (settings.uselinkpopup && typeof linkdialog != "undefined")
+ {
+ removelinkdialog();
+ }
else if (currentnote.title == "Help" || currentnote.title == "Search result")
{
loadlast();