-
-
Save rlemon/2b34420d128c924615f5 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
var page = require('webpage').create(); | |
var path = null; | |
var fns = [ | |
{ | |
reg: /^(http|https):\/\/stackoverflow.com\/?/, | |
fn: openChat | |
}, | |
{ | |
reg: /^(http|https):\/\/chat.stackoverflow.com\/rooms\/17\/.*/, | |
fn: setupBot | |
} | |
]; | |
page.open('http://stackoverflow.com/users/login', function(status) { | |
page.render('pics/login.png'); | |
page.evaluate(DOMLogin); | |
page.render('pics/login2.png'); | |
}); | |
page.onUrlChanged = function(newTarget) { | |
path = newTarget; | |
console.log('requesting', newTarget); | |
}; | |
page.onLoadFinished = function(status) { | |
console.log(path, 'loaded'); | |
for( var i = 0; i < fns.length; i++ ) { | |
var res = fns[i].reg.test(path); | |
console.log( path , ' : ', res ); | |
if( res ) { | |
console.log('triggered', fns[i].reg); | |
setTimeout(fns[i].fn, 3000); | |
} | |
} | |
path = null; | |
}; | |
function DOMLogin() { | |
var settings = { | |
email: '....', | |
password: '....' | |
}; | |
var $id = document.getElementById.bind(document); | |
$id('email').value = settings.email; | |
$id('password').value = settings.password; | |
$id('submit-button').click(); | |
return; | |
} | |
function openChat() { | |
page.open('http://chat.stackoverflow.com/rooms/17', function() { | |
console.log('opened'); | |
page.evaluate(function() { | |
// do some shit | |
}) | |
}); | |
} | |
function setupBot() { | |
page.render('pics/chat.png'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment