added: fetch title for external links (remote mode only)

changed: hide link popup when press escape
This commit is contained in:
quenousimporte 2023-11-14 11:52:33 +01:00
parent b61688a486
commit b40446789b
2 changed files with 44 additions and 4 deletions

View File

@ -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\>(.*)\<\/title\>/", $str, $title);
$result['title'] = $title[1];
}
echo json_encode($result);
break;
default:
echo '{"error": "unknown action ' . $action . '"}';
break;

37
main.js
View File

@ -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();