From f3d475a0b8d2816ece6b964314e4ab543ac97e3c Mon Sep 17 00:00:00 2001
From: Ivor Barhansky <me@lopar.space>
Date: Fri, 10 May 2024 15:59:04 +0300
Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?=
 =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D1=8F=D0=B2=D0=B0=D1=81=D0=BA=D1=80?=
 =?UTF-8?q?=D0=B8=D0=BF=D1=82=D0=BE=D0=B2.=20=D0=A3=D0=B1=D0=BE=D1=80?=
 =?UTF-8?q?=D0=BA=D0=B0=20jQuery.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 _incl_data/class/Battle.php |  5 ++-
 js/btl_mini.js              | 80 ++++++++++++++++++++++++-------------
 2 files changed, 55 insertions(+), 30 deletions(-)

diff --git a/_incl_data/class/Battle.php b/_incl_data/class/Battle.php
index fc683ae5..c721b487 100644
--- a/_incl_data/class/Battle.php
+++ b/_incl_data/class/Battle.php
@@ -1525,13 +1525,14 @@ JS;
             $jstext = json_encode($log['text']);
             $jsvars = json_encode($log['vars']);
 
-            $js = "add_log({$log['id']},$jstext,{$log['id_hod']},$jsvars)" . $js;
+            $js = "add_log({$log['id']},$jstext,{$log['id_hod']},$jsvars);" . $js;
         }
 
         Db::sql('update stats set alog = ? where id = ?', [$u->info['alog'], $u->info['id']]);
         $js .= "id_log=$pll;";
 
-        return htmlspecialchars($js, ENT_QUOTES);
+        //return htmlspecialchars($js, ENT_QUOTES);
+        return $js;
     }
 
 
diff --git a/js/btl_mini.js b/js/btl_mini.js
index 5f1b5179..d5ad3e8e 100644
--- a/js/btl_mini.js
+++ b/js/btl_mini.js
@@ -442,56 +442,76 @@ var id_log_ar = [];
 var id_log;
 var type_log = top.type_log;
 
+// Эта функция получает элемент по идентификатору из фрейма 'main'.
+const getElementByIdInMainFrame = (id) => {
+    const frame = top.frames['main'];
+    if (!frame) {
+        console.error("Фрейм 'main' не найден!");
+        return null;
+    }
+
+    return frame.document.getElementById(id);
+};
+
 function add_log(id, text, hod_id, vars) {
+    const logsdiv = getElementByIdInMainFrame('battle_logg');
+    let hodlogdiv = getElementByIdInMainFrame(`battle_log_${hod_id}`);
+    const hodlogdiv7 = getElementByIdInMainFrame(`battle_log_${hod_id - 7}`);
+    const hodlogdiv25 = getElementByIdInMainFrame(`battle_log_${hod_id - 25}`);
+    const logid = getElementByIdInMainFrame(`log_id_${id}`);
+
     if (top.des === 1) type_log = 0
     else type_log = 1;
 
     if (type_log === 1) {
         chsee = 'chsee2';
 
-        //if(id_log_ar[id]!=id)
-        //{
         text = looklogrep(text, vars);
         id_log_ar[id] = id;
         id_log = id;
-        // if (top.frames['main'].document.getElementById("battle_log_" + hod_id + "") == undefined && hod_id != 1) {
-        if (!top.frames['main'].document.getElementById(`battle_log_${hod_id}`) && hod_id != 1) {
+
+        if (!hodlogdiv && hod_id !== 1) {
             if (fstlh === 0) fstlh = hod_id
             lsthd[lsti] = hod_id;
             lsti++;
-            $(top.frames['main'].document.getElementById('battle_logg')).prepend(`<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_'${hod_id}" class="battle_hod_style"></div>`);
-        } else if (!top.frames['main'].document.getElementById(`battle_log_${hod_id}`)) {
-            top.frames['main'].document.getElementById('battle_logg').innerHTML = top.frames['main'].document.getElementById('battle_logg').innerHTML + `<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_${hod_id}"></div>`;
+            logsdiv.insertAdjacentHTML('afterbegin', `<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_'${hod_id}" class="battle_hod_style"></div>`);
+            hodlogdiv = getElementByIdInMainFrame(`battle_log_${hod_id}`);
+        } else if (!hodlogdiv) {
+            logsdiv.insertAdjacentHTML('beforeend', `<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_${hod_id}"></div>`);
+            hodlogdiv = getElementByIdInMainFrame(`battle_log_${hod_id}`);
         }
 
-        if (!top.frames['main'].document.getElementById(`log_id_${id}`)) {
-            $(top.frames['main'].document.getElementById(`battle_log_${hod_id}`)).prepend(`<span id="log_id_${id}" class="foryou0">${text}</span><br>`);
+        if (!logid) {
+            hodlogdiv.insertAdjacentHTML('afterbegin', `<span id="log_id_${id}" class="foryou0">${text}</span><br>`);
         }
-        //}
-        if (top.frames['main'].document.getElementById(`battle_log_${hod_id - 25}`)) {
+
+        if (hodlogdiv25) {
             top.rmve(`#battle_log_${hod_id - 25}`);
         }
         return
     }
+
     chsee = 'chsee2';
 
     text = looklogrep(text, vars);
     id_log_ar[id] = id;
     id_log = id;
-    if (!top.document.getElementById(`battle_log_${hod_id}`) && hod_id != 1) {
+    if (!hodlogdiv && hod_id !== 1) {
         if (fstlh === 0) {
             fstlh = hod_id;
         }
         lsthd[lsti] = hod_id;
         lsti++;
-        $(top.document.getElementById('battle_logg')).prepend(`<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_${hod_id}" tabindex="${0 - hod_id}" class="battle_hod_style"></div>`);
-    } else if (!top.document.getElementById("battle_log_" + hod_id + "")) {
-        top.document.getElementById('battle_logg').innerHTML = top.document.getElementById('battle_logg').innerHTML + `<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_${hod_id}"></div>`;
+        logsdiv.insertAdjacentHTML('afterbegin', `<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_${hod_id}" tabindex="${0 - hod_id}" class="battle_hod_style"></div>`);
+        hodlogdiv = getElementByIdInMainFrame(`battle_log_${hod_id}`);
+    } else if (!hodlogdiv) {
+        logsdiv.insertAdjacentHTML('beforeend', `<div style="padding-top:2px;padding-bottom:2px;" id="battle_log_${hod_id}"></div>`);
+        hodlogdiv = getElementByIdInMainFrame(`battle_log_${hod_id}`);
     }
-    if (!top.document.getElementById(`log_id_${id}`)) {
-        $(top.document.getElementById(`battle_log_${hod_id}`)).prepend(`<span id="log_id_${id}" class="foryou0">${text}</span><br>`);
+    if (!logid) {
+        hodlogdiv.insertAdjacentHTML('afterbegin', `<span id="log_id_${id}" class="foryou0">${text}</span><br>`);
     }
-    if (top.document.getElementById(`battle_log_${hod_id - 7}`)) {
+    if (hodlogdiv7) {
         top.rmve(`#battle_log_${hod_id - 7}`);
     }
 }
@@ -499,22 +519,26 @@ function add_log(id, text, hod_id, vars) {
 //-- Мой лог--------------------------------
 //-------------------------------------------
 function add_mlog(id, text, hod_id, vars) {
+    const logsdiv = getElementByIdInMainFrame('battle_mlogg');
+    let hodlogdiv = getElementByIdInMainFrame(`battle_mlog_${hod_id}`);
+    const hodlogdiv14 = getElementByIdInMainFrame(`battle_mlog_${hod_id - 14}`);
+    const logid = getElementByIdInMainFrame(`mlog_id_${id}`);
+
     chsee = 'chsee7';
     text = looklogrep(text, vars);
     id_log_ar[id] = id;
     id_log = id;
-    if (!top.document.getElementById(`battle_mlog_${hod_id}`) && hod_id != 1) {
-        $(top.document.getElementById('battle_mlogg')).prepend(`<div style="padding-top:2px;padding-bottom:2px;" id="battle_mlog_${hod_id}" tabindex="${0 - hod_id}" class="battle_hod_style"></div>`);
-
-    } else if (!top.document.getElementById(`battle_mlog_${hod_id}`)) {
-        top.document.getElementById('battle_mlogg').innerHTML = top.document.getElementById('battle_mlogg').innerHTML + `<div style="padding-top:2px;padding-bottom:2px;" id="battle_mlog_${hod_id}"></div>`;
+    if (!hodlogdiv && hod_id !== 1) {
+        logsdiv.insertAdjacentHTML('afterbegin', `<div style="padding-top:2px;padding-bottom:2px;" id="battle_mlog_${hod_id}" tabindex="${0 - hod_id}" class="battle_hod_style"></div>`);
+        hodlogdiv = getElementByIdInMainFrame(`battle_mlog_${hod_id}`);
+    } else if (!hodlogdiv) {
+        logsdiv.insertAdjacentHTML('beforeend', `<div style="padding-top:2px;padding-bottom:2px;" id="battle_mlog_${hod_id}"></div>`);
+        hodlogdiv = getElementByIdInMainFrame(`battle_mlog_${hod_id}`);
     }
-
-    if (!top.document.getElementById(`mlog_id_${id}`)) {
-        $(top.document.getElementById(`battle_mlog_${hod_id}`)).prepend(`<span id="mlog_id_${id}" class="foryou0">${text}</span><br>`);
-
+    if (!logid) {
+        hodlogdiv.insertAdjacentHTML('afterbegin', `<span id="mlog_id_${id}" class="foryou0">${text}</span><br>`);
     }
-    if (top.document.getElementById(`battle_mlog_${hod_id - 14}`)) {
+    if (hodlogdiv14) {
         top.rmve(`#battle_mlog_${hod_id - 14}`);
     }
 }