Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
added possibility of executing javascript
azivner27cb6b1c4de8
diff --git a/public/javascripts/note_editor.js b/public/javascripts/note_editor.jsindex 73b64749c3..50362b1f0a 100644--- a/public/javascripts/note_editor.js+++ b/public/javascripts/note_editor.js@@ -196,6 +196,14 @@ const noteEditor = (function() {return currentNote ? currentNote.detail.type : null;}+ function executeScript() {+ if (getCurrentNoteType() === 'code') {+ const script = codeEditor.getValue();++ eval(script);+ }+ }+$(document).ready(() => {noteTitleEl.on('input', () => {noteChanged();@@ -234,6 +242,8 @@ const noteEditor = (function() {noteDetailEl.attr("tabindex", 2);});+ $(document).bind('keydown', "ctrl+return", executeScript);+setInterval(saveNoteIfChanged, 5000);return {@@ -249,6 +259,7 @@ const noteEditor = (function() {getCurrentNoteId,newNoteCreated,getEditor,- focus+ focus,+ executeScript};})();\ No newline at end of filediff --git a/public/javascripts/note_type.js b/public/javascripts/note_type.jsindex 726080682c..3cd764cdc9 100644--- a/public/javascripts/note_type.js+++ b/public/javascripts/note_type.js@@ -1,6 +1,7 @@"use strict";const noteType = (function() {+ const executeScriptButton = $("#execute-script-button");const noteTypeModel = new NoteTypeModel();function NoteTypeModel() {@@ -74,6 +75,8 @@ const noteType = (function() {+ '/mime/' + encodeURIComponent(self.mime()));await noteEditor.reload();++ self.updateExecuteScriptButtonVisibility();}this.selectText = function() {@@ -96,6 +99,10 @@ const noteType = (function() {save();};++ this.updateExecuteScriptButtonVisibility = function() {+ executeScriptButton.toggle(self.mime() === 'application/javascript');+ }}ko.applyBindings(noteTypeModel, document.getElementById('note-type'));@@ -105,6 +112,10 @@ const noteType = (function() {setNoteType: type => noteTypeModel.type(type),getNoteMime: () => noteTypeModel.mime(),- setNoteMime: mime => noteTypeModel.mime(mime)+ setNoteMime: mime => {+ noteTypeModel.mime(mime);++ noteTypeModel.updateExecuteScriptButtonVisibility();+ }};})();\ No newline at end of filediff --git a/views/index.ejs b/views/index.ejsindex 8c3152b2f6..4fa48dbe65 100644--- a/views/index.ejs+++ b/views/index.ejs@@ -95,6 +95,11 @@<span id="note-id-display" title="Note ID"></span>+ <button class="btn btn-sm"+ style="display: none; margin-right: 10px"+ id="execute-script-button"+ onclick="noteEditor.executeScript()">Execute <kbd>Ctrl+Enter</kbd></button>+<div class="dropdown" id="note-type"><button id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm">Type: <span data-bind="text: typeString()"></span>