Upload 2 files
Browse files
gemini.js
CHANGED
@@ -224,8 +224,11 @@ function createSummarizedText() {
|
|
224 |
if (rootUl) {
|
225 |
processUl(rootUl);
|
226 |
}
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
229 |
}
|
230 |
|
231 |
function createPayload() {
|
@@ -292,9 +295,37 @@ function debugPrompt() {
|
|
292 |
});
|
293 |
}
|
294 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
295 |
function fetchStream(ENDPOINT, payload) {
|
296 |
const novelContent2 = document.getElementById('novelContent2');
|
297 |
-
|
298 |
controller = new AbortController();
|
299 |
const signal = controller.signal;
|
300 |
|
@@ -382,11 +413,11 @@ function fetchStream(ENDPOINT, payload) {
|
|
382 |
}).catch(error => {
|
383 |
if (error.name === 'AbortError') {
|
384 |
console.log('フェッチがユーザーによって中止されました');
|
|
|
385 |
} else {
|
386 |
console.error('ストリーム読み取りエラー:', error);
|
|
|
387 |
}
|
388 |
-
document.getElementById('stopButton').classList.add('d-none');
|
389 |
-
requestButton.disabled = false;
|
390 |
});
|
391 |
}
|
392 |
|
@@ -395,29 +426,31 @@ function fetchStream(ENDPOINT, payload) {
|
|
395 |
.catch(error => {
|
396 |
if (error.name === 'AbortError') {
|
397 |
console.log('フェッチがユーザーよって中止されました');
|
|
|
398 |
} else {
|
399 |
console.error('フェッチエラー:', error);
|
|
|
400 |
}
|
401 |
-
requestButton.disabled = false;
|
402 |
});
|
403 |
}
|
404 |
|
405 |
-
function fetchNonStream(ENDPOINT, payload) {
|
406 |
const novelContent2 = document.getElementById('novelContent2');
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
}
|
418 |
-
|
419 |
-
|
420 |
-
|
|
|
421 |
}
|
422 |
|
423 |
function createOpenAIPayload() {
|
@@ -464,7 +497,7 @@ function createOpenAIPayload() {
|
|
464 |
|
465 |
function fetchOpenAIStream(ENDPOINT, payload) {
|
466 |
const novelContent2 = document.getElementById('novelContent2');
|
467 |
-
|
468 |
controller = new AbortController();
|
469 |
const signal = controller.signal;
|
470 |
|
@@ -520,11 +553,11 @@ function fetchOpenAIStream(ENDPOINT, payload) {
|
|
520 |
}).catch(error => {
|
521 |
if (error.name === 'AbortError') {
|
522 |
console.log('フェッチがユーザーによって中止されました');
|
|
|
523 |
} else {
|
524 |
console.error('ストリーム読み取りエラー:', error);
|
|
|
525 |
}
|
526 |
-
document.getElementById('stopButton').classList.add('d-none');
|
527 |
-
requestButton.disabled = false;
|
528 |
});
|
529 |
}
|
530 |
|
@@ -533,33 +566,35 @@ function fetchOpenAIStream(ENDPOINT, payload) {
|
|
533 |
.catch(error => {
|
534 |
if (error.name === 'AbortError') {
|
535 |
console.log('フェッチがユーザーよって中止されました');
|
|
|
536 |
} else {
|
537 |
console.error('フェッチエラー:', error);
|
|
|
538 |
}
|
539 |
-
requestButton.disabled = false;
|
540 |
});
|
541 |
}
|
542 |
|
543 |
-
function fetchOpenAINonStream(ENDPOINT, payload) {
|
544 |
const novelContent2 = document.getElementById('novelContent2');
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
.then(data => {
|
552 |
-
if (data && data.choices && data.choices[0].message && data.choices[0].message.content) {
|
553 |
-
novelContent2.value += data.choices[0].message.content;
|
554 |
-
novelContent2.scrollTop = novelContent2.scrollHeight;
|
555 |
-
}
|
556 |
-
})
|
557 |
-
.catch(error => {
|
558 |
-
console.error('エラー:', error);
|
559 |
-
})
|
560 |
-
.finally(() => {
|
561 |
-
document.getElementById('requestButton').disabled = false;
|
562 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
}
|
564 |
|
565 |
async function tokenCount() {
|
@@ -693,8 +728,7 @@ function stopGeneration() {
|
|
693 |
controller.abort();
|
694 |
controller = null;
|
695 |
}
|
696 |
-
|
697 |
-
document.getElementById('requestButton').disabled = false;
|
698 |
}
|
699 |
|
700 |
// 新しい関数を追加
|
@@ -907,7 +941,7 @@ function generateIndexMenu() {
|
|
907 |
}
|
908 |
|
909 |
updateAllAccordionHeaderCounts();
|
910 |
-
updateTokenCount(
|
911 |
}
|
912 |
|
913 |
function toggleSubMenu(li) {
|
@@ -1050,7 +1084,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
1050 |
document.getElementById(id).addEventListener('input', () => {
|
1051 |
saveToUserStorage(false);
|
1052 |
generateIndexMenu();
|
1053 |
-
updateTokenCount(); // 60秒に1回の制限が適用される
|
1054 |
});
|
1055 |
});
|
1056 |
|
@@ -1059,7 +1092,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
1059 |
document.getElementById(id).addEventListener('input', () => {
|
1060 |
saveToUserStorage(true);
|
1061 |
generateIndexMenu();
|
1062 |
-
updateTokenCount(); // 60秒に1回の制限が適用される
|
1063 |
});
|
1064 |
});
|
1065 |
|
@@ -1067,7 +1099,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
1067 |
document.getElementById(id).addEventListener('change', () => {
|
1068 |
saveToUserStorage(true);
|
1069 |
generateIndexMenu();
|
1070 |
-
updateTokenCount(); // 60秒に1回の制限が適用される
|
1071 |
});
|
1072 |
});
|
1073 |
|
|
|
224 |
if (rootUl) {
|
225 |
processUl(rootUl);
|
226 |
}
|
227 |
+
if (summarizedText) {
|
228 |
+
return summarizedText.trim();
|
229 |
+
} else {
|
230 |
+
return document.getElementById('novelContent1').value;
|
231 |
+
}
|
232 |
}
|
233 |
|
234 |
function createPayload() {
|
|
|
295 |
});
|
296 |
}
|
297 |
|
298 |
+
// 新しい関数を追加
|
299 |
+
function updateRequestButtonState(state, flashClass = null) {
|
300 |
+
const requestButton = document.getElementById('requestButton');
|
301 |
+
const stopButton = document.getElementById('stopButton');
|
302 |
+
|
303 |
+
switch (state) {
|
304 |
+
case 'generating':
|
305 |
+
requestButton.disabled = true;
|
306 |
+
stopButton.classList.remove('d-none');
|
307 |
+
break;
|
308 |
+
case 'idle':
|
309 |
+
requestButton.disabled = false;
|
310 |
+
stopButton.classList.add('d-none');
|
311 |
+
break;
|
312 |
+
case 'error':
|
313 |
+
requestButton.disabled = false;
|
314 |
+
stopButton.classList.add('d-none');
|
315 |
+
break;
|
316 |
+
}
|
317 |
+
|
318 |
+
if (flashClass) {
|
319 |
+
requestButton.classList.add(flashClass);
|
320 |
+
setTimeout(() => {
|
321 |
+
requestButton.classList.remove(flashClass);
|
322 |
+
}, 2000);
|
323 |
+
}
|
324 |
+
}
|
325 |
+
|
326 |
function fetchStream(ENDPOINT, payload) {
|
327 |
const novelContent2 = document.getElementById('novelContent2');
|
328 |
+
updateRequestButtonState('generating');
|
329 |
controller = new AbortController();
|
330 |
const signal = controller.signal;
|
331 |
|
|
|
413 |
}).catch(error => {
|
414 |
if (error.name === 'AbortError') {
|
415 |
console.log('フェッチがユーザーによって中止されました');
|
416 |
+
updateRequestButtonState('idle');
|
417 |
} else {
|
418 |
console.error('ストリーム読み取りエラー:', error);
|
419 |
+
updateRequestButtonState('error', 'red-flash-bg');
|
420 |
}
|
|
|
|
|
421 |
});
|
422 |
}
|
423 |
|
|
|
426 |
.catch(error => {
|
427 |
if (error.name === 'AbortError') {
|
428 |
console.log('フェッチがユーザーよって中止されました');
|
429 |
+
updateRequestButtonState('idle');
|
430 |
} else {
|
431 |
console.error('フェッチエラー:', error);
|
432 |
+
updateRequestButtonState('error', 'red-flash-bg');
|
433 |
}
|
|
|
434 |
});
|
435 |
}
|
436 |
|
437 |
+
async function fetchNonStream(ENDPOINT, payload) {
|
438 |
const novelContent2 = document.getElementById('novelContent2');
|
439 |
+
updateRequestButtonState('generating');
|
440 |
+
try {
|
441 |
+
const response = await fetch(ENDPOINT, payload);
|
442 |
+
const data = await response.json();
|
443 |
+
if (data && data.candidates && data.candidates[0].content && data.candidates[0].content.parts && data.candidates[0].content.parts[0].text) {
|
444 |
+
novelContent2.value += data.candidates[0].content.parts[0].text;
|
445 |
+
novelContent2.scrollTop = novelContent2.scrollHeight;
|
446 |
+
updateRequestButtonState('idle', 'green-flash-bg');
|
447 |
+
} else {
|
448 |
+
throw new Error('予期しないレスポンス形式');
|
449 |
+
}
|
450 |
+
} catch (error) {
|
451 |
+
console.error('エラー:', error);
|
452 |
+
updateRequestButtonState('error', 'red-flash-bg');
|
453 |
+
}
|
454 |
}
|
455 |
|
456 |
function createOpenAIPayload() {
|
|
|
497 |
|
498 |
function fetchOpenAIStream(ENDPOINT, payload) {
|
499 |
const novelContent2 = document.getElementById('novelContent2');
|
500 |
+
updateRequestButtonState('generating');
|
501 |
controller = new AbortController();
|
502 |
const signal = controller.signal;
|
503 |
|
|
|
553 |
}).catch(error => {
|
554 |
if (error.name === 'AbortError') {
|
555 |
console.log('フェッチがユーザーによって中止されました');
|
556 |
+
updateRequestButtonState('idle');
|
557 |
} else {
|
558 |
console.error('ストリーム読み取りエラー:', error);
|
559 |
+
updateRequestButtonState('error', 'red-flash-bg');
|
560 |
}
|
|
|
|
|
561 |
});
|
562 |
}
|
563 |
|
|
|
566 |
.catch(error => {
|
567 |
if (error.name === 'AbortError') {
|
568 |
console.log('フェッチがユーザーよって中止されました');
|
569 |
+
updateRequestButtonState('idle');
|
570 |
} else {
|
571 |
console.error('フェッチエラー:', error);
|
572 |
+
updateRequestButtonState('error', 'red-flash-bg');
|
573 |
}
|
|
|
574 |
});
|
575 |
}
|
576 |
|
577 |
+
async function fetchOpenAINonStream(ENDPOINT, payload) {
|
578 |
const novelContent2 = document.getElementById('novelContent2');
|
579 |
+
updateRequestButtonState('generating');
|
580 |
+
try {
|
581 |
+
const response = await fetch(ENDPOINT, {
|
582 |
+
...payload,
|
583 |
+
mode: 'cors',
|
584 |
+
credentials: 'same-origin'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
585 |
});
|
586 |
+
const data = await response.json();
|
587 |
+
if (data && data.choices && data.choices[0].message && data.choices[0].message.content) {
|
588 |
+
novelContent2.value += data.choices[0].message.content;
|
589 |
+
novelContent2.scrollTop = novelContent2.scrollHeight;
|
590 |
+
updateRequestButtonState('idle', 'green-flash-bg');
|
591 |
+
} else {
|
592 |
+
throw new Error('予期しないレスポンス形式');
|
593 |
+
}
|
594 |
+
} catch (error) {
|
595 |
+
console.error('エラー:', error);
|
596 |
+
updateRequestButtonState('error', 'red-flash-bg');
|
597 |
+
}
|
598 |
}
|
599 |
|
600 |
async function tokenCount() {
|
|
|
728 |
controller.abort();
|
729 |
controller = null;
|
730 |
}
|
731 |
+
updateRequestButtonState('idle');
|
|
|
732 |
}
|
733 |
|
734 |
// 新しい関数を追加
|
|
|
941 |
}
|
942 |
|
943 |
updateAllAccordionHeaderCounts();
|
944 |
+
updateTokenCount(false);
|
945 |
}
|
946 |
|
947 |
function toggleSubMenu(li) {
|
|
|
1084 |
document.getElementById(id).addEventListener('input', () => {
|
1085 |
saveToUserStorage(false);
|
1086 |
generateIndexMenu();
|
|
|
1087 |
});
|
1088 |
});
|
1089 |
|
|
|
1092 |
document.getElementById(id).addEventListener('input', () => {
|
1093 |
saveToUserStorage(true);
|
1094 |
generateIndexMenu();
|
|
|
1095 |
});
|
1096 |
});
|
1097 |
|
|
|
1099 |
document.getElementById(id).addEventListener('change', () => {
|
1100 |
saveToUserStorage(true);
|
1101 |
generateIndexMenu();
|
|
|
1102 |
});
|
1103 |
});
|
1104 |
|