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,
tagsinlists: true,
tagfilter: "",
darkcode: true
darkcode: true,
uselinkpopup: true
};
//builtin
@ -783,6 +784,47 @@ function tagatpos()
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()
{
if (!saved)
@ -790,6 +832,7 @@ function clickeditor()
console.log("Not saved, ctrl+click ignored.");
return;
}
if (event.ctrlKey)
{
var link = linkatpos();
@ -810,6 +853,23 @@ function clickeditor()
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()

View File

@ -142,5 +142,18 @@ body::-webkit-scrollbar-thumb {
/* colors */
.color-code {
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;
}