Eval


SUBMITTED BY: rilp44

DATE: Dec. 1, 2015, 3:04 a.m.

FORMAT: Text only

SIZE: 1.4 kB

HITS: 12331

  1. VERSION BUILD=10.4.28.1074
  2. TAB T=1
  3. URL GOTO=http://demo.imacros.net/Automate/Eval
  4. 'Wait a random number (1 to 5) of seconds
  5. SET !VAR1 EVAL("Math.floor(Math.random()*5 + 1);")
  6. WAIT SECONDS={{!VAR1}}
  7. SET !EXTRACT_TEST_POPUP NO
  8. 'Extract the date
  9. TAG POS=1 TYPE=B ATTR=TXT:* EXTRACT=TXT
  10. 'Check if time deviates more than 20 hours. If yes, stop macro with an error
  11. SET !VAR2 EVAL("var n_hours = 20, ms_in_hour = 60*60*1000, s=\"{{!EXTRACT}}\"; var now = new Date(); var deviation = now.getTime()-Date.parse(s); if(deviation > n_hours*ms_in_hour ) MacroError(\"Time deviates more than 20 hours\")")
  12. 'Clean the !EXTRACT variable for the next task
  13. SET !EXTRACT NULL
  14. 'Count how many times the word "macro" appears on the page
  15. TAG POS=1 TYPE=DIV ATTR=ID:main EXTRACT=TXT
  16. SET !VAR1 EVAL("var m = '{{!EXTRACT}}'.match(/\\bMacro\\b/ig); if (!m) 'no word \"macro\" found'; else 'There are '+m.length+' occurrences of the word \"macro\" on this page';")
  17. PROMPT {{!VAR1}}
  18. 'Clean the !EXTRACT variable for the next task
  19. SET !EXTRACT NULL
  20. 'Extract the number in the input box
  21. TAG POS=1 TYPE=INPUT:TEXT FORM=ID:form1 ATTR=NAME:textfield EXTRACT=TXT
  22. 'Check if extracted number (still a string, has to be parsed into a float!) lies between 99 and 101.
  23. 'Stop macro with an error if not.
  24. SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\", d = parseFloat(s); if(d > 99 && d < 101) d; else MacroError(\"Value is not in the set range\");")

comments powered by Disqus