/*
 * 2026 Ecom Experts
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 *
 * @author    Ecom Experts <ecomyseo@gmail.com>
 * @copyright 2026 Ecom Experts
 * @license   AFL-3.0
 */
(function () {
    'use strict';
    var script = document.currentScript;
    if (!script || document.cookie.indexOf('ecs_js=') !== -1 || !window.fetch) {
        return;
    }
    var url = script.getAttribute('data-token-url');
    if (!url) {
        return;
    }
    fetch(url, {cache: 'no-store', credentials: 'same-origin'})
        .then(function (response) { return response.text(); })
        .then(function (token) {
            if (/^v1\.[0-9]{10}\.[0-9a-f]{64}$/.test(token)) {
                document.cookie = 'ecs_js=' + token + '; path=/; max-age=172800; SameSite=Lax'
                    + (location.protocol === 'https:' ? '; Secure' : '');
            }
        }).catch(function () {});
}());
