mirror of
https://github.com/zadam/trilium.git
synced 2025-01-17 20:48:12 +08:00
added possibility of executing javascript
This commit is contained in:
parent
8adb31757f
commit
27cb6b1c4d
3 changed files with 29 additions and 2 deletions
|
@ -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
|
||||
};
|
||||
})();
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
})();
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue