diff options
author | Yaohan Chen <yaohan.chen@gmail.com> | 2014-04-05 00:26:38 -0400 |
---|---|---|
committer | Yaohan Chen <yaohan.chen@gmail.com> | 2014-04-05 00:26:38 -0400 |
commit | afc97d764b5d3b6279d05fadc3e5aea593d62eaf (patch) | |
tree | a1e7e8451155060cbac2834cafad69705f6e43e3 | |
parent | 9bd67f7b1e29ac08ea5bc9085c8e662d525b7c53 (diff) | |
download | hib-dlagent-afc97d764b5d3b6279d05fadc3e5aea593d62eaf.tar.gz hib-dlagent-afc97d764b5d3b6279d05fadc3e5aea593d62eaf.zip |
Minor changes in PhantomJS script
-rw-r--r-- | discover-url.coffee | 2 | ||||
-rw-r--r-- | util.coffee | 11 |
2 files changed, 5 insertions, 8 deletions
diff --git a/discover-url.coffee b/discover-url.coffee index bd7bcba..bd64ffd 100644 --- a/discover-url.coffee +++ b/discover-url.coffee @@ -14,7 +14,7 @@ page.open listing_page, (status) -> url = page.evaluate (filename) -> # Characters in filename may need to be escaped for use in a selector found = document.querySelector ".downloads.linux a[href*='#{filename}']" - found and found.getAttribute('href') + found?.getAttribute('href') , filename util.log "Found URL: #{url}" if url diff --git a/util.coffee b/util.coffee index 8b11814..e0ddb33 100644 --- a/util.coffee +++ b/util.coffee @@ -32,10 +32,8 @@ exports.handle_login = handle_login = (username, password) -> page.evaluate (username, password) -> username_box = document.querySelector 'input[name="username"]' password_box = document.querySelector 'input[name="password"]' - if username_box - username_box.value = username - if password_box - password_box.value = password + username_box?.value = username + password_box?.value = password (username_box or password_box)? , username, password @@ -52,7 +50,7 @@ exports.handle_captcha = handle_captcha = -> Recaptcha.reload() else captcha_box = document.querySelector '#recaptcha_response_field' - captcha_box.value = input + captcha_box?.value = input , input # handles login/captcha, repeating if necessary, and performs the action @@ -66,8 +64,7 @@ exports.handle_login_captcha = handle_login_captcha = (action, username, passwor page.evaluate -> # FIXME make sure we're submitting the right form form = document.querySelector('form') - if form - form.submit() + form?.submit() else log 'Logged in...' action() |