Your IP : 216.73.217.78


Current Path : /home/seto/888mirror.pm/
Upload File :
Current File : /home/seto/888mirror.pm/widget.js

(function () {
    var script = document.currentScript || (function () {
        var s = document.getElementsByTagName('script');
        return s[s.length - 1];
    })();

    var base    = script.src.replace(/widget\.(js|php).*$/, '');
    var country = script.getAttribute('data-country') || '';
    var lang    = script.getAttribute('data-lang')    || '';
    var layout  = script.getAttribute('data-layout') || '';
    var target  = script.getAttribute('data-target') || '#casino-widget';

    var params = 'output=html&_v=5';
    if (layout)  params += '&layout=' + encodeURIComponent(layout);
    if (country) params += '&country=' + encodeURIComponent(country);
    if (lang)    params += '&lang='    + encodeURIComponent(lang);
    params += '&ref=' + encodeURIComponent(window.location.hostname);

    var url = base + 'widget-api.php?' + params;

    // Находим или создаём контейнер
    var container = document.querySelector(target);
    if (!container) {
        container = document.createElement('div');
        container.id = target.replace(/^#/, '');
        script.parentNode.insertBefore(container, script.nextSibling);
    }

    // Лоадер-плейсхолдер
    container.innerHTML = '<div style="padding:40px;text-align:center;opacity:.3;font-family:sans-serif;font-size:13px">Loading...</div>';

    fetch(url)
        .then(function (r) {
            if (!r.ok) throw new Error('HTTP ' + r.status);
            return r.text();
        })
        .then(function (html) {
            // Парсим HTML, отдельно выносим <style> и <script>
            var tmp = document.createElement('div');
            tmp.innerHTML = html;

            // Inject <style> в <head> (всегда обновляем)
            tmp.querySelectorAll('style').forEach(function (s) {
                var existing = document.getElementById('cw-styles');
                if (existing) {
                    existing.textContent = s.textContent;
                } else {
                    var st = document.createElement('style');
                    st.id = 'cw-styles';
                    st.textContent = s.textContent;
                    document.head.appendChild(st);
                }
                s.remove();
            });

            // Inject Google Fonts если нужно
            if (!document.querySelector('link[href*="fonts.googleapis.com"][href*="Inter"]')) {
                var lp = document.createElement('link');
                lp.rel = 'preconnect'; lp.href = 'https://fonts.googleapis.com';
                document.head.appendChild(lp);
                var lf = document.createElement('link');
                lf.rel = 'stylesheet';
                lf.href = 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap';
                document.head.appendChild(lf);
            }

            container.innerHTML = tmp.innerHTML;

            // Выполняем inline <script>
            container.querySelectorAll('script').forEach(function (s) {
                var ns = document.createElement('script');
                ns.textContent = s.textContent;
                s.parentNode.replaceChild(ns, s);
            });
        })
        .catch(function (err) {
            container.innerHTML = '<div style="padding:20px;color:#c00;font-family:sans-serif;font-size:12px">Widget load error: ' + err.message + '</div>';
        });
})();