imacros / Javascript if else exists Text

时间:2017-06-28 12:55:22

标签: javascript if-statement imacros exists

我在Windows 8 x64上的Firefox 53.0.3(64位)上使用iMacros v9.0.3

我正在尝试使用imacros检查文本是否存在 - 如果存在则运行脚本的其余部分,否则转到特定的URL

以下是我的代码块:

var n1 = prompt("Enter Number Of Clicks You Want: ");
    iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=http://addmefast.com/welcome');
    iimPlay('CODE:'+'wait seconds=1');
    iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=http://addmefast.com/free_points/instagram_likes');

    for(var P = 1; P <= n1; P++)
{
    iimDisplay("Current Click is: "+P)
    iimPlay('CODE:'+'SET !TIMEOUT_STEP 0'+'\nTAG POS=1 TYPE=h2 ATTR=class:center_title&&TXT:Instagram<sp>Likes CONTENT=EVENT:MOUSEOVER');
    iimPlay('CODE:'+'wait seconds=2');
    iimPlay('CODE:'+'SET !TIMEOUT_STEP 0'+'\nTAG POS=1 TYPE=div ATTR=class:btn3&&TXT:Like');
    iimPlay('CODE:'+'SET !TIMEOUT_STEP 20'+'\nTAG POS=1 TYPE=a ATTR=class:_1b8in<sp>_soakw<sp>coreSpriteDesktopNavLogoAndWordmark&&href:/&&TXT:Instagram CONTENT=EVENT:MOUSEOVER');
    iimPlay('CODE:'+'wait seconds=6');
    iimPlay('CODE:'+'SET !TIMEOUT_STEP 0'+'\nTAG POS=1 TYPE=span ATTR=class:_soakw<sp>coreSpriteHeartOpen&&TXT:Like');
    iimPlay('CODE:'+'wait seconds=9');
    iimPlay('CODE:'+'\nEVENT TYPE=KEYPRESS SELECTOR=* CHAR="1" MODIFIERS="ctrl"');
    iimPlay('CODE:'+'TAB CLOSEALLOTHERS');
    iimPlay('CODE:'+'wait seconds=5');
    if (P % 5 == 0 && P!=0) {
iimPlay('CODE:'+'REFRESH');
}
}

我的代码工作正常,但不幸的是,有时Tab 2关闭而不是Tab 1,所以脚本最终失败并需要手动工作再次重播,所以我想要If Else格式的脚本

我对javascript /编程知之甚少。我搜索了Google并尝试了一些建议,但没有一个有效。

以下是我正在尝试的代码:

 var n1 = prompt("Enter Number Of Clicks You Want: ");
    var answer=iimGetLastExtract();
        iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=http://addmefast.com/welcome');
        iimPlay('CODE:'+'wait seconds=1');
        iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=http://addmefast.com/free_points/instagram_likes');

        for(var P = 1; P <= n1; P++)
    {
        iimDisplay("Current Click is: "+P)
        iimPlay('CODE:'+'SET !TIMEOUT_STEP 0'+'\nTAG POS=1 TYPE=h2 ATTR=class:center_title&&TXT:Instagram<sp>Likes EXTRACT=TXT');

if(answer=="Instagram Likes"){
        iimPlay('CODE:'+'wait seconds=2');
        iimPlay('CODE:'+'SET !TIMEOUT_STEP 0'+'\nTAG POS=1 TYPE=div ATTR=class:btn3&&TXT:Like');
        iimPlay('CODE:'+'SET !TIMEOUT_STEP 20'+'\nTAG POS=1 TYPE=a ATTR=class:_1b8in<sp>_soakw<sp>coreSpriteDesktopNavLogoAndWordmark&&href:/&&TXT:Instagram CONTENT=EVENT:MOUSEOVER');
        iimPlay('CODE:'+'wait seconds=6');
        iimPlay('CODE:'+'SET !TIMEOUT_STEP 0'+'\nTAG POS=1 TYPE=span ATTR=class:_soakw<sp>coreSpriteHeartOpen&&TXT:Like');
        iimPlay('CODE:'+'wait seconds=9');
        iimPlay('CODE:'+'\nEVENT TYPE=KEYPRESS SELECTOR=* CHAR="1" MODIFIERS="ctrl"');
        iimPlay('CODE:'+'TAB CLOSEALLOTHERS');
        iimPlay('CODE:'+'wait seconds=5');
        if (P % 5 == 0 && P!=0) {
    iimPlay('CODE:'+'REFRESH');
    }
} else {iimPlay('CODE:'+'SET !TIMEOUT_PAGE 100'+'\nURL GOTO=http://addmefast.com/free_points/instagram_likes');}
    }

所以,这段代码中有什么问题,我该如何解决呢?

0 个答案:

没有答案