forked from node-red-jp/node-red-contrib-plugin-chatgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatgpt.html
24 lines (24 loc) · 998 Bytes
/
chatgpt.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<script type='text/javascript'>
RED.events.on('editor:open', function () {
setTimeout(function () {
var askButton = $('<button type="button" class="red-ui-button">Ask ChatGPT</button>')
askButton.prependTo('.red-ui-tray-footer-left');
askButton.on('click', function () {
askButton.prop('value', 'Asking...');
askButton.prop('disabled', true);
$.ajax({
url: "/chatgpt",
type: "POST",
contentType: "application/json",
data: {}
}).done(function (data) {
var editors = monaco.editor.getEditors();
editors[editors.length-1].setValue(data.body);
}).always(function () {
askButton.prop('value', 'Ask ChatGPT');
askButton.prop('disabled', false);
});
});
}, 300);
});
</script>