16011602// Виджет ПЛ только для стора: buyer-dashboard / LKP store. На lk-dashboard скрипта лояльности нет.1603if (!window.tildaMembers || !window.tildaMembers.is_init_store) return;16041605if (typeof tmst__loyalty__createUserbarWidget === 'function') {1606tma__userbar__renderLoyaltyWidget(data && data.loyalty);1607} else if (typeof t_onFuncLoad === 'function') {1608t_onFuncLoad('tmst__loyalty__createUserbarWidget', () => {1609tma__userbar__renderLoyaltyWidget(data && data.loyalty);1610});1611}
}/** * @param {object | null | undefined} loyaltyRaw - сырой loyalty из getbuyerinfo */function tma__userbar__renderLoyaltyWidget(loyaltyRaw) { const popup = document.querySelector('.tlk-userbar__popup'); if (!popup || !popup.classList.contains('tlk-userbar__popup-show')) return; if ( typeof tmst__loyalty__fromBuyerInfo !== 'function' || typeof tmst__loyalty__createUserbarWidget !== 'function' ) { return; } const existing = popup.querySelector('.tlk-userbar__loyalty'); const view = tmst__loyalty__fromBuyerInfo(loyaltyRaw); const el = tmst__loyalty__createUserbarWidget(view); if (!el) { if (existing) existing.remove(); return; } if (existing) existing.remove(); const login = popup.querySelector('.tlk-userbar__popup-login'); if (!login) return; login.after(el);}/** * Добавляет или обновляет блок style c переданным ID * * @param {string} id * @param {string} className - класс для которого необходимо определить стиль * @param {object} styles - описание стиля */function tma__createOrUpdateCSSClass(id, className, styles) { var newStyle = document.createElement('style'); newStyle.id = id; var cssText = `.${className} {`; for (const property in styles) { cssText += `${property}: ${styles[property]};`; } cssText += '}'; newStyle.innerHTML = cssText; var oldStyle = document.getElementById(id); if (!oldStyle) { document.head.appendChild(newStyle); } else { document.head.replaceChild(newStyle, oldStyle); }}/** * Дальше запросы за данными store, копипаста из tilda-members-store-other.js *//** * Выполняет XHR-запрос к серверу * * @param {string} endpoint - Конечная точка API * @param {FetchParams} [params] - Параметры для построения URL и выполнения запроса * @returns {Promise<any>} Промис с данными ответа */function tmst__fetchData(endpoint, params = {}) { const { queryParams = {}, body = {}, method = 'POST' } = params; return new Promise((resolve, reject) => { const token = tmst__getToken(); // Без токена не должен проходить запрос if (!token) { reject('wrong_user_token'); } const serverName = tmst__getServerName(); const rootZone = tmst__getRootZone(); let queryString = tmst__getQueryString(queryParams); queryString = queryString ? `?${queryString}` : ''; const url = `https://${serverName}/api/orders/${endpoint}/${queryString}`; const xhr = new XMLHttpRequest(); const startTime = Date.now(); body.token = token; xhr.onload = () => { if (xhr.readyState === xhr.DONE) { // Проверяем статус и время выполнения запроса