a2s.su/pages/js/rev2.js

48 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-08-04 15:48:48 +03:00
export function update_rev2(data) {
2023-08-06 03:20:32 +03:00
// Обновление оставшегося времени
const time_remaining_element = document.getElementById('rev2_time_remaining');
const time_remaining_counter = document.createTextNode(data.time_remaining);
const time_remaining_text = document.createElement('span');
time_remaining_text.classList.add('fw-bold');
time_remaining_text.innerText = 'Времени осталось: ';
[time_remaining_text, time_remaining_counter].forEach((element) => {
time_remaining_element.appendChild(element);
});
time_remaining_element.removeAttribute('class');
// Обновление HP
const content_element = document.getElementById('rev2_emenies');
data.enemies.forEach((emeny) => {
2023-08-06 03:56:12 +03:00
let enemy_data = emeny.split(' ');
2023-08-06 03:20:32 +03:00
// Элемент с именем монстра
const enemy_name = document.createElement('p');
enemy_name.innerText = enemy_data[0];
['my-1', 'fw-bold', 'd-flex', 'justify-content-between'].forEach((style_class) => {
enemy_name.classList.add(style_class);
});
// Элемент с полосой здоровья босса
const progressbar_element = document.createElement('div');
['progress-bar', 'bg-danger'].forEach((style_class) => {
progressbar_element.classList.add(style_class);
});
progressbar_element.style.width = enemy_data[1];
progressbar_element.innerText = enemy_data[1];
const progress_element = document.createElement('div');
progress_element.classList.add('progress');
time_remaining_element.setAttribute('aria-valuemin', 0);
time_remaining_element.setAttribute('aria-valuemax', 100);
time_remaining_element.setAttribute('aria-valuenow', enemy_data[1].replace('%', ''));
progress_element.appendChild(progressbar_element);
content_element.appendChild(enemy_name);
content_element.appendChild(progress_element);
});
2023-08-04 15:48:48 +03:00
}