added: popup to follow links

This commit is contained in:
quenousimporte 2023-11-13 17:17:38 +01:00
parent 9981af5f3b
commit d5b261cc88
2 changed files with 75 additions and 2 deletions

62
main.js
View File

@ -19,7 +19,8 @@ var defaultsettings =
sync: false, sync: false,
tagsinlists: true, tagsinlists: true,
tagfilter: "", tagfilter: "",
darkcode: true darkcode: true,
uselinkpopup: true
}; };
//builtin //builtin
@ -783,6 +784,47 @@ function tagatpos()
return md.value.substring(start + 1, end); return md.value.substring(start + 1, end);
} }
function removelinkdialog()
{
if (typeof linkdialog != "undefined")
{
notepage.removeChild(linkdialog);
}
}
function showlinkdialog(link)
{
var div = document.createElement("div");
div.setAttribute("style", "top:" + event.pageY + "px;left:" + event.pageX + "px");
div.setAttribute("id", "linkdialog");
var a = document.createElement("a");
a.setAttribute("id", "linkelt");
if (link.startsWith("https://"))
{
a.setAttribute("href", link);
a.setAttribute("target", "_blank");
a.innerText = link;
div.onclick = removelinkdialog;
}
else
{
a.setAttribute("href", "#");
a.innerText = link;
div.onclick = function()
{
removelinkdialog();
loadnote(link);
};
}
div.appendChild(a);
setTimeout(removelinkdialog, 3000);
notepage.appendChild(div);
}
function clickeditor() function clickeditor()
{ {
if (!saved) if (!saved)
@ -790,6 +832,7 @@ function clickeditor()
console.log("Not saved, ctrl+click ignored."); console.log("Not saved, ctrl+click ignored.");
return; return;
} }
if (event.ctrlKey) if (event.ctrlKey)
{ {
var link = linkatpos(); var link = linkatpos();
@ -810,6 +853,23 @@ function clickeditor()
window.open(word, '_blank'); window.open(word, '_blank');
} }
} }
else if (settings.uselinkpopup)
{
removelinkdialog();
var link = linkatpos();
if (link)
{
showlinkdialog(link);
}
else
{
var word = wordatpos();
if (word.startsWith("https://"))
{
showlinkdialog(word);
}
}
}
} }
function restoresettings() function restoresettings()

View File

@ -142,5 +142,18 @@ body::-webkit-scrollbar-thumb {
/* colors */ /* colors */
.color-code { .color-code {
color:white; color:white;
background-color:black; background-color:rgb(55, 53, 47);
}
/* link dialog */
#linkdialog {
border-radius: 3px;
opacity:1;
color: white;
background-color:rgb(55, 53, 47);
position:absolute;
}
#linkelt {
margin: 5px 7px 5px 7px;
} }