Files
Trilium/src/scripts/fixes/activelink.ts

27 lines
867 B
TypeScript
Raw Normal View History

2023-09-22 23:57:17 -04:00
/**
* For some reason Trilium share chooses to have the
* active link be just a <strong> rather than a true
* link with a special style. This fixes that and
* turns the <strong> back into an actual link
* with the correct note id.
2023-09-23 07:21:38 -04:00
*
* TODO: make it fix aliases too
2023-09-22 23:57:17 -04:00
*/
2023-09-23 07:21:38 -04:00
export default function fixActiveLink(aliases: Record<string, string>) {
2023-09-21 03:18:11 -04:00
const active = document.querySelector("#menu strong");
if (!active) return; // Something is really wrong
2023-09-22 23:57:17 -04:00
// Currently active note id is stored on body
2023-09-23 07:21:38 -04:00
const id = document.body.dataset.noteId!;
const href = aliases[id] ?? id;
2023-09-22 23:57:17 -04:00
// Create the new link
2023-09-21 03:18:11 -04:00
const link = document.createElement("a");
link.className = "type-text active";
link.href = ``;
link.textContent = active.textContent;
2023-09-23 07:21:38 -04:00
link.href = `./${href}`;
2023-09-22 23:57:17 -04:00
// Replace the <strong>
active.replaceWith(link);
2023-09-21 03:18:11 -04:00
}