function sleep(sleepdelay) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(sleepdelay);
        }, sleepdelay);
    })
}
function get_tobody_data(tbody_) {
    let arr_trs_datares = [];
    let arr_trs = Array.from(tbody_.querySelectorAll("tr"));
    for (let idx_tr_ = 0; idx_tr_ < arr_trs.length; idx_tr_++) {
        let arr_tds_datares = new Array(13);
        arr_trs_datares.push(arr_tds_datares);
        let tr_ = arr_trs[idx_tr_];
        let arr_tds = Array.from(tr_.querySelectorAll("td"));
        for (let idx_td_ = 0; idx_td_ < arr_tds.length; idx_td_++) {
            let td_ = arr_tds[idx_td_];
            if (idx_td_ == 0) {
                continue
            }
            else if (idx_td_ == 1) {
                let txhash = td_.innerText.trim();
                arr_tds_datares[0] = txhash;
            } else if (idx_td_ == 2) {
                let date = td_.innerText.trim();
                arr_tds_datares[1] = date;
                arr_tds_datares[2] = new Date(date).valueOf();

            } else if (idx_td_ == 3) {
                let action_type = td_.innerText.trim();
                if (action_type.indexOf('SWAP') != -1) {
                    action_type = "SWAP";
                }
                arr_tds_datares[3] = action_type;
            } else if (idx_td_ == 4) {
                let from = td_.innerText.trim();
                arr_tds_datares[4] = from;
            } else if (idx_td_ == 5) {
                let arr_tokenname_amount = td_.innerText.trim().replace(/,/, '').split('\n');
                let arr_tokenlink = Array.from(td_.querySelectorAll("a"));
                let swapin_tokenaddress = arr_tokenlink[0].href.trim().split('/').slice(-1)[0];
                let swapin_tokenname = arr_tokenname_amount[1];
                let swapin_tokenamount = arr_tokenname_amount[0];
                let swapout_tokenaddress = arr_tokenlink[1].href.trim().split('/').slice(-1)[0];
                let swapout_tokenname = arr_tokenname_amount[3];
                let swapout_tokenamount = arr_tokenname_amount[2];

                arr_tds_datares[5] = swapin_tokenaddress;
                arr_tds_datares[6] = swapout_tokenaddress;
                arr_tds_datares[7] = swapin_tokenname;
                arr_tds_datares[8] = swapout_tokenname;
                arr_tds_datares[9] = swapin_tokenamount;
                arr_tds_datares[10] = swapout_tokenamount;

            } else if (idx_td_ == 6) {
                let router_link = td_.querySelectorAll("a")[0].href.trim().split('/').slice(-1)[0];
                arr_tds_datares[11] = router_link;
            }
            else if (idx_td_ == 7) {
                // link is pool's address  every pool has every address , we cant know whichi is raydium pool or  juypool so wu use img to config
                let arr_pool_img = Array.from(td_.querySelectorAll("img"));
                for (let idx_pool_img = 0; idx_pool_img < arr_pool_img.length; idx_pool_img++) {
                    arr_pool_img[idx_pool_img] = arr_pool_img[idx_pool_img].src.trim().split('=').slice(-1)[0];
                }
                if (arr_pool_img.includes("68747470733a2f2f737461746963732e736f6c7363616e2e696f2f65782d696d672f3637356b5058394d48546a53327a7431716672314e5948757a654c5866514d394832347746535574314d70382e706e67")) {
                    // inculude raydium img
                    arr_pool_img = 1;
                } else {
                    arr_pool_img = 0;
                }
                arr_tds_datares[12] = arr_pool_img;

            }
        }

    }

    return arr_trs_datares;

}

async function get_swapactivaties() {


    let table_, thead_, arr_th_, tbody_;


    let data_res = [];
    let arr_title = [['txhash', 'date', 'timestamp', 'action', 'from', 'swapin_tokenaddress',
        'swapout_tokenaddress',
        'swapin_tokenname',
        'swapout_tokenname',
        'swapin_tokenamount',
        'swapout_tokenamount',
        'router',
        'israydium'

    ]]


    try {
        table_ = document.querySelector("table.w-full");
        thead_ = table_.getElementsByTagName('thead')[0];
        arr_th_ = Array.from(thead_.getElementsByTagName('th'));
        tbody_ = table_.getElementsByTagName('tbody')[0];

        let arr_trs_datares = get_tobody_data(tbody_);
        let res_data = [...arr_trs_datares];
        return res_data


    } catch (e) {

        ;
    }
    return



}



let res_data = undefined

res_data = get_swapactivaties();
return res_data;

