Last active
August 29, 2015 14:17
-
-
Save raa0121/ed89f546be675a2f5e4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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