Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/scripts/openai-google-image-ajax.js
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
"use strict";
2
+
function googleimagefunct() {
3
+
jQuery('#aigoogleimagesubmitbut').attr('disabled', true);
4
+
var instructionx = jQuery('#aiomatic_google_image_instruction');
5
+
var instruction = instructionx.val();
6
+
if(instruction == '')
7
+
{
8
+
jQuery('#aigoogleimagesubmitbut').attr('disabled', false);
9
+
jQuery('#openai-google-image-response').html('<div class="text-primary highlight-text-fail" role="status">Please add a prompt in the input field.</div>');
10
+
console.log('Instruction cannot be empty.');
11
+
return;
12
+
}
13
+
var image_placeholder = aiomatic_google_image_ajax_object.image_placeholder;
14
+
jQuery("#aiomatic_google_image_response").attr("src", image_placeholder).fadeIn();
15
+
var image_size = aiomatic_google_image_ajax_object.image_size;
16
+
var user_token_cap_per_day = aiomatic_google_image_ajax_object.user_token_cap_per_day;
17
+
var user_id = aiomatic_google_image_ajax_object.user_id;
18
+
// Show the loading animation
19
+
jQuery('#openai-google-image-response').html('<div class="automaticx-dual-ring"></div>');
20
+
if(image_size == 'default' || image_size == '')
21
+
{
22
+
image_size = jQuery( "#model-google-size-selector option:selected" ).text();
23
+
}
24
+
jQuery.ajax({
25
+
type: 'POST',
26
+
url: aiomatic_google_image_ajax_object.ajax_url,
27
+
data: {
28
+
action: 'aiomatic_google_image_ajax_submit',
29
+
instruction: instruction,
30
+
image_size: image_size,
31
+
user_token_cap_per_day: user_token_cap_per_day,
32
+
nonce: aiomatic_google_image_ajax_object.nonce,
33
+
user_id: user_id
34
+
},
35
+
success: function(response)
36
+
{
37
+
if(typeof response === 'string' || response instanceof String)
38
+
{
39
+
try {
40
+
var responset = JSON.parse(response);
41
+
response = responset;
42
+
} catch (error) {
43
+
console.error("An error occurred while parsing the JSON: " + error + ' Json: ' + response);
44
+
}
45
+
}
46
+
if(response.status == 'success')
47
+
{
48
+
if(response.data == '')
49
+
{
50
+
jQuery('#openai-google-image-response').html('<div class="text-primary" role="status">No image was returned. Please try using a different text input.</div>');
51
+
jQuery("#aiomatic_google_image_response").attr("src", '').fadeIn();
52
+
}
53
+
else
54
+
{
55
+
jQuery("#aiomatic_google_image_response").attr("src", "data:image/png;base64," + response.data).fadeIn();
56
+
jQuery('#openai-google-image-response').html('');
57
+
}
58
+
}
59
+
else
60
+
{
61
+
if(typeof response.msg !== 'undefined')
62
+
{
63
+
jQuery('#openai-google-image-response').html('<div class="text-primary highlight-text-fail" role="status">' + response.msg + '</div>');
64
+
}
65
+
else
66
+
{
67
+
console.log('Error: ' + response);
68
+
jQuery('#openai-google-image-response').html('<div class="text-primary highlight-text-fail" role="status">Processing failed, please try again</div>');
69
+
}
70
+
jQuery("#aiomatic_google_image_response").attr("src", '').fadeIn();
71
+
}
72
+
jQuery('#aigoogleimagesubmitbut').attr('disabled', false);
73
+
},
74
+
error: function(error) {
75
+
console.log('Error: ' + error.responseText);
76
+
jQuery("#aiomatic_google_image_response").attr("src", '').fadeIn();
77
+
// Clear the response container
78
+
jQuery('#openai-google-image-response').html('<div class="text-primary highlight-text-fail" role="status">Failed to image content, try again later.</div>');
79
+
// Enable the submit button
80
+
jQuery('#aigoogleimagesubmitbut').attr('disabled', false);
81
+
},
82
+
});
83
+
}
84
+
85
+
var recognition;
86
+
var recognizing = false;
87
+
jQuery(document).ready(function() {
88
+
89
+
if(!jQuery('#aiomatic_google_image_templates').length)
90
+
{
91
+
// Check if the browser supports the Web Speech API
92
+
if ('webkitSpeechRecognition' in window) {
93
+
recognition = new webkitSpeechRecognition();
94
+
recognition.continuous = true;
95
+
recognition.interimResults = true;
96
+
97
+
// Start the speech recognition when the button is clicked
98
+
jQuery('#openai-google-image-speech-button').on('click', function() {
99
+
if (recognizing) {
100
+
recognition.stop();
101
+
recognizing = false;
102
+
} else {
103
+
recognition.start();
104
+
recognizing = true;
105
+
}
106
+
});
107
+
108
+
// Handle the speech recognition results
109
+
recognition.onresult = function(event) {
110
+
for (var i = event.resultIndex; i < event.results.length; ++i) {
111
+
if (event.results[i].isFinal) {
112
+
jQuery('#aiomatic_google_image_instruction').val(jQuery('#aiomatic_google_image_instruction').val() + " " + event.results[i][0].transcript);
113
+
}
114
+
}
115
+
116
+
};
117
+
}
118
+
}
119
+
else
120
+
{
121
+
jQuery('#aiomatic_google_image_templates').on('change', function()
122
+
{
123
+
jQuery('#aiomatic_google_image_instruction').val(jQuery( "#aiomatic_google_image_templates" ).val());
124
+
});
125
+
}
126
+
});