2ch commited on
Commit
210789e
·
verified ·
1 Parent(s): 17c2068

Update Grok Imagine Pro UI v2.5-2.5.user.js

Browse files
Grok Imagine Pro UI v2.5-2.5.user.js CHANGED
@@ -12,6 +12,7 @@
12
  'use strict';
13
 
14
  let historyImages = []; // Сгенерированные картинки
 
15
  let promptHistory = JSON.parse(localStorage.getItem('grok_prompt_history') || '[]');
16
  let currentIndex = -1;
17
 
@@ -90,9 +91,23 @@
90
  <textarea id="prompt-input" placeholder="What should I imagine?"></textarea>
91
  <div class="row">
92
  <button class="btn-secondary" id="toggle-sidebar">📜 History</button>
 
 
 
93
  <select id="ratio-select">
94
- <option value="auto">Auto Ratio</option><option value="1:1">1:1</option><option value="16:9">16:9</option>
95
- <option value="9:16">9:16</option><option value="4:3">4:3</option><option value="3:2">3:2</option>
 
 
 
 
 
 
 
 
 
 
 
96
  </select>
97
  <input type="number" id="count-input" value="1" min="1" max="20" style="width: 45px;">
98
  <select id="mode-select">
@@ -137,6 +152,46 @@
137
  }
138
  });
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  renderHistory();
141
  }
142
 
@@ -188,15 +243,27 @@
188
 
189
  // --- REQUEST LOGIC ---
190
  async function sendRequest(prompt, ratio, n = 1) {
191
- const response = await fetch('https://console.x.ai/v1/images/generations', {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  method: 'POST',
193
  headers: { 'Content-Type': 'application/json' },
194
- body: JSON.stringify({
195
- model: 'grok-imagine-image',
196
- prompt, n, aspect_ratio: ratio,
197
- resolution: '2k', response_format: 'b64_json'
198
- })
199
  });
 
200
  if (!response.ok) {
201
  const err = await response.json();
202
  throw new Error(err.error || `HTTP ${response.status}`);
 
12
  'use strict';
13
 
14
  let historyImages = []; // Сгенерированные картинки
15
+ let selectedImages = []; // Хранилище Base64 выбранных файлов
16
  let promptHistory = JSON.parse(localStorage.getItem('grok_prompt_history') || '[]');
17
  let currentIndex = -1;
18
 
 
91
  <textarea id="prompt-input" placeholder="What should I imagine?"></textarea>
92
  <div class="row">
93
  <button class="btn-secondary" id="toggle-sidebar">📜 History</button>
94
+ <input type="file" id="file-input" multiple accept="image/*" style="display:none">
95
+ <button class="btn-secondary" id="upload-btn">📎 Edit (0/10)</button>
96
+ <button class="btn-danger" id="clear-files" style="display:none; padding: 2px 8px;">✕</button>
97
  <select id="ratio-select">
98
+ <option value="auto">Auto Ratio</option>
99
+ <option value="1:1">1:1</option>
100
+ <option value="16:9">16:9</option>
101
+ <option value="9:16">9:16</option>
102
+ <option value="19.5:9">19.5:9</option>
103
+ <option value="9:19.5">9:19.5</option>
104
+ <option value="20:9">20:9</option>
105
+ <option value="9:20">9:20</option>
106
+ <option value="4:3">4:3</option>
107
+ <option value="3:2">3:2</option>
108
+ <option value="2:3">2:3</option>
109
+ <option value="2:1">2:1</option>
110
+ <option value="1:2">1:2</option>
111
  </select>
112
  <input type="number" id="count-input" value="1" min="1" max="20" style="width: 45px;">
113
  <select id="mode-select">
 
152
  }
153
  });
154
 
155
+ const fileInput = document.getElementById('file-input');
156
+ const uploadBtn = document.getElementById('upload-btn');
157
+ const clearFilesBtn = document.getElementById('clear-files');
158
+ const ratioSelect = document.getElementById('ratio-select');
159
+
160
+ uploadBtn.onclick = () => fileInput.click();
161
+
162
+ fileInput.onchange = async (e) => {
163
+ const files = Array.from(e.target.files).slice(0, 10);
164
+ selectedImages = [];
165
+
166
+ for (const file of files) {
167
+ const base64 = await new Promise(resolve => {
168
+ const reader = new FileReader();
169
+ reader.onload = () => resolve(reader.result);
170
+ reader.readAsDataURL(file);
171
+ });
172
+ selectedImages.push({ url: base64 });
173
+ }
174
+
175
+ if (selectedImages.length > 0) {
176
+ uploadBtn.innerText = `📎 Edit (${selectedImages.length}/10)`;
177
+ uploadBtn.style.color = "#0f0";
178
+ clearFilesBtn.style.display = "inline-block";
179
+ ratioSelect.disabled = true;
180
+ ratioSelect.value = "auto";
181
+ document.getElementById('gen-btn').innerText = "EDIT IMAGES";
182
+ }
183
+ };
184
+
185
+ clearFilesBtn.onclick = () => {
186
+ selectedImages = [];
187
+ fileInput.value = "";
188
+ uploadBtn.innerText = "📎 Edit (0/10)";
189
+ uploadBtn.style.color = "#fff";
190
+ clearFilesBtn.style.display = "none";
191
+ ratioSelect.disabled = false;
192
+ document.getElementById('gen-btn').innerText = "GENERATE";
193
+ };
194
+
195
  renderHistory();
196
  }
197
 
 
243
 
244
  // --- REQUEST LOGIC ---
245
  async function sendRequest(prompt, ratio, n = 1) {
246
+ const isEdit = selectedImages.length > 0;
247
+ const url = isEdit ? 'https://console.x.ai/v1/images/edits' : 'https://console.x.ai/v1/images/generations';
248
+
249
+ const body = {
250
+ model: 'grok-imagine-image',
251
+ prompt, n,
252
+ aspect_ratio: isEdit ? 'auto' : ratio,
253
+ resolution: '2k',
254
+ response_format: 'b64_json'
255
+ };
256
+
257
+ if (isEdit) {
258
+ body.images = selectedImages; // Добавляем массив картинок
259
+ }
260
+
261
+ const response = await fetch(url, {
262
  method: 'POST',
263
  headers: { 'Content-Type': 'application/json' },
264
+ body: JSON.stringify(body)
 
 
 
 
265
  });
266
+
267
  if (!response.ok) {
268
  const err = await response.json();
269
  throw new Error(err.error || `HTTP ${response.status}`);