Рефакторинг яваскриптов. Уборка jQuery.

This commit is contained in:
Ivor Barhansky 2024-05-10 15:59:04 +03:00
parent 023d9856ea
commit f3d475a0b8
2 changed files with 55 additions and 30 deletions

View File

@ -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;
}

View File

@ -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}`);
}
}