Created
January 3, 2014 13:39
-
-
Save allquixotic/8237974 to your computer and use it in GitHub Desktop.
properly sanitized zombie.js bot this time
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
// Make sure we got a filename on the command line. | |
if (process.argv.length < 3) { | |
console.log('Usage: node ' + process.argv[1] + ' FILENAME'); | |
process.exit(1); | |
} | |
// Read the file and print its contents. | |
var fs = require('fs') | |
, filename = process.argv[2] | |
, happy = ""; | |
fs.readFile(filename, 'utf8', function(err, data) { | |
if (err) throw err; | |
console.log('[SO-ChatBot-Driver] OK: ' + filename); | |
//console.log(data) | |
happy = data; | |
}); | |
var Browser = require("zombie"); | |
var assert = require("assert"); | |
console.log("[SO-ChatBot-Driver] zombie and assert loaded"); | |
var chatURL = "http://chat.stackexchange.com/rooms/118/root-access"; | |
console.log('[SO-ChatBot-Driver] Going to ' + chatURL); | |
var browser = new Browser({ debug: true, maxWait: 30000, waitFor: 30000, userAgent: "Mozilla/5.0 (Windows NT 6.2; Win64; x64;) Gecko/20100101 Firefox/20.0" }); | |
//var browser = new Browser({ debug: true, maxWait: 20000, waitFor: 60000, userAgent: "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8)" }); | |
browser.visit(chatURL, function() { | |
console.log('[SO-ChatBot-Driver] 0n page ' + browser.location); | |
browser.dump(); | |
browser.wait(20000); | |
//var rslt = browser.document.evaluate("//a[starts-with(@href, '/login/global') and text() = 'logged in' and not(ancestor::div[contains(@style,'display:none')]) and not(ancestor::div[contains(@style,'display: none')])]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
browser.visit("http://chat.stackexchange.com/login/global?returnurl=" + encodeURIComponent(chatURL), function () { | |
console.log('[SO-ChatBot-Driver] 0n page ' + browser.location); | |
//var rslt2 = browser.document.evaluate("//a[contains(@href, '/users/chat-login')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
browser.visit("http://stackexchange.com/users/login?returnurl=%2fusers%2fchat-login", function () { | |
console.log('[SO-ChatBot-Driver] 0n page ' + browser.location); | |
browser.evaluate("openid.signin('stack_exchange'); var affildoc = window.document.getElementById('affiliate-signin-iframe').document; affildoc.getElementById('email').value = '[email protected]'; affildoc.getElementById('affiliate-signin-iframe').getElementById('password').value = 'nice try'; affildoc.getElementById('affiliate-button').click();"); | |
browser.wait().then(function() { | |
console.log('[SO-ChatBot-Driver] On page ' + browser.location); | |
browser.visit(chatURL, function () { | |
console.log('[SO-ChatBot-Driver] 0n page ' + browser.location); | |
browser.evaluate(happy); | |
//rslt = browser.document.evaluate("//a[starts-with(@href, '/login/global') and text() = 'logged in' and not(ancestor::div[contains(@style,'display:none')]) and not(ancestor::div[contains(@style,'display: none')])]", browser.document, null, 9, null).singleNodeValue; | |
/*browser.fire("click", rslt, function () { | |
console.log('[SO-ChatBot-Driver] 0n page ' + browser.location); | |
console.log('[SO-ChatBot-Driver] Loading bot!'); | |
browser.evaluate(happy); | |
console.log("Bot up and running!"); | |
});*/ | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment