如何兑现承诺?

时间:2019-12-03 07:18:26

标签: javascript google-chrome

async function exc () 
{
     //var forward = $("body>div:nth-child(3)>div>div>main>div>div:nth-child(3)>div>div:nth-child(2)>div>div>div:nth-child(2)>div:nth-child(2)>div>div:nth-child(2)>div>div:nth-child(2)>div>ul>li:nth-last-child(1)")


    while($("#root>div>div>main>div>div:nth-child(3)>div>div:nth-child(2)>div>div>div:nth-child(2)>div:nth-child(2)>div>div:nth-child(2)>div>div:nth-child(2)>div>ul>li:nth-last-child(1)").css("cursor")=="pointer") {
    await l()
    await page()


    }
}
function page()
{
    return new Promise((resolve, reject)=> {
    setTimeout(function () {
    fo=$("#root>div>div>main>div>div:nth-child(3)>div>div:nth-child(2)>div>div>div:nth-child(2)>div:nth-child(2)>div>div:nth-child(2)>div>div:nth-child(2)>div>ul>li:nth-last-child(1)")
    fo.click()
    console.log('翻页')
    },100)
    resolve();
    })
}
function l()
{    return new Promise((resolve, reject)=> {
    $('#root>div>div>main>div>div:nth-child(3)>div>div:nth-child(2)>div>div>div:nth-child(2)>div:nth-child(2)>div>div:nth-child(2)>div>div:nth-child(1)>div:nth-child(1)>table>tbody>tr>td:nth-child(7)>div>div:nth-child(2)>a>span')
    .each(
         function()
         {
         var t=$(this)
     p = p.then(_ => new Promise(resolve =>
        setTimeout(function () {

            t.click()
            resolve();
        },  200)
    ))
    .then(
    _ => new Promise(resolve =>
        setTimeout(function () {
            console.log('wocao')
            $('body>div:nth-last-child(1)>div>div>div:nth-child(3)>div:nth-child(2)>button>span').click()
            resolve();
        },  200)
    )



    )

         }
    )

    resolve();


    })


}
function send()

{
    return new Promise((resolve, reject)=> {
    var num=$('body>div>div>div>main>div>div:nth-child(3)>div>div:nth-child(2)>div>div>div:nth-child(2)>div:nth-child(2)>div>div:nth-child(2)>div>div:nth-child(2)>div>ul>li:nth-child(1)')
    num=parseInt(num.text().slice(3,-2))
    setTimeout(function(){

        chrome.runtime.sendMessage(

            true
        , function (response) {
            data=response

            console.log(data)
            for(let i in data.head)
            {

            f(data.body[i],data.head[i])    

            }







        });     

        },1000)
    resolve();
    })



}
function page()
{
    return new Promise((resolve, reject)=> {
    setTimeout(function () {
    fo=$("#root>div>div>main>div>div:nth-child(3)>div>div:nth-child(2)>div>div>div:nth-child(2)>div:nth-child(2)>div>div:nth-child(2)>div>div:nth-child(2)>div>ul>li:nth-last-child(1)")
    fo.click()
    console.log('翻页')
    },100)
    resolve();
    })
}
exc();

我希望功能l工作,然后功能页工作,此循环继续进行几次,然后功能发送工作。我该怎么做。 我已经以不同的方式尝试了很多次,我对l函数的递归承诺是:第一个settimeout循环几次,然后第二个settimeout循环,或者页面函数首先工作。

0 个答案:

没有答案