Skip to content

Instantly share code, notes, and snippets.

@raa0121
Last active August 29, 2015 14:17
Show Gist options
  • Save raa0121/ed89f546be675a2f5e4a to your computer and use it in GitHub Desktop.
Save raa0121/ed89f546be675a2f5e4a to your computer and use it in GitHub Desktop.
Spooky = require 'spooky'
module.exports = (robot) ->
robot.hear /(https?:\/\/.*)$/i, (msg) ->
url = RegExp.$1
spooky = new Spooky
child:
command: './node_modules/.bin/casperjs'
casper:
logLevel: 'debug',
verbose: true
, (err) ->
if err
e = new Error 'Failed to init SpookyJS'
e.details = err
throw e
spooky.on 'error', (e, stack) ->
console.error(e)
if (stack)
console.log(stack)
spooky.on 'console', (log) ->
if (log.lastIndexOf('Unsafe JavaScript attempt', 0) == 0)
return
console.log(log)
spooky.start url, ->
titles = @evaluate ->
items = document.querySelectorAll("title")
Array::map.call items, (e) ->
e.innerHTML
console.log(titles.join("\n"))
msg.send(titles.join("\n"))
spooky.run ->
@exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment