From e3306a94b45cf567bf0944b4955e6d1822b8cc9f Mon Sep 17 00:00:00 2001 From: wowlikon Date: Wed, 25 Feb 2026 14:07:31 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B5=D0=BA=D1=83=D0=BD=D0=B4=D0=BE?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=B0=20=D1=80=D0=B0=D0=B7=D0=BC=D1=8B=D1=88?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library_service/static/page/create_book.js | 90 ++++++++++++++++----- library_service/static/page/edit_book.js | 91 +++++++++++++++++----- 2 files changed, 142 insertions(+), 39 deletions(-) diff --git a/library_service/static/page/create_book.js b/library_service/static/page/create_book.js index 6b86a02..8c7c88a 100644 --- a/library_service/static/page/create_book.js +++ b/library_service/static/page/create_book.js @@ -398,6 +398,8 @@ $(document).ready(() => { let curInfoEl = null; let lastType = null; let idleTimer = null; + let thinkTimer = null; + let thinkStartTime = null; const twQueues = new Map(); @@ -519,31 +521,65 @@ $(document).ready(() => { } } + function formatThinkTime(sec) { + if (sec < 60) { + return sec.toFixed(1) + "с"; + } + const m = Math.floor(sec / 60); + const s = Math.floor(sec % 60); + return m + "м " + String(s).padStart(2, "0") + "с"; + } + function addThinkBlock() { const id = "ai-t-" + Date.now(); $logEntries.append(` -
-
- - - - - Думает - - - -
-
-

-
+
+
+ + + + + + Думает + + + + 0.0с + + + + +
- `); +
+

+
+
+ `); + $(`[data-toggle="${id}-b"]`).on("click", function () { $(`#${id}-b`).toggleClass("hidden"); $(this).find(".ai-t-chev").toggleClass("rotate-180"); }); + curThinkEl = $(`#${id}`); scrollLog(); + + thinkStartTime = performance.now(); + clearInterval(thinkTimer); + thinkTimer = setInterval(() => { + if (!curThinkEl) return; + const elapsed = (performance.now() - thinkStartTime) / 1000; + curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed)); + }, 100); } function appendThink(text) { @@ -557,14 +593,26 @@ $(document).ready(() => { function endThink() { if (!curThinkEl) return; + + clearInterval(thinkTimer); + thinkTimer = null; + + if (thinkStartTime) { + const elapsed = (performance.now() - thinkStartTime) / 1000; + curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed)); + thinkStartTime = null; + } + const p = curThinkEl.find(".ai-t-txt")[0]; twFlush(p); curThinkEl.find(".ai-t-txt").removeClass("typing-cursor"); curThinkEl.find(".ai-t-spin").removeClass("animate-spin").html(` - - - - `); + + + + `); const id = curThinkEl.attr("id"); if (id) { @@ -645,6 +693,10 @@ $(document).ready(() => { } function hideWidget() { + clearInterval(thinkTimer); + thinkTimer = null; + thinkStartTime = null; + $aiWidget.addClass("hidden"); $logWrap.addClass("hidden"); $logEntries.empty(); diff --git a/library_service/static/page/edit_book.js b/library_service/static/page/edit_book.js index 021f3d8..9027d2d 100644 --- a/library_service/static/page/edit_book.js +++ b/library_service/static/page/edit_book.js @@ -503,6 +503,8 @@ $(document).ready(() => { let curInfoEl = null; let lastType = null; let idleTimer = null; + let thinkTimer = null; + let thinkStartTime = null; const twQueues = new Map(); @@ -611,7 +613,6 @@ $(document).ready(() => { title: $titleInput.val() || null, description: $descInput.val() || null, page_count: $pagesInput.val() ? parseInt($pagesInput.val(), 10) : null, - status: $statusSelect.val() || "active", }; } @@ -625,31 +626,65 @@ $(document).ready(() => { } } + function formatThinkTime(sec) { + if (sec < 60) { + return sec.toFixed(1) + "с"; + } + const m = Math.floor(sec / 60); + const s = Math.floor(sec % 60); + return m + "м " + String(s).padStart(2, "0") + "с"; + } + function addThinkBlock() { const id = "ai-t-" + Date.now(); $logEntries.append(` -
-
- - - - - Думает - - - -
-
-

-
+
+
+ + + + + + Думает + + + + 0.0с + + + + +
- `); +
+

+
+
+ `); + $(`[data-toggle="${id}-b"]`).on("click", function () { $(`#${id}-b`).toggleClass("hidden"); $(this).find(".ai-t-chev").toggleClass("rotate-180"); }); + curThinkEl = $(`#${id}`); scrollLog(); + + thinkStartTime = performance.now(); + clearInterval(thinkTimer); + thinkTimer = setInterval(() => { + if (!curThinkEl) return; + const elapsed = (performance.now() - thinkStartTime) / 1000; + curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed)); + }, 100); } function appendThink(text) { @@ -663,14 +698,26 @@ $(document).ready(() => { function endThink() { if (!curThinkEl) return; + + clearInterval(thinkTimer); + thinkTimer = null; + + if (thinkStartTime) { + const elapsed = (performance.now() - thinkStartTime) / 1000; + curThinkEl.find(".ai-t-timer").text(formatThinkTime(elapsed)); + thinkStartTime = null; + } + const p = curThinkEl.find(".ai-t-txt")[0]; twFlush(p); curThinkEl.find(".ai-t-txt").removeClass("typing-cursor"); curThinkEl.find(".ai-t-spin").removeClass("animate-spin").html(` - - - - `); + + + + `); const id = curThinkEl.attr("id"); if (id) { @@ -751,6 +798,10 @@ $(document).ready(() => { } function hideWidget() { + clearInterval(thinkTimer); + thinkTimer = null; + thinkStartTime = null; + $aiWidget.addClass("hidden"); $logWrap.addClass("hidden"); $logEntries.empty();