phantomjs.rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +7 -0
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +16 -0
- data/Rakefile +1 -0
- data/lib/phantomjs.rb +53 -0
- data/lib/phantomjs/version.rb +3 -0
- data/phantomjs.rb.gemspec +24 -0
- data/spec/phantomjs_spec.rb +13 -0
- data/spec/runner.js +2 -0
- data/vendor/phantomjs-1.4.1_OSX/ChangeLog +145 -0
- data/vendor/phantomjs-1.4.1_OSX/LICENSE.BSD +22 -0
- data/vendor/phantomjs-1.4.1_OSX/README.md +33 -0
- data/vendor/phantomjs-1.4.1_OSX/bin/Info.plist +12 -0
- data/vendor/phantomjs-1.4.1_OSX/bin/phantomjs +0 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/arguments.coffee +6 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/arguments.js +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee +46 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.js +51 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/countdown.coffee +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/countdown.js +9 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.coffee +40 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/direction.coffee +29 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/direction.js +34 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.coffee +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/features.js +30 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/fibo.coffee +8 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/fibo.js +9 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/follow.coffee +54 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/follow.js +59 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/hello.coffee +2 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/hello.js +2 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.coffee +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/injectme.coffee +23 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/injectme.js +25 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.js +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/modernizr.js +1116 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/movies.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/movies.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netlog.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netlog.js +23 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.coffee +109 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.js +131 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.coffee +12 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.js +16 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.coffee +13 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.js +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/pizza.coffee +18 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/pizza.js +20 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/post.coffee +12 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/post.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.coffee +22 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.js +27 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.js +60 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.coffee +59 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.js +77 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.coffee +62 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.js +74 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/scandir.coffee +15 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/scandir.js +21 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.js +19 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.coffee +35 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.js +40 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.js +24 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/technews.coffee +17 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/technews.js +16 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee +30 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/tweets.js +36 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.coffee +18 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.js +24 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/useragent.coffee +11 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/useragent.js +14 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/version.coffee +5 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/version.js +5 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/weather.coffee +48 -0
- data/vendor/phantomjs-1.4.1_OSX/examples/weather.js +57 -0
- data/vendor/phantomjs-1.4.1_OSX/lib/jquery.js +8374 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/ChangeLog +177 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/LICENSE.BSD +22 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/README.md +33 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/Info.plist +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/phantomjs +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.coffee +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee +46 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.js +51 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.coffee +8 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.coffee +41 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.js +58 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee +30 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.js +35 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.js +24 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/features.js +30 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.coffee +8 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.js +9 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.coffee +29 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.coffee +2 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.js +2 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.js +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.coffee +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.js +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/modernizr.js +1116 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.coffee +110 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.js +132 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.coffee +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.js +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.coffee +13 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.js +19 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.js +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.coffee +12 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/postserver.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printenv.js +10 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printmargins.js +35 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.coffee +23 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.js +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.coffee +50 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.js +62 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.coffee +61 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.js +79 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.coffee +64 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.js +76 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.coffee +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.js +22 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.coffee +17 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.js +19 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/server.js +43 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/serverkeepalive.js +34 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.coffee +38 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.js +42 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.coffee +20 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.js +25 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.coffee +17 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.js +16 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.coffee +31 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js +37 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.coffee +18 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.js +24 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.coffee +11 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.js +14 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.coffee +5 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.js +5 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.coffee +48 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.js +57 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.coffee +49 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.js +58 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.prl +7 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8.0 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.la +28 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.prl +6 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9 +0 -0
- data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9.0 +0 -0
- metadata +252 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
var system = require('system');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Wait until the test condition is true or a timeout occurs. Useful for waiting
|
5
|
+
* on a server response or for a ui change (fadeIn, etc.) to occur.
|
6
|
+
*
|
7
|
+
* @param testFx javascript condition that evaluates to a boolean,
|
8
|
+
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
9
|
+
* as a callback function.
|
10
|
+
* @param onReady what to do when testFx condition is fulfilled,
|
11
|
+
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
12
|
+
* as a callback function.
|
13
|
+
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
14
|
+
*/
|
15
|
+
function waitFor(testFx, onReady, timeOutMillis) {
|
16
|
+
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3001, //< Default Max Timout is 3s
|
17
|
+
start = new Date().getTime(),
|
18
|
+
condition = false,
|
19
|
+
interval = setInterval(function() {
|
20
|
+
if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
|
21
|
+
// If not time-out yet and condition not yet fulfilled
|
22
|
+
condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
|
23
|
+
} else {
|
24
|
+
if(!condition) {
|
25
|
+
// If condition still not fulfilled (timeout but condition is 'false')
|
26
|
+
console.log("'waitFor()' timeout");
|
27
|
+
phantom.exit(1);
|
28
|
+
} else {
|
29
|
+
// Condition fulfilled (timeout and/or condition is 'true')
|
30
|
+
console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
|
31
|
+
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
|
32
|
+
clearInterval(interval); //< Stop this interval
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}, 100); //< repeat check every 250ms
|
36
|
+
};
|
37
|
+
|
38
|
+
|
39
|
+
if (system.args.length !== 2) {
|
40
|
+
console.log('Usage: run-qunit.js URL');
|
41
|
+
phantom.exit(1);
|
42
|
+
}
|
43
|
+
|
44
|
+
var page = require('webpage').create();
|
45
|
+
|
46
|
+
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
47
|
+
page.onConsoleMessage = function(msg) {
|
48
|
+
console.log(msg);
|
49
|
+
};
|
50
|
+
|
51
|
+
page.open(system.args[1], function(status){
|
52
|
+
if (status !== "success") {
|
53
|
+
console.log("Unable to access network");
|
54
|
+
phantom.exit(1);
|
55
|
+
} else {
|
56
|
+
waitFor(function(){
|
57
|
+
return page.evaluate(function(){
|
58
|
+
var el = document.getElementById('qunit-testresult');
|
59
|
+
if (el && el.innerText.match('completed')) {
|
60
|
+
return true;
|
61
|
+
}
|
62
|
+
return false;
|
63
|
+
});
|
64
|
+
}, function(){
|
65
|
+
var failedNum = page.evaluate(function(){
|
66
|
+
var el = document.getElementById('qunit-testresult');
|
67
|
+
console.log(el.innerText);
|
68
|
+
try {
|
69
|
+
return el.getElementsByClassName('failed')[0].innerHTML;
|
70
|
+
} catch (e) { }
|
71
|
+
return 10000;
|
72
|
+
});
|
73
|
+
phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0);
|
74
|
+
});
|
75
|
+
}
|
76
|
+
});
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# List all the files in a Tree of Directories
|
2
|
+
system = require 'system'
|
3
|
+
|
4
|
+
if system.args.length != 2
|
5
|
+
console.log "Usage: phantomjs scandir.coffee DIRECTORY_TO_SCAN"
|
6
|
+
phantom.exit()
|
7
|
+
scanDirectory = (path) ->
|
8
|
+
fs = require 'fs'
|
9
|
+
if fs.exists(path) and fs.isFile(path)
|
10
|
+
console.log path
|
11
|
+
else if fs.isDirectory(path)
|
12
|
+
fs.list(path).forEach (e) ->
|
13
|
+
scanDirectory path + "/" + e if e != "." and e != ".."
|
14
|
+
|
15
|
+
scanDirectory system.args[1]
|
16
|
+
phantom.exit()
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// List all the files in a Tree of Directories
|
2
|
+
var system = require('system');
|
3
|
+
|
4
|
+
if (system.args.length !== 2) {
|
5
|
+
console.log("Usage: phantomjs scandir.js DIRECTORY_TO_SCAN");
|
6
|
+
phantom.exit();
|
7
|
+
}
|
8
|
+
|
9
|
+
var scanDirectory = function (path) {
|
10
|
+
var fs = require('fs');
|
11
|
+
if (fs.exists(path) && fs.isFile(path)) {
|
12
|
+
console.log(path);
|
13
|
+
} else if (fs.isDirectory(path)) {
|
14
|
+
fs.list(path).forEach(function (e) {
|
15
|
+
if ( e !== "." && e !== ".." ) { //< Avoid loops
|
16
|
+
scanDirectory(path + '/' + e);
|
17
|
+
}
|
18
|
+
});
|
19
|
+
}
|
20
|
+
};
|
21
|
+
scanDirectory(system.args[1]);
|
22
|
+
phantom.exit();
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Show BBC seasonal food list.
|
2
|
+
|
3
|
+
window.cbfunc = (data) ->
|
4
|
+
list = data.query.results.results.result
|
5
|
+
names = ['January', 'February', 'March',
|
6
|
+
'April', 'May', 'June',
|
7
|
+
'July', 'August', 'September',
|
8
|
+
'October', 'November', 'December']
|
9
|
+
for item in list
|
10
|
+
console.log [item.name.replace(/\s/ig, ' '), ':',
|
11
|
+
names[item.atItsBestUntil], 'to',
|
12
|
+
names[item.atItsBestFrom]].join(' ')
|
13
|
+
phantom.exit()
|
14
|
+
|
15
|
+
el = document.createElement 'script'
|
16
|
+
el.src = 'http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20bbc.goodfood.seasonal%3B&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=window.cbfunc'
|
17
|
+
document.body.appendChild el
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// Show BBC seasonal food list.
|
2
|
+
|
3
|
+
var cbfunc = function (data) {
|
4
|
+
var list = data.query.results.results.result,
|
5
|
+
names = ['January', 'February', 'March',
|
6
|
+
'April', 'May', 'June',
|
7
|
+
'July', 'August', 'September',
|
8
|
+
'October', 'November', 'December'];
|
9
|
+
list.forEach(function (item) {
|
10
|
+
console.log([item.name.replace(/\s/ig, ' '), ':',
|
11
|
+
names[item.atItsBestUntil], 'to',
|
12
|
+
names[item.atItsBestFrom]].join(' '));
|
13
|
+
});
|
14
|
+
phantom.exit();
|
15
|
+
};
|
16
|
+
|
17
|
+
var el = document.createElement('script');
|
18
|
+
el.src = 'http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20bbc.goodfood.seasonal%3B&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc';
|
19
|
+
document.body.appendChild(el);
|
@@ -0,0 +1,43 @@
|
|
1
|
+
var page = require('webpage').create();
|
2
|
+
var server = require('webserver').create();
|
3
|
+
var system = require('system');
|
4
|
+
var host, port;
|
5
|
+
|
6
|
+
if (system.args.length !== 2) {
|
7
|
+
console.log('Usage: server.js <some port>');
|
8
|
+
phantom.exit();
|
9
|
+
} else {
|
10
|
+
port = system.args[1];
|
11
|
+
var listening = server.listen(port, function (request, response) {
|
12
|
+
console.log("GOT HTTP REQUEST");
|
13
|
+
console.log(JSON.stringify(request, null, 4));
|
14
|
+
|
15
|
+
// we set the headers here
|
16
|
+
response.statusCode = 200;
|
17
|
+
response.headers = {"Cache": "no-cache", "Content-Type": "text/html"};
|
18
|
+
// this is also possible:
|
19
|
+
response.setHeader("foo", "bar");
|
20
|
+
// now we write the body
|
21
|
+
// note: the headers above will now be sent implictly
|
22
|
+
response.write("<html><head><title>YES!</title></head>");
|
23
|
+
// note: writeBody can be called multiple times
|
24
|
+
response.write("<body><p>pretty cool :)</body></html>");
|
25
|
+
response.close();
|
26
|
+
});
|
27
|
+
if (!listening) {
|
28
|
+
console.log("could not create web server listening on port " + port);
|
29
|
+
phantom.exit();
|
30
|
+
}
|
31
|
+
var url = "http://localhost:" + port + "/foo/bar.php?asdf=true";
|
32
|
+
console.log("SENDING REQUEST TO:");
|
33
|
+
console.log(url);
|
34
|
+
page.open(url, function (status) {
|
35
|
+
if (status !== 'success') {
|
36
|
+
console.log('FAIL to load the address');
|
37
|
+
} else {
|
38
|
+
console.log("GOT REPLY FROM SERVER:");
|
39
|
+
console.log(page.content);
|
40
|
+
}
|
41
|
+
phantom.exit();
|
42
|
+
});
|
43
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
var port, server, service,
|
2
|
+
system = require('system');
|
3
|
+
|
4
|
+
if (system.args.length !== 2) {
|
5
|
+
console.log('Usage: serverkeepalive.js <portnumber>');
|
6
|
+
phantom.exit();
|
7
|
+
} else {
|
8
|
+
port = system.args[1];
|
9
|
+
server = require('webserver').create();
|
10
|
+
|
11
|
+
service = server.listen(port, { keepAlive: true }, function (request, response) {
|
12
|
+
console.log('Request at ' + new Date());
|
13
|
+
console.log(JSON.stringify(request, null, 4));
|
14
|
+
|
15
|
+
var body = JSON.stringify(request, null, 4);
|
16
|
+
response.statusCode = 200;
|
17
|
+
response.headers = {
|
18
|
+
'Cache': 'no-cache',
|
19
|
+
'Content-Type': 'text/plain',
|
20
|
+
'Connection': 'Keep-Alive',
|
21
|
+
'Keep-Alive': 'timeout=5, max=100',
|
22
|
+
'Content-Length': body.length
|
23
|
+
};
|
24
|
+
response.write(body);
|
25
|
+
response.close();
|
26
|
+
});
|
27
|
+
|
28
|
+
if (service) {
|
29
|
+
console.log('Web server running on port ' + port);
|
30
|
+
} else {
|
31
|
+
console.log('Error: Could not create web server listening on port ' + port);
|
32
|
+
phantom.exit();
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
system = require 'system'
|
2
|
+
|
3
|
+
if system.args.length is 1
|
4
|
+
console.log "Usage: simpleserver.coffee <portnumber>"
|
5
|
+
phantom.exit()
|
6
|
+
else
|
7
|
+
port = system.args[1]
|
8
|
+
server = require("webserver").create()
|
9
|
+
|
10
|
+
service = server.listen(port, (request, response) ->
|
11
|
+
|
12
|
+
console.log "Request at " + new Date()
|
13
|
+
console.log JSON.stringify(request, null, 4)
|
14
|
+
|
15
|
+
response.statusCode = 200
|
16
|
+
response.headers =
|
17
|
+
Cache: "no-cache"
|
18
|
+
"Content-Type": "text/html"
|
19
|
+
|
20
|
+
response.write "<html>"
|
21
|
+
response.write "<head>"
|
22
|
+
response.write "<title>Hello, world!</title>"
|
23
|
+
response.write "</head>"
|
24
|
+
response.write "<body>"
|
25
|
+
response.write "<p>This is from PhantomJS web server.</p>"
|
26
|
+
response.write "<p>Request data:</p>"
|
27
|
+
response.write "<pre>"
|
28
|
+
response.write JSON.stringify(request, null, 4)
|
29
|
+
response.write "</pre>"
|
30
|
+
response.write "</body>"
|
31
|
+
response.write "</html>"
|
32
|
+
response.close()
|
33
|
+
)
|
34
|
+
if service
|
35
|
+
console.log "Web server running on port " + port
|
36
|
+
else
|
37
|
+
console.log "Error: Could not create web server listening on port " + port
|
38
|
+
phantom.exit()
|
@@ -0,0 +1,42 @@
|
|
1
|
+
var port, server, service,
|
2
|
+
system = require('system');
|
3
|
+
|
4
|
+
if (system.args.length !== 2) {
|
5
|
+
console.log('Usage: simpleserver.js <portnumber>');
|
6
|
+
phantom.exit();
|
7
|
+
} else {
|
8
|
+
port = system.args[1];
|
9
|
+
server = require('webserver').create();
|
10
|
+
|
11
|
+
service = server.listen(port, function (request, response) {
|
12
|
+
|
13
|
+
console.log('Request at ' + new Date());
|
14
|
+
console.log(JSON.stringify(request, null, 4));
|
15
|
+
|
16
|
+
response.statusCode = 200;
|
17
|
+
response.headers = {
|
18
|
+
'Cache': 'no-cache',
|
19
|
+
'Content-Type': 'text/html'
|
20
|
+
};
|
21
|
+
response.write('<html>');
|
22
|
+
response.write('<head>');
|
23
|
+
response.write('<title>Hello, world!</title>');
|
24
|
+
response.write('</head>');
|
25
|
+
response.write('<body>');
|
26
|
+
response.write('<p>This is from PhantomJS web server.</p>');
|
27
|
+
response.write('<p>Request data:</p>');
|
28
|
+
response.write('<pre>');
|
29
|
+
response.write(JSON.stringify(request, null, 4));
|
30
|
+
response.write('</pre>');
|
31
|
+
response.write('</body>');
|
32
|
+
response.write('</html>');
|
33
|
+
response.close();
|
34
|
+
});
|
35
|
+
|
36
|
+
if (service) {
|
37
|
+
console.log('Web server running on port ' + port);
|
38
|
+
} else {
|
39
|
+
console.log('Error: Could not create web server listening on port ' + port);
|
40
|
+
phantom.exit();
|
41
|
+
}
|
42
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
###
|
2
|
+
Sort integers from the command line in a very ridiculous way: leveraging timeouts :P
|
3
|
+
###
|
4
|
+
|
5
|
+
system = require 'system'
|
6
|
+
|
7
|
+
if system.args.length < 2
|
8
|
+
console.log "Usage: phantomjs sleepsort.coffee PUT YOUR INTEGERS HERE SEPARATED BY SPACES"
|
9
|
+
phantom.exit()
|
10
|
+
else
|
11
|
+
sortedCount = 0
|
12
|
+
args = Array.prototype.slice.call(system.args, 1)
|
13
|
+
for int in args
|
14
|
+
setTimeout (do (int) ->
|
15
|
+
->
|
16
|
+
console.log int
|
17
|
+
++sortedCount
|
18
|
+
phantom.exit() if sortedCount is args.length),
|
19
|
+
int
|
20
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
|
2
|
+
var system = require('system');
|
3
|
+
|
4
|
+
function sleepSort(array, callback) {
|
5
|
+
var sortedCount = 0,
|
6
|
+
i, len;
|
7
|
+
for ( i = 0, len = array.length; i < len; ++i ) {
|
8
|
+
setTimeout((function(j){
|
9
|
+
return function() {
|
10
|
+
console.log(array[j]);
|
11
|
+
++sortedCount;
|
12
|
+
(len === sortedCount) && callback();
|
13
|
+
};
|
14
|
+
}(i)), array[i]);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
if ( system.args < 2 ) {
|
19
|
+
console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES");
|
20
|
+
phantom.exit();
|
21
|
+
} else {
|
22
|
+
sleepSort(Array.prototype.slice.call(system.args, 1), function() {
|
23
|
+
phantom.exit();
|
24
|
+
});
|
25
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
page = require('webpage').create()
|
2
|
+
|
3
|
+
page.viewportSize = { width: 320, height: 480 }
|
4
|
+
|
5
|
+
page.open 'http://news.google.com/news/i/section?&topic=t',
|
6
|
+
(status) ->
|
7
|
+
if status isnt 'success'
|
8
|
+
console.log 'Unable to access the network!'
|
9
|
+
else
|
10
|
+
page.evaluate ->
|
11
|
+
body = document.body
|
12
|
+
body.style.backgroundColor = '#fff'
|
13
|
+
body.querySelector('div#title-block').style.display = 'none'
|
14
|
+
body.querySelector('form#edition-picker-form')
|
15
|
+
.parentElement.parentElement.style.display = 'none'
|
16
|
+
page.render 'technews.png'
|
17
|
+
phantom.exit()
|
@@ -0,0 +1,16 @@
|
|
1
|
+
var page = require('webpage').create();
|
2
|
+
page.viewportSize = { width: 320, height: 480 };
|
3
|
+
page.open('http://news.google.com/news/i/section?&topic=t', function (status) {
|
4
|
+
if (status !== 'success') {
|
5
|
+
console.log('Unable to access the network!');
|
6
|
+
} else {
|
7
|
+
page.evaluate(function () {
|
8
|
+
var body = document.body;
|
9
|
+
body.style.backgroundColor = '#fff';
|
10
|
+
body.querySelector('div#title-block').style.display = 'none';
|
11
|
+
body.querySelector('form#edition-picker-form').parentElement.parentElement.style.display = 'none';
|
12
|
+
});
|
13
|
+
page.render('technews.png');
|
14
|
+
}
|
15
|
+
phantom.exit();
|
16
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Get twitter status for given account (or for the default one, "HeadlessPhantom")
|
2
|
+
|
3
|
+
page = require('webpage').create()
|
4
|
+
system = require 'system'
|
5
|
+
twitterId = 'HeadlessPhantom' #< default value
|
6
|
+
|
7
|
+
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
8
|
+
page.onConsoleMessage = (msg) ->
|
9
|
+
console.log msg
|
10
|
+
|
11
|
+
# Print usage message, if no twitter ID is passed
|
12
|
+
if system.args.length < 2
|
13
|
+
console.log 'Usage: tweets.coffee [twitter ID]'
|
14
|
+
else
|
15
|
+
twitterId = system.args[1]
|
16
|
+
|
17
|
+
# Heading
|
18
|
+
console.log "*** Latest tweets from @#{twitterId} ***\n"
|
19
|
+
|
20
|
+
# Open Twitter Mobile and, onPageLoad, do...
|
21
|
+
page.open encodeURI("http://mobile.twitter.com/#{twitterId}"), (status) ->
|
22
|
+
# Check for page load success
|
23
|
+
if status isnt 'success'
|
24
|
+
console.log 'Unable to access network'
|
25
|
+
else
|
26
|
+
# Execute some DOM inspection within the page context
|
27
|
+
page.evaluate ->
|
28
|
+
list = document.querySelectorAll 'span.status'
|
29
|
+
for i, j in list
|
30
|
+
console.log "#{j + 1}: #{i.innerHTML.replace /<.*?>/g, ''}"
|
31
|
+
phantom.exit()
|
@@ -0,0 +1,37 @@
|
|
1
|
+
// Get twitter status for given account (or for the default one, "HeadlessPhantom")
|
2
|
+
|
3
|
+
var page = require('webpage').create(),
|
4
|
+
system = require('system'),
|
5
|
+
twitterId = "HeadlessPhantom"; //< default value
|
6
|
+
|
7
|
+
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
8
|
+
page.onConsoleMessage = function(msg) {
|
9
|
+
console.log(msg);
|
10
|
+
};
|
11
|
+
|
12
|
+
// Print usage message, if no twitter ID is passed
|
13
|
+
if (system.args.length < 2) {
|
14
|
+
console.log("Usage: tweets.js [twitter ID]");
|
15
|
+
} else {
|
16
|
+
twitterId = system.args[1];
|
17
|
+
}
|
18
|
+
|
19
|
+
// Heading
|
20
|
+
console.log("*** Latest tweets from @" + twitterId + " ***\n");
|
21
|
+
|
22
|
+
// Open Twitter Mobile and, onPageLoad, do...
|
23
|
+
page.open(encodeURI("http://mobile.twitter.com/" + twitterId), function (status) {
|
24
|
+
// Check for page load success
|
25
|
+
if (status !== "success") {
|
26
|
+
console.log("Unable to access network");
|
27
|
+
} else {
|
28
|
+
// Execute some DOM inspection within the page context
|
29
|
+
page.evaluate(function() {
|
30
|
+
var list = document.querySelectorAll('span.status');
|
31
|
+
for (var i = 0; i < list.length; ++i) {
|
32
|
+
console.log((i + 1) + ": " + list[i].innerHTML.replace(/<.*?>/g, ''));
|
33
|
+
}
|
34
|
+
});
|
35
|
+
}
|
36
|
+
phantom.exit();
|
37
|
+
});
|