promo! csp

This commit is contained in:
Zakhar 2026-08-21 18:23:20 +03:00
parent f7e53901f9
commit baba9b9263
2 changed files with 20 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
const host = 'https://hvatilo.ru'; // const host = 'https://hvatilo.ru';
// const host = 'https://local.hvatilo.ru:8055'; const host = 'https://local.hvatilo.ru:8055';
// Returns a function, that, when invoked, will only be triggered at most once // Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time. Normally, the throttled function will run // during a given window of time. Normally, the throttled function will run
@ -193,7 +193,7 @@ function renderProduct(item, index) {
const li = document.createElement('li'); const li = document.createElement('li');
li.className = 'cart-item'; li.className = 'cart-item';
const amount = item.unit === 'g' ? item.n + ' г' : item.n + ' шт'; const amount = item.unit === 'g' ? item.n + ' г' : item.n + ' шт';
li.innerHTML = ` li.innerHTML = cartPolicy.createHTML(`
<div class="item-image"><img src="${item.image}" alt=""></div> <div class="item-image"><img src="${item.image}" alt=""></div>
<div class="item-details"> <div class="item-details">
<div class="item-name">${item.name}</div> <div class="item-name">${item.name}</div>
@ -208,7 +208,7 @@ function renderProduct(item, index) {
</ul> </ul>
</div> </div>
</div> </div>
`; `);
return li; return li;
} }
@ -219,8 +219,12 @@ let showMoreBtn;
let remainingSpan; let remainingSpan;
let initialData_g; let initialData_g;
const cartPolicy = trustedTypes.createPolicy('cartPolicy', {
createHTML: (string) => string
});
function renderProducts() { function renderProducts() {
cartList.innerHTML = ''; cartList.innerHTML = cartPolicy.createHTML('');
visibleProducts.forEach((item, index) => { visibleProducts.forEach((item, index) => {
cartList.appendChild(renderProduct(item, index)); cartList.appendChild(renderProduct(item, index));
}); });
@ -240,10 +244,10 @@ function updateSummaryCount() {
Math.round(allProducts.reduce((sum, item) => sum + item.total_price, 0) * 100) / 100, Math.round(allProducts.reduce((sum, item) => sum + item.total_price, 0) * 100) / 100,
); );
const x = Math.round(initialData_g.days * initialData_g.excess + initialData_g.days); const x = Math.round(initialData_g.days * initialData_g.excess + initialData_g.days);
document.getElementById('summary-details').innerHTML = `${allProducts.length} ${declension(allProducts.length, ['товар', 'товара', 'товаров'])} &bull; ${totalPrice} ~ с запасами на ${x} ${declension(x, ['день', 'дня', 'дней'])}, точность ${Math.round(initialData_g.precision * 100)/100}%`; document.getElementById('summary-details').innerHTML = cartPolicy.createHTML(`${allProducts.length} ${declension(allProducts.length, ['товар', 'товара', 'товаров'])} &bull; ${totalPrice} ~ с запасами на ${x} ${declension(x, ['день', 'дня', 'дней'])}, точность ${Math.round(initialData_g.precision * 100)/100}%`);
document.getElementById('total-price').innerHTML = `${totalPrice}`; document.getElementById('total-price').innerHTML = cartPolicy.createHTML(`${totalPrice}`);
if(allProducts.length === 0) { if(allProducts.length === 0) {
document.getElementById('summary-details').innerHTML = `0 товаров &bull; ${totalPrice}`; document.getElementById('summary-details').innerHTML = cartPolicy.createHTML(`0 товаров &bull; ${totalPrice}`);
} }
} }
function calculateListHeight() { function calculateListHeight() {
@ -412,20 +416,20 @@ function wholeRender(initialData) {
let editingIndex = null; let editingIndex = null;
function renderPeople() { function renderPeople() {
familyList.innerHTML = ''; familyList.innerHTML = cartPolicy.createHTML('');
people.forEach((person, index) => { people.forEach((person, index) => {
const avatar = '🥦'; const avatar = '🥦';
const div = document.createElement('div'); const div = document.createElement('div');
div.className = 'family-member'; div.className = 'family-member';
div.dataset.index = index; div.dataset.index = index;
div.innerHTML = ` div.innerHTML = cartPolicy.createHTML(`
<div class="avatar">${avatar}</div> <div class="avatar">${avatar}</div>
<div class="info"> <div class="info">
<div class="name">${person.name}</div> <div class="name">${person.name}</div>
<div class="age">${person.age} лет</div> <div class="age">${person.age} лет</div>
</div> </div>
<div class="delete-member" data-index="${index}">×</div> <div class="delete-member" data-index="${index}">×</div>
`; `);
familyList.appendChild(div); familyList.appendChild(div);
}); });
@ -467,7 +471,7 @@ function wholeRender(initialData) {
editingIndex = index; editingIndex = index;
// Очистка тегов внутри попапа // Очистка тегов внутри попапа
document.querySelectorAll('#personModal .tags-wrap').forEach(el => el.innerHTML = ''); document.querySelectorAll('#personModal .tags-wrap').forEach(el => el.innerHTML = cartPolicy.createHTML(''));
if (editingIndex !== null) { if (editingIndex !== null) {
modalTitle.textContent = 'Редактировать человека'; modalTitle.textContent = 'Редактировать человека';
@ -534,7 +538,7 @@ function wholeRender(initialData) {
const tag = document.createElement('div'); const tag = document.createElement('div');
tag.className = `tag ${type === 'avoid' ? 'tag-red' : 'tag-green'}`; tag.className = `tag ${type === 'avoid' ? 'tag-red' : 'tag-green'}`;
tag.innerHTML = `${text} <span class="tag-close">×</span>`; tag.innerHTML = cartPolicy.createHTML(`${text} <span class="tag-close">×</span>`);
tag.querySelector('.tag-close').addEventListener('click', function() { tag.querySelector('.tag-close').addEventListener('click', function() {
tag.remove(); tag.remove();
}); });
@ -549,7 +553,7 @@ function wholeRender(initialData) {
input.addEventListener('input', function() { input.addEventListener('input', function() {
const val = this.value.toLowerCase(); const val = this.value.toLowerCase();
listEl.innerHTML = ''; listEl.innerHTML = cartPolicy.createHTML('');
// Ищем все уже выбранные теги в обеих группах внутри попапа // Ищем все уже выбранные теги в обеих группах внутри попапа
const allSelectedTags = new Set(); const allSelectedTags = new Set();
@ -637,7 +641,7 @@ function wholeRender(initialData) {
const toggleBtn = document.getElementById('expand-categories'); const toggleBtn = document.getElementById('expand-categories');
function renderCategories() { function renderCategories() {
categoriesGrid.innerHTML = ''; categoriesGrid.innerHTML = cartPolicy.createHTML('');
const dataToShow = isCategoriesExpanded ? categories : categories.slice(0, maxVisibleCategories); const dataToShow = isCategoriesExpanded ? categories : categories.slice(0, maxVisibleCategories);
dataToShow.forEach(cat => { dataToShow.forEach(cat => {