<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,viewport-fit=cover,user-scalable=0">
    <title>Download the game to help your friends withdraw money</title>
    <link href="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/css/Page1.2aff4632.css" rel="stylesheet">
    <link href="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/css/chunk-common.a49a41eb.css" rel="stylesheet">
    <!-- Google tag (gtag.js) dynamically loaded with Thymeleaf -->
    <script src="https://www.googletagmanager.com/gtag/js?id=G-WT46NVYKEE" async></script>

    <script>
        window.dataLayer = window.dataLayer || [];

        function gtag() {
            dataLayer.push(arguments);
        }

        gtag('js', new Date());

        gtag('config', "G-WT46NVYKEE");
    </script>

    <!-- Facebook Pixel dynamically loaded with Thymeleaf -->
    <script>
        /*<![CDATA[*/
        !function (f, b, e, v, n, t, s) {
            if (f.fbq) return;
            n = f.fbq = function () {
                n.callMethod ?
                    n.callMethod.apply(n, arguments) : n.queue.push(arguments)
            };
            if (!f._fbq) f._fbq = n;
            n.push = n;
            n.loaded = !0;
            n.version = '2.0';
            n.queue = [];
            t = b.createElement(e);
            t.async = !0;
            t.src = v;
            s = b.getElementsByTagName(e)[0];
            s.parentNode.insertBefore(t, s)
        }(window, document, 'script',
            'https://connect.facebook.net/en_US/fbevents.js');
        fbq('init', "1920446981742117");
        fbq('track', 'PageView');
        /*]]>*/
    </script>

    <noscript><img height="1" width="1" style="display:none"
                   src="https://www.facebook.com/tr?id=1920446981742117&amp;ev=PageView&amp;noscript=1"/></noscript>
    <!-- End Facebook Pixel Code -->
    <link rel="stylesheet" href="https://assets.googleplaystore.in/assets/css/smedia.css">
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>


<body>
<div id="downloadImage" onclick="download('download_button')">
    <div data-v-18cfbbe4="" class="cps-container">
        <div data-v-18cfbbe4="" class="cps-content">
            <div data-v-18cfbbe4="" class="bottom-wrap"><img data-v-18cfbbe4="" src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/img/page1-icon.e7bdad99.png"
                                                             class="down-img-icon"><img data-v-18cfbbe4="" src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/img/download1.a9434a65.webp"
                                                                                        class="down-img-bottom"></div>
        </div>
    </div>
</div>
<script src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/js/chunk-vendors.c68ca08a.js"></script>
<script src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/js/chunk-common.8125e70a.js"></script>
<script src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/js/cps.30e8cc95.js"></script>
<script src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/js/PageAce.356f986a.js"></script>
<script src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/js/Page.322ec436.js"></script>

<script src="https://assets.googleplaystore.in/asc/RTYSZAF/output_id/js/download.js"></script>
<script>
    const scrCode = 'RTYSZAF'
</script>


<input type="hidden" id="channel" value="slm_1200527" />
<input type="hidden" id="appName" value="Teen Patti Master" />
<input type="hidden" id="pkgType" value="1" />
<input type="hidden" id="downloadDomain" value="https://d1o61kxrx8e2s3.cloudfront.net" />
<input type="hidden" id="adjustTrackerToken" value="1dw1rpml" />
<input type="hidden" id="onlinePkgUrl" value="" />
<input type="hidden" id="ext" value="" />
<input type="hidden" id="pixelId" value="1920446981742117" />
<input type="hidden" id="eventId" value="fc0bbcb6-2ce6-44f8-8daf-7002a0f47f4c" />

</body>
<script>
    var fbp = getCookie('_fbp') || getQueryString('_fbp') || getQueryString("fbp") || getCookie('fbp');
    var fbc = getCookie('_fbc') || getQueryString('_fbc') || getQueryString("fbc") || getCookie('fbc');
    console.log('fbp', fbp)
    console.log('fbc', fbc)

    let pkgType = document.getElementById('pkgType').value;
    let downloadDomain = document.getElementById('downloadDomain').value;
    let adjustTracker = document.getElementById('adjustTrackerToken').value;
    let onlinePkgUrl = document.getElementById('onlinePkgUrl').value;
    let ext = document.getElementById('ext').value;
    let pxid = document.getElementById('pixelId').value;
    let appName = document.getElementById('appName').value;
    let channel = document.getElementById('channel').value;
    let eventId = document.getElementById('eventId').value;

    let extStr = JSON.stringify(ext)
    let encodeExtStr = encodeURIComponent(extStr)
    let offlineUrl;
    let url = '';

    let reportFlag = 0

    // 开始计时
    const startTime = Date.now();

    function checkCookie() {
        const startTime = Date.now(); // 记录开始时间
        let timeCost = 0; // 保存时间花费

        const intervalId = setInterval(() => {
            const fbcValue = getCookie('_fbc');
            const currentTime = Date.now();
            if (fbcValue) {
                // 停止监听
                clearInterval(intervalId);

                // 计算时间花费
                timeCost = currentTime - startTime;
                reportLog(timeCost);
                // 在控制台输出时间花费
                console.log('Time cost:', timeCost, 'milliseconds');
            } else if (currentTime - startTime > 10000) {
                // 超过10秒仍未找到_fbc，打印日志
                clearInterval(intervalId);
                timeCost = currentTime - startTime;
                reportLog(timeCost);
                console.log('Time cost exceeds 10 seconds. _fbc not found.');
            } else {
                console.log('Check Cookie: _fbc not found yet.');
            }
        }, 100); // 间隔0.1秒检查一次
        checkFbc(intervalId,startTime,timeCost)
    }

    function checkFbc(intervalId,starTime,timeCost) {
        console.log('checkFbc')
        const fbcValue = getCookie('_fbc');
        const currentTime = Date.now();
        if (fbcValue) {
            // 停止监听
            clearInterval(intervalId);

            // 计算时间花费
            timeCost = currentTime - startTime;
            reportLog(timeCost);
            // 在控制台输出时间花费
            console.log('Time cost:', timeCost, 'milliseconds');
        } else if (currentTime - startTime > 10000) {
            // 超过10秒仍未找到_fbc，打印日志
            clearInterval(intervalId);
            timeCost = currentTime - startTime;
            reportLog(timeCost);
            console.log('Time cost exceeds 10 seconds. _fbc not found.');
        } else {
            console.log('Check Cookie: _fbc not found yet.');
        }
    }

    // 调用函数开始监听
    checkCookie();

    //读取url参数
    const urlParams = new Proxy({}, {
        get: (target, name) => name in target ? target[name] : ''
    });

    window.addEventListener("DOMContentLoaded", () => {
        const currentURL = window.location.href;
        const parsedURL = new URL(currentURL);
        const params = parsedURL.searchParams;
        for (const [param, value] of params) {
            urlParams[param] = value;
        }
    });
    console.log(urlParams)

    var gclid = getGclid();
    console.log('getGclid:', gclid)
    function getGclid() {
        let ups = readUrlParams();
        if(ups.gclid) {
            return ups.gclid
        }
        let adjust_referrer = ups.adjust_referrer
        if(adjust_referrer) {
            adjust_referrer = decodeURIComponent(adjust_referrer)
            let ar = adjust_referrer.split("=")
            console.log('ar:', ar)
            if(ar && ar.length > 1) {
                return ar[1]
            }
        }
        return ''
    }
    var wbraid = getQueryString("wbraid") || getCookie('wbraid');
    var gbraid = getQueryString("gbraid") || getCookie('gbraid');

    function getQueryString(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return "";
    }

    function getCookie(cname) {
        let name = cname + "=";
        let ca = document.cookie.split(';');
        for (let i = 0; i < ca.length; i++) {
            let c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function createEventId() {
        return 'xxxxxxxyx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = Math.random() * 16 | 0,
                v = c === 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }

    //线下包地址
    if(pkgType === '1') {
        offlineUrl = downloadDomain + '/cg/gaoct/fg/' + appName + '.apk?' + 'channel=' + channel + '&pxid=' + pxid + '&fbp=' + fbp + '&fbc=' + fbc + '&gclid=' + gclid + '&wbraid=' + wbraid + '&gbraid=' + gbraid + '&eventId=' + eventId + '&ext=' + encodeExtStr;

        console.log('offlineUrl:', offlineUrl)
        url = offlineUrl;
    } else if(pkgType === '2') {
        //线上包地址
        url = buildOnlinePkgReferrer()
    }

    webClick()
    function webClick() {

        let uri = window.location.href;
        uri = uri.replace(/^https?:\/\//, '');
        uri = encodeURIComponent(uri)
        // 获取当前页面的所有 Cookie
        const cookies = document.cookie;
        let logrpUrl = '';

        const urlP = readUrlParams()

        if (isGoogleAdLink()) {
            const campaignName = urlP.campaign
            const adset = urlP.adgroup
            const creative = urlP.creative
            const gbraid = urlP.gbraid
            const wbraid = urlP.wbraid
            logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/click?uri=' + uri + '&eventId=' + eventId + '&channel=' + channel +
                '&gbraid=' + gbraid + '&wbraid=' + wbraid + '&campaignName=' + campaignName + "&campaignId=" + campaignName + '&gclid=' + gclid + '&adsetName=' + adset + '&adsetId=' + adset + '&creative='
                + creative + '&adjustTrackerToken=' + adjustTracker
        } else if (isFacebookAdLink()) {
            const campaignName = urlP.p1
            const campaignId = urlP.p2
            const adsetName = urlP.p3
            const adsetId = urlP.p4
            const adName = urlP.p5
            const adId = urlP.p6
            const fbclid = urlP.fbclid
            const fbpid = urlP.fbpid
            logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/click?uri=' + uri + '&eventId=' + eventId + '&channel=' + channel +
                '&campaignName=' + campaignName + '&adsetName=' + adsetName + '&adjustTrackerToken=' + adjustTracker +
                '&campaignId=' + campaignId + '&adsetId=' + adsetId + '&adName=' + adName + '&adId=' + adId + '&fbclid=' + fbclid + '&fbpid=' + fbpid;
        } else {
            //自然量
            logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/click?uri=' + uri + '&eventId=' + eventId + '&channel=' + channel +
                '&adjustTrackerToken=' + adjustTracker
        }

        // 发送GET请求
        fetch(logrpUrl,{mode:'no-cors'})
            .then(response => {
            })
            .then(data => {
            })
            .catch(error => {
                console.log('web click error', error)
            });
    }

    function onBtnClick(redirect) {

        if (isGoogleAdLink()) {
            const campaign = urlParams.campaign
            const adgroup = urlParams.adgroup
            const creative = urlParams.creative
            const gbraid = urlParams.gbraid
            const wbraid = urlParams.wbraid
            const url = 'https://app.adjust.com/' + adjustTracker + '?engagement_type=fallback_click&campaign=' + campaign + '&external_click_id=' + gclid +
                '&adgroup=' + adgroup + '&creative=' + creative + '&gbraid=' + gbraid + '&wbraid=' + wbraid + '&redirect=' + redirect
            console.log(url)
            window.location.href = url;
        } else if (isFacebookAdLink()) {
            const campaignName = urlParams.p1
            const campaignId = urlParams.p2
            const adsetName = urlParams.p3
            const adsetId = urlParams.p4
            const adName = urlParams.p5
            const adId = urlParams.p6
            const fbclid = urlParams.fbclid
            const fbpid = urlParams.fbpid
            const url = 'https://app.adjust.com/' + adjustTracker + '?engagement_type=fallback_click&campaign=' + campaignName + '%20%28' + campaignId
                + '%29&adgroup=' + adsetName + '%20%28' + adsetId + '%29&creative=' + adName + '%20%28' + adId + '%29&fbclid='
                + fbclid + '&fbpid=' + fbpid + '&redirect=' + redirect
            window.location.href = url;
        } else {
            window.location.href = 'https://app.adjust.com/' + adjustTracker + '?engagement_type=fallback_click&redirect=' + redirect;
        }
    }

    function isGoogleAdLink() {
        return gclid
    }

    function isFacebookAdLink() {
        return window.location.href.includes('fbclid');
    }

    function sendGtagEvent(action) {
        console.log('sendGtagEvent', action)
        // 其他参数被设定为固定值
        const category = 'button';
        const label = 'myButton';
        const value = 1;

        gtag('event', action, {
            'event_category': category,
            'event_label': label,
            'value': value
        });
    }

    //必须将download赋值给window
    function download(eventName) {
        sendGtagEvent(eventName)
        reportLog(Date.now() - startTime);
        var encodedUrl = encodeURIComponent(url);
        onBtnClick(encodedUrl);
    }

    window.download = download;

    function readUrlParams() {
        //读取url参数
        const urlParams = new Proxy({}, {
            get: (target, name) => name in target ? target[name] : ''
        });

        const currentURL = window.location.href;
        const parsedURL = new URL(currentURL);
        const params = parsedURL.searchParams;

        for (const [param, value] of params) {
            urlParams[param] = value;
            console.log('urlParams: ', urlParams[param])
        }
        return urlParams;
    }

    function reportLog(timeCost) {
        if(reportFlag > 0) {
            return;
        }
        reportFlag = 1
        let uri = window.location.href;
        uri = uri.replace(/^https?:\/\//, '');
        console.log('uri:', uri)
        // 获取当前页面的所有 Cookie
        const cookies = document.cookie;
        // 将 Cookie 添加到 URL 参数中
        let cookieA = `&cookie=${encodeURIComponent(cookies)}`;
        let logrpUrl = '';

        const urlP = readUrlParams()

        var uriWithoutParams = window.location.origin + window.location.pathname;
        const p0 = urlP.p0
        const p1 = urlP.p1
        const p2 = urlP.p2
        const p3 = urlP.p3
        const p4 = urlP.p4
        const p5 = urlP.p5
        const p6 = urlP.p6
        const fbclid = urlP.fbclid

        logrpUrl = 'https://tracker2.bx1.pw/webAdsTracker/report?uri=' + uriWithoutParams + '&p0=' + p0 + '&p1=' + p1 + '&p2=' + p2 + '&p3=' + p3 + '&p4=' + p4
            + '&p5=' + p5 + '&p6=' + p6 + '&fbclid=' + fbclid + '&eventId=' + eventId + cookieA + '&timecost=' + timeCost + '&channel=' + channel;
        // 发送GET请求
        fetch(logrpUrl,{mode:'no-cors'})
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! Status: ${response.status}`);
                }
                return response.json();
            })
            .then(data => {
                console.log('reportLog', logrpUrl)
            })
            .catch(error => {
                console.log('reportLog:', logrpUrl)
            });
    }

    function hasQuestionMark(uri) {
        const regex = /\?/;
        return regex.test(uri);
    }

    function buildOnlinePkgReferrer() {
        let up = readUrlParams()
        if (isFacebookAdLink()) {
            onlinePkgUrl = onlinePkgUrl + '&referrer=fbclid%3D' + up.fbclid + '%26eventId%3D' + eventId
        } else if (isGoogleAdLink()) {
            onlinePkgUrl = onlinePkgUrl + '&referrer=fbclid%3D' + gclid + '%26eventId%3D' + eventId
        } else {
            onlinePkgUrl = onlinePkgUrl + '&referrer=eventId%3D' + eventId
        }
        return onlinePkgUrl
    }


    const commonUrl = 'https://media.teamraid.xyz'
    // const commonUrl = 'http://127.0.0.1'
    let media = null
    function getRequest(url, params) {
        var result = axios({
            method: "get",
            url: url,
            params: params,
            baseURL: commonUrl,
        })
            .then(function (resp) {
                media = resp.data.data

                showMedia()
            })
            .catch(function (error) {
                return "exception=" + error;
            });

    }

    function getMedia() {
        mediaUrl = '/webMedia/getMedia'
        let params = {
            channel: channel,
            category: null
        }
        getRequest(mediaUrl, params)
    }
    function showMedia() {

        if(!media) {
            return
        }

        const sideDiv = document.createElement('div');
        sideDiv.className = 'side';

        // Create the ul element
        const list = document.createElement('ul');
        list.id = 'social-media-list';

        // Append the ul to the main container div
        sideDiv.appendChild(list);

        // Append the main container div to the body
        document.body.appendChild(sideDiv);

        // Add the list items if the URLs are defined
        if (media.telegramUrl) {
            list.appendChild(createListItem(media.telegramUrl, 'https://assets.googleplaystore.in/media/tel.png', '', false, 'click_telegram'));
        }
        if (media.whatsappUrl) {
            list.appendChild(createListItem(media.whatsappUrl, 'https://assets.googleplaystore.in/media/wapp.png', '', false, 'click_whatsapp'));
        }
        if (media.youtubeUrl) {
            list.appendChild(createListItem(media.youtubeUrl, 'https://assets.googleplaystore.in/media/ytb.png', '', false, 'click_youtube'));
        }
        if (media.instagramUrl) {
            list.appendChild(createListItem(media.instagramUrl, 'https://assets.googleplaystore.in/media/ins.png', '', true, 'click_instagram'));
        }
        if (media.facebookUrl) {
            list.appendChild(createListItem(media.facebookUrl, 'https://assets.googleplaystore.in/media/fb.png', '15px', false, 'click_facebook'));
        }
        if (media.twitterUrl) {
            list.appendChild(createListItem(media.twitterUrl, 'https://assets.googleplaystore.in/media/tw.png', '', false, 'click_twitter'));
        }

    }
    // Define a function to create a list item
    function createListItem(url, imgSrc, borderRadius = '', borderNone = false, gtagName) {
        const li = document.createElement('li');
        const a = document.createElement('a');
        const div = document.createElement('div');
        const img = document.createElement('img');
        // a.href = url;
        a.target = "_blank";
        div.className = "side2box";
        if (borderRadius) {
            div.style.borderTopLeftRadius = borderRadius;
        }
        if (borderNone) {
            li.style.border = 'none';
        }
        img.src = imgSrc;

        div.appendChild(img);
        a.appendChild(div);
        li.appendChild(a);

        // Add click event listener to the <a> element
        a.addEventListener('click', function(event) {
            sendGtagEvent(gtagName)
            window.open(url, '_blank'); // Open the URL in a new tab
        });

        return li;
    }

    getMedia()
</script>
</html>