|
| 1 | +var Nightmare = require('nightmare'); |
| 2 | +var hound = new Nightmare(); |
| 3 | + |
| 4 | +/*********** Change me! ***********/ |
| 5 | +var config = { |
| 6 | + email: 'you can guess', |
| 7 | + password: 'what these are' |
| 8 | +}; |
| 9 | + |
| 10 | +function once (fn) { |
| 11 | + var called = false, res; |
| 12 | + return function () { |
| 13 | + if (called) { return res; } |
| 14 | + |
| 15 | + called = true; |
| 16 | + res = fn.apply(this, arguments); |
| 17 | + |
| 18 | + return res; |
| 19 | + }; |
| 20 | +} |
| 21 | + |
| 22 | +hound |
| 23 | + .goto('https://stackoverflow.com/users/login/') |
| 24 | + .screenshot('pics/pre-login.png') |
| 25 | + .type('#se-login input[type="email"]', config.email) |
| 26 | + .type('#se-login input[type="password"]', config.password) |
| 27 | + .click('#se-login input[type="button"]') |
| 28 | + .wait() |
| 29 | + .screenshot('pics/login.png') |
| 30 | + .goto('https://chat.stackoverflow.com/rooms/76070') |
| 31 | + .screenshot('pics/chat.png') |
| 32 | + .evaluate(function () { |
| 33 | + var script = document.createElement('script'); |
| 34 | + script.src = 'https://raw.github.com/Zirak/SO-ChatBot/master/master.js'; |
| 35 | + script.onload = function() { |
| 36 | + console.log('Loaded bot'); |
| 37 | + }; |
| 38 | + document.head.appendChild(script); |
| 39 | + }, function () { |
| 40 | + console.log('Injected chatbot.'); |
| 41 | + }) |
| 42 | + .setup(function () { |
| 43 | + var self = hound; |
| 44 | + |
| 45 | + setTimeout(next, 0); |
| 46 | + function next(err) { |
| 47 | + var item = self.queue.shift(); |
| 48 | + if (!item) { |
| 49 | + console.log('Should be done loading stuff.'); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + var method = item[0], |
| 54 | + args = item[1]; |
| 55 | + args.push(once(next)); |
| 56 | + method.apply(self, args); |
| 57 | + } |
| 58 | + }); |
0 commit comments