mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added possibility of executing javascript
This commit is contained in:
parent
8adb31757f
commit
27cb6b1c4d
@ -196,6 +196,14 @@ const noteEditor = (function() {
|
|||||||
return currentNote ? currentNote.detail.type : null;
|
return currentNote ? currentNote.detail.type : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function executeScript() {
|
||||||
|
if (getCurrentNoteType() === 'code') {
|
||||||
|
const script = codeEditor.getValue();
|
||||||
|
|
||||||
|
eval(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
noteTitleEl.on('input', () => {
|
noteTitleEl.on('input', () => {
|
||||||
noteChanged();
|
noteChanged();
|
||||||
@ -234,6 +242,8 @@ const noteEditor = (function() {
|
|||||||
noteDetailEl.attr("tabindex", 2);
|
noteDetailEl.attr("tabindex", 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).bind('keydown', "ctrl+return", executeScript);
|
||||||
|
|
||||||
setInterval(saveNoteIfChanged, 5000);
|
setInterval(saveNoteIfChanged, 5000);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -249,6 +259,7 @@ const noteEditor = (function() {
|
|||||||
getCurrentNoteId,
|
getCurrentNoteId,
|
||||||
newNoteCreated,
|
newNoteCreated,
|
||||||
getEditor,
|
getEditor,
|
||||||
focus
|
focus,
|
||||||
|
executeScript
|
||||||
};
|
};
|
||||||
})();
|
})();
|
@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const noteType = (function() {
|
const noteType = (function() {
|
||||||
|
const executeScriptButton = $("#execute-script-button");
|
||||||
const noteTypeModel = new NoteTypeModel();
|
const noteTypeModel = new NoteTypeModel();
|
||||||
|
|
||||||
function NoteTypeModel() {
|
function NoteTypeModel() {
|
||||||
@ -74,6 +75,8 @@ const noteType = (function() {
|
|||||||
+ '/mime/' + encodeURIComponent(self.mime()));
|
+ '/mime/' + encodeURIComponent(self.mime()));
|
||||||
|
|
||||||
await noteEditor.reload();
|
await noteEditor.reload();
|
||||||
|
|
||||||
|
self.updateExecuteScriptButtonVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.selectText = function() {
|
this.selectText = function() {
|
||||||
@ -96,6 +99,10 @@ const noteType = (function() {
|
|||||||
|
|
||||||
save();
|
save();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.updateExecuteScriptButtonVisibility = function() {
|
||||||
|
executeScriptButton.toggle(self.mime() === 'application/javascript');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ko.applyBindings(noteTypeModel, document.getElementById('note-type'));
|
ko.applyBindings(noteTypeModel, document.getElementById('note-type'));
|
||||||
@ -105,6 +112,10 @@ const noteType = (function() {
|
|||||||
setNoteType: type => noteTypeModel.type(type),
|
setNoteType: type => noteTypeModel.type(type),
|
||||||
|
|
||||||
getNoteMime: () => noteTypeModel.mime(),
|
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>
|
<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">
|
<div class="dropdown" id="note-type">
|
||||||
<button id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="btn btn-sm">
|
<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>
|
Type: <span data-bind="text: typeString()"></span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user