Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update examples to use system.args.

Also update coffee-script script path names in usage messages.

http://code.google.com/p/phantomjs/issues/detail?id=276
  • Loading branch information...
commit b73ec44796af086acb5d7cdc104374fbd577c769 1 parent 545a3f7
@execjosh execjosh authored committed
Showing with 154 additions and 109 deletions.
  1. +3 −2 examples/arguments.coffee
  2. +3 −2 examples/arguments.js
  3. +4 −3 examples/detectsniff.coffee
  4. +3 −2 examples/detectsniff.js
  5. +6 −5 examples/direction.coffee
  6. +4 −3 examples/direction.js
  7. +7 −6 examples/echoToFile.coffee
  8. +6 −5 examples/echoToFile.js
  9. +3 −2 examples/imagebin.coffee
  10. +3 −2 examples/imagebin.js
  11. +4 −3 examples/loadspeed.coffee
  12. +3 −2 examples/loadspeed.js
  13. +3 −2 examples/netlog.coffee
  14. +4 −2 examples/netlog.js
  15. +4 −3 examples/netsniff.coffee
  16. +5 −4 examples/netsniff.js
  17. +8 −7 examples/rasterize.coffee
  18. +7 −6 examples/rasterize.js
  19. +4 −2 examples/render_multi_url.coffee
  20. +8 −6 examples/render_multi_url.js
  21. +5 −3 examples/run-jasmine.coffee
  22. +4 −2 examples/run-jasmine.js
  23. +4 −2 examples/run-qunit.coffee
  24. +4 −2 examples/run-qunit.js
  25. +4 −3 examples/scandir.coffee
  26. +3 −2 examples/scandir.js
  27. +3 −2 examples/server.js
  28. +5 −3 examples/simpleserver.coffee
  29. +4 −3 examples/simpleserver.js
  30. +9 −6 examples/sleepsort.coffee
  31. +3 −2 examples/sleepsort.js
  32. +3 −2 examples/tweets.coffee
  33. +3 −2 examples/tweets.js
  34. +4 −3 examples/weather.coffee
  35. +4 −3 examples/weather.js
View
5 examples/arguments.coffee
@@ -1,6 +1,7 @@
-if phantom.args.length is 0
+system = require 'system'
+if system.args.length is 1
console.log 'Try to pass some args when invoking this script!'
else
- for arg, i in phantom.args
+ for arg, i in system.args
console.log i + ': ' + arg
phantom.exit()
View
5 examples/arguments.js
@@ -1,7 +1,8 @@
-if (phantom.args.length === 0) {
+var system = require('system');
+if (system.args.length === 1) {
console.log('Try to pass some args when invoking this script!');
} else {
- phantom.args.forEach(function (arg, i) {
+ system.args.forEach(function (arg, i) {
console.log(i + ': ' + arg);
});
}
View
7 examples/detectsniff.coffee
@@ -1,4 +1,5 @@
page = require('webpage').create()
+system = require 'system'
page.onInitialized = ->
page.evaluate ->
@@ -18,11 +19,11 @@ page.onInitialized = ->
window.navigator.sniffed = true
platform
-if phantom.args.length is 0
- console.log 'Usage: unsniff.js <some URL>'
+if system.args.length is 1
+ console.log 'Usage: unsniff.coffee <some URL>'
phantom.exit()
else
- address = phantom.args[0]
+ address = system.args[1]
console.log 'Checking ' + address + '...'
page.open address, (status) ->
if status isnt 'success'
View
5 examples/detectsniff.js
@@ -1,6 +1,7 @@
// Detect if a web page sniffs the user agent or not.
var page = require('webpage').create(),
+ system = require('system'),
sniffed,
address;
@@ -31,11 +32,11 @@ page.onInitialized = function () {
});
};
-if (phantom.args.length === 0) {
+if (system.args.length === 1) {
console.log('Usage: unsniff.js <some URL>');
phantom.exit();
} else {
- address = phantom.args[0];
+ address = system.args[1];
console.log('Checking ' + address + '...');
page.open(address, function (status) {
if (status !== 'success') {
View
11 examples/direction.coffee
@@ -1,14 +1,15 @@
# Get driving direction using Google Directions API.
page = require('webpage').create()
+system = require 'system'
-if phantom.args.length < 2
- console.log 'Usage: direction.js origin destination'
- console.log 'Example: direction.js "San Diego" "Palo Alto"'
+if system.args.length < 3
+ console.log 'Usage: direction.coffee origin destination'
+ console.log 'Example: direction.coffee "San Diego" "Palo Alto"'
phantom.exit(1)
else
- origin = phantom.args[0]
- dest = phantom.args[1]
+ origin = system.args[1]
+ dest = system.args[2]
page.open encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
'&destination=' + dest + '&units=imperial&mode=driving&sensor=false'),
(status) ->
View
7 examples/direction.js
@@ -1,15 +1,16 @@
// Get driving direction using Google Directions API.
var page = require('webpage').create(),
+ system = require('system'),
origin, dest, steps;
-if (phantom.args.length < 2) {
+if (system.args.length < 3) {
console.log('Usage: direction.js origin destination');
console.log('Example: direction.js "San Diego" "Palo Alto"');
phantom.exit(1);
} else {
- origin = phantom.args[0];
- dest = phantom.args[1];
+ origin = system.args[1];
+ dest = system.args[2];
page.open(encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
'&destination=' + dest + '&units=imperial&mode=driving&sensor=false'), function (status) {
if (status !== 'success') {
View
13 examples/echoToFile.coffee
@@ -1,18 +1,19 @@
# echoToFile.coffee - Write in a given file all the parameters passed on the CLI
fs = require 'fs'
+system = require 'system'
-if phantom.args.length < 2
- console.log "Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>"
+if system.args.length < 3
+ console.log "Usage: echoToFile.coffee DESTINATION_FILE <arguments to echo...>"
phantom.exit()
else
content = ""
f = null
- i = 1
- while i < phantom.args.length
- content += phantom.args[i] + (if i == phantom.args.length - 1 then "" else " ")
+ i = 2
+ while i < system.args.length
+ content += system.args[i] + (if i == system.args.length - 1 then "" else " ")
++i
try
- f = fs.open(phantom.args[0], "w")
+ f = fs.open(system.args[1], "w")
f.writeLine content
catch e
console.log e
View
11 examples/echoToFile.js
@@ -1,18 +1,19 @@
// echoToFile.js - Write in a given file all the parameters passed on the CLI
-var fs = require('fs');
+var fs = require('fs'),
+ system = require('system');
-if (phantom.args.length < 2) {
+if (system.args.length < 3) {
console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>");
phantom.exit();
} else {
var content = '',
f = null;
- for ( i= 1; i < phantom.args.length; ++i ) {
- content += phantom.args[i] + (i === phantom.args.length-1 ? '' : ' ');
+ for ( i= 2; i < system.args.length; ++i ) {
+ content += system.args[i] + (i === system.args.length-1 ? '' : ' ');
}
try {
- f = fs.open(phantom.args[0], "w");
+ f = fs.open(system.args[1], "w");
f.writeLine(content);
f.close();
} catch (e) {
View
5 examples/imagebin.coffee
@@ -1,12 +1,13 @@
# Upload an image to imagebin.org
page = require('webpage').create()
+system = require 'system'
-if phantom.args.length isnt 1
+if system.args.length isnt 2
console.log 'Usage: imagebin.coffee filename'
phantom.exit()
else
- fname = phantom.args[0]
+ fname = system.args[1]
page.open 'http://imagebin.org/index.php?page=add', ->
page.uploadFile 'input[name=image]', fname
page.evaluate ->
View
5 examples/imagebin.js
@@ -1,13 +1,14 @@
// Upload an image to imagebin.org
var page = require('webpage').create(),
+ system = require('webpage'),
fname;
-if (phantom.args.length !== 1) {
+if (system.args.length !== 2) {
console.log('Usage: imagebin.js filename');
phantom.exit();
} else {
- fname = phantom.args[0];
+ fname = system.args[1];
page.open("http://imagebin.org/index.php?page=add", function () {
page.uploadFile('input[name=image]', fname);
page.evaluate(function () {
View
7 examples/loadspeed.coffee
@@ -1,11 +1,12 @@
page = require('webpage').create()
+system = require 'system'
-if phantom.args.length is 0
- console.log 'Usage: loadspeed.js <some URL>'
+if system.args.length is 1
+ console.log 'Usage: loadspeed.coffee <some URL>'
phantom.exit()
else
t = Date.now()
- address = phantom.args[0]
+ address = system.args[1]
page.open address, (status) ->
if status isnt 'success'
console.log('FAIL to load the address')
View
5 examples/loadspeed.js
@@ -1,12 +1,13 @@
var page = require('webpage').create(),
+ system = require('system'),
t, address;
-if (phantom.args.length === 0) {
+if (system.args.length === 1) {
console.log('Usage: loadspeed.js <some URL>');
phantom.exit();
} else {
t = Date.now();
- address = phantom.args[0];
+ address = system.args[1];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
View
5 examples/netlog.coffee
@@ -1,10 +1,11 @@
page = require('webpage').create()
-address = phantom.args[0]
+system = require 'system'
-if phantom.args.length is 0
+if system.args.length is 1
console.log 'Usage: netlog.coffee <some URL>'
phantom.exit()
else
+ address = system.args[1]
page.onResourceRequested = (req) ->
console.log 'requested ' + JSON.stringify(req, undefined, 4)
View
6 examples/netlog.js
@@ -1,10 +1,12 @@
var page = require('webpage').create(),
- address = phantom.args[0];
+ system = require('system'),
+ address;
-if (phantom.args.length === 0) {
+if (system.args.length === 1) {
console.log('Usage: netlog.js <some URL>');
phantom.exit();
} else {
+ address = system.args[1];
page.onResourceRequested = function (req) {
console.log('requested: ' + JSON.stringify(req, undefined, 4));
View
7 examples/netsniff.coffee
@@ -74,12 +74,13 @@ createHAR = (address, title, startTime, resources) ->
entries: entries
page = require('webpage').create()
+system = require 'system'
-if phantom.args.length is 0
- console.log 'Usage: netsniff.js <some URL>'
+if system.args.length is 1
+ console.log 'Usage: netsniff.coffee <some URL>'
phantom.exit()
else
- page.address = phantom.args[0]
+ page.address = system.args[1]
page.resources = []
page.onLoadStarted = ->
View
9 examples/netsniff.js
@@ -84,14 +84,15 @@ function createHAR(address, title, startTime, resources)
};
}
-var page = require('webpage').create();
+var page = require('webpage').create(),
+ system = require('system');
-if (phantom.args.length === 0) {
- console.log('Usage: netsniff.js <some URL>');
+if (system.args.length === 1) {
+ console.log('Usage: netsniff.coffee <some URL>');
phantom.exit();
} else {
- page.address = phantom.args[0];
+ page.address = system.args[1];
page.resources = [];
page.onLoadStarted = function () {
View
15 examples/rasterize.coffee
@@ -1,19 +1,20 @@
page = require('webpage').create()
+system = require 'system'
-if phantom.args.length < 2 or phantom.args.length > 3
- console.log 'Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'
+if system.args.length < 3 or system.args.length > 4
+ console.log 'Usage: rasterize.coffee URL filename [paperwidth*paperheight|paperformat]'
console.log ' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'
phantom.exit()
else
- address = phantom.args[0]
- output = phantom.args[1]
+ address = system.args[1]
+ output = system.args[2]
page.viewportSize = { width: 600, height: 600 }
- if phantom.args.length is 3 and phantom.args[1].substr(-4) is ".pdf"
- size = phantom.args[2].split '*'
+ if system.args.length is 4 and system.args[2].substr(-4) is ".pdf"
+ size = system.args[3].split '*'
if size.length is 2
page.paperSize = { width: size[0], height: size[1], border: '0px' }
else
- page.paperSize = { format: phantom.args[2], orientation: 'portrait', border: '1cm' }
+ page.paperSize = { format: system.args[3], orientation: 'portrait', border: '1cm' }
page.open address, (status) ->
if status isnt 'success'
console.log 'Unable to load the address!'
View
13 examples/rasterize.js
@@ -1,18 +1,19 @@
var page = require('webpage').create(),
+ system = require('system'),
address, output, size;
-if (phantom.args.length < 2 || phantom.args.length > 3) {
+if (system.args.length < 3 || system.args.length > 4) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
phantom.exit();
} else {
- address = phantom.args[0];
- output = phantom.args[1];
+ address = system.args[1];
+ output = system.args[2];
page.viewportSize = { width: 600, height: 600 };
- if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") {
- size = phantom.args[2].split('*');
+ if (system.args.length === 3 && system.args[1].substr(-4) === ".pdf") {
+ size = system.args[2].split('*');
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
- : { format: phantom.args[2], orientation: 'portrait', margin: '1cm' };
+ : { format: system.args[2], orientation: 'portrait', margin: '1cm' };
}
page.open(address, function (status) {
if (status !== 'success') {
View
6 examples/render_multi_url.coffee
@@ -1,6 +1,8 @@
# Render Multiple URLs to file
# FIXME: For now it is fine with pure domain names: don't think it would work with paths and stuff like that
+system = require 'system'
+
# Extend the Array Prototype with a 'foreach'
Array.prototype.forEach = (action) ->
for i, j in this
@@ -25,8 +27,8 @@ renderUrlToFile = (url, file, callback) ->
callback url, file
# Read the passed args
-if phantom.args.length > 0
- arrayOfUrls = phantom.args
+if system.args.length > 1
+ arrayOfUrls = Array.prototype.slice.call system.args, 1
else
# Default (no args passed)
console.log 'Usage: phantomjs render_multi_url.coffee [domain.name1, domain.name2, ...]'
View
14 examples/render_multi_url.js
@@ -1,6 +1,8 @@
// Render Multiple URLs to file
// FIXME: For now it is fine with pure domain names: don't think it would work with paths and stuff like that
+var system = require('system');
+
// Extend the Array Prototype with a 'foreach'
Array.prototype.forEach = function (action) {
var i, len;
@@ -9,7 +11,7 @@ Array.prototype.forEach = function (action) {
}
};
-/**
+/**
* Render a given url to a given file
* @param url URL to render
* @param file File to render to
@@ -19,7 +21,7 @@ function renderUrlToFile(url, file, callback) {
var page = require('webpage').create();
page.viewportSize = { width: 800, height : 600 };
page.settings.userAgent = "Phantom.js bot";
-
+
page.open(url, function(status){
if ( status !== "success") {
console.log("Unable to render '"+url+"'");
@@ -33,22 +35,22 @@ function renderUrlToFile(url, file, callback) {
// Read the passed args
var arrayOfUrls;
-if ( phantom.args.length > 0 ) {
- arrayOfUrls = phantom.args;
+if ( system.args.length > 1 ) {
+ arrayOfUrls = Array.prototype.slice.call(system.args, 1);
} else {
// Default (no args passed)
console.log("Usage: phantomjs render_multi_url.js [domain.name1, domain.name2, ...]");
arrayOfUrls = [
'www.google.com',
'www.bbc.co.uk',
- 'www.phantomjs.org'
+ 'www.phantomjs.org'
];
}
// For each URL
arrayOfUrls.forEach(function(pos, url, total){
var file_name = "./" + url + ".png";
-
+
// Render to a file
renderUrlToFile("http://"+url, file_name, function(url, file){
console.log("Rendered '"+url+"' at '"+file+"'");
View
8 examples/run-jasmine.coffee
@@ -1,3 +1,5 @@
+system = require 'system'
+
##
# Wait until the test condition is true or a timeout occurs. Useful for waiting
# on a server response or for a ui change (fadeIn, etc.) to occur.
@@ -29,7 +31,7 @@ waitFor = (testFx, onReady, timeOutMillis=3000) ->
clearInterval interval #< Stop this interval
interval = setInterval f, 100 #< repeat check every 100ms
-if phantom.args.length isnt 1
+if system.args.length isnt 2
console.log 'Usage: run-jasmine.coffee URL'
phantom.exit()
@@ -39,7 +41,7 @@ page = require('webpage').create()
page.onConsoleMessage = (msg) ->
console.log msg
-page.open phantom.args[0], (status) ->
+page.open system.args[1], (status) ->
if status isnt 'success'
console.log 'Unable to access network'
phantom.exit()
@@ -53,7 +55,7 @@ page.open phantom.args[0], (status) ->
page.evaluate ->
console.log document.body.querySelector('.description').innerText
list = document.body.querySelectorAll('.failed > .description, .failed > .messages > .resultMessage')
- for el in list
+ for el in list
console.log el.innerText
phantom.exit()
View
6 examples/run-jasmine.js
@@ -1,3 +1,5 @@
+var system = require('system');
+
/**
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
@@ -34,7 +36,7 @@ function waitFor(testFx, onReady, timeOutMillis) {
};
-if (phantom.args.length === 0 || phantom.args.length > 2) {
+if (system.args.length !== 2) {
console.log('Usage: run-jasmine.js URL');
phantom.exit();
}
@@ -46,7 +48,7 @@ page.onConsoleMessage = function(msg) {
console.log(msg);
};
-page.open(phantom.args[0], function(status){
+page.open(system.args[1], function(status){
if (status !== "success") {
console.log("Unable to access network");
phantom.exit();
View
6 examples/run-qunit.coffee
@@ -1,3 +1,5 @@
+system = require 'system'
+
##
# Wait until the test condition is true or a timeout occurs. Useful for waiting
# on a server response or for a ui change (fadeIn, etc.) to occur.
@@ -29,7 +31,7 @@ waitFor = (testFx, onReady, timeOutMillis=3000) ->
clearInterval interval #< Stop this interval
interval = setInterval f, 100 #< repeat check every 100ms
-if phantom.args.length isnt 1
+if system.args.length isnt 2
console.log 'Usage: run-qunit.coffee URL'
phantom.exit(1)
@@ -39,7 +41,7 @@ page = require('webpage').create()
page.onConsoleMessage = (msg) ->
console.log msg
-page.open phantom.args[0], (status) ->
+page.open system.args[1], (status) ->
if status isnt 'success'
console.log 'Unable to access network'
phantom.exit(1)
View
6 examples/run-qunit.js
@@ -1,3 +1,5 @@
+var system = require('system');
+
/**
* Wait until the test condition is true or a timeout occurs. Useful for waiting
* on a server response or for a ui change (fadeIn, etc.) to occur.
@@ -34,7 +36,7 @@ function waitFor(testFx, onReady, timeOutMillis) {
};
-if (phantom.args.length === 0 || phantom.args.length > 2) {
+if (system.args.length !== 2) {
console.log('Usage: run-qunit.js URL');
phantom.exit(1);
}
@@ -46,7 +48,7 @@ page.onConsoleMessage = function(msg) {
console.log(msg);
};
-page.open(phantom.args[0], function(status){
+page.open(system.args[1], function(status){
if (status !== "success") {
console.log("Unable to access network");
phantom.exit(1);
View
7 examples/scandir.coffee
@@ -1,7 +1,8 @@
# List all the files in a Tree of Directories
+system = require 'system'
-if phantom.args.length != 1
- console.log "Usage: phantomjs scandir.js DIRECTORY_TO_SCAN"
+if system.args.length != 2
+ console.log "Usage: phantomjs scandir.coffee DIRECTORY_TO_SCAN"
phantom.exit()
scanDirectory = (path) ->
fs = require 'fs'
@@ -11,5 +12,5 @@ scanDirectory = (path) ->
fs.list(path).forEach (e) ->
scanDirectory path + "/" + e if e != "." and e != ".."
-scanDirectory phantom.args[0]
+scanDirectory system.args[1]
phantom.exit()
View
5 examples/scandir.js
@@ -1,6 +1,7 @@
// List all the files in a Tree of Directories
+var system = require('system');
-if (phantom.args.length !== 1) {
+if (system.args.length !== 2) {
console.log("Usage: phantomjs scandir.js DIRECTORY_TO_SCAN");
phantom.exit();
}
@@ -17,5 +18,5 @@ var scanDirectory = function (path) {
});
}
};
-scanDirectory(phantom.args[0]);
+scanDirectory(system.args[1]);
phantom.exit();
View
5 examples/server.js
@@ -1,12 +1,13 @@
var page = require('webpage').create();
var server = require('webserver').create();
+var system = require('system');
var host, port;
-if (phantom.args.length !== 1) {
+if (system.args.length !== 2) {
console.log('Usage: server.js <some port>');
phantom.exit();
} else {
- port = phantom.args[0];
+ port = system.args[1];
var listening = server.listen(port, function (request, response) {
console.log("GOT HTTP REQUEST");
console.log(JSON.stringify(request, null, 4));
View
8 examples/simpleserver.coffee
@@ -1,8 +1,10 @@
-if phantom.args.length is 0
- console.log "Usage: simpleserver.js <portnumber>"
+system = require 'system'
+
+if system.args.length is 1
+ console.log "Usage: simpleserver.coffee <portnumber>"
phantom.exit()
else
- port = phantom.args[0]
+ port = system.args[1]
server = require("webserver").create()
service = server.listen(port, (request, response) ->
View
7 examples/simpleserver.js
@@ -1,10 +1,11 @@
-var port, server, service;
+var port, server, service,
+ system = require('system');
-if (phantom.args.length !== 1) {
+if (system.args.length !== 2) {
console.log('Usage: simpleserver.js <portnumber>');
phantom.exit();
} else {
- port = phantom.args[0];
+ port = system.args[1];
server = require('webserver').create();
service = server.listen(port, function (request, response) {
View
15 examples/sleepsort.coffee
@@ -2,16 +2,19 @@
Sort integers from the command line in a very ridiculous way: leveraging timeouts :P
###
-if phantom.args < 1
- console.log "Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES"
+system = require 'system'
+
+if system.args.length < 2
+ console.log "Usage: phantomjs sleepsort.coffee PUT YOUR INTEGERS HERE SEPARATED BY SPACES"
phantom.exit()
else
sortedCount = 0
- for int in phantom.args
- setTimeout ((j) ->
+ args = Array.prototype.slice.call(system.args, 1)
+ for int in args
+ setTimeout (do (int) ->
->
- console.log j
+ console.log int
++sortedCount
- phantom.exit() if sortedCount is phantom.args.length)(int),
+ phantom.exit() if sortedCount is args.length),
int
View
5 examples/sleepsort.js
@@ -1,4 +1,5 @@
// sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
+var system = require('system');
function sleepSort(array, callback) {
var sortedCount = 0,
@@ -14,11 +15,11 @@ function sleepSort(array, callback) {
}
}
-if ( phantom.args < 1 ) {
+if ( system.args < 2 ) {
console.log("Usage: phantomjs sleepsort.js PUT YOUR INTEGERS HERE SEPARATED BY SPACES");
phantom.exit();
} else {
- sleepSort(phantom.args, function() {
+ sleepSort(Array.prototype.slice.call(system.args, 1), function() {
phantom.exit();
});
}
View
5 examples/tweets.coffee
@@ -1,6 +1,7 @@
# Get twitter status for given account (or for the default one, "HeadlessPhantom")
page = require('webpage').create()
+system = require 'system'
twitterId = 'HeadlessPhantom' #< default value
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
@@ -8,10 +9,10 @@ page.onConsoleMessage = (msg) ->
console.log msg
# Print usage message, if no twitter ID is passed
-if phantom.args.length < 1
+if system.args.length < 2
console.log 'Usage: tweets.coffee [twitter ID]'
else
- twitterId = phantom.args[0]
+ twitterId = system.args[1]
# Heading
console.log "*** Latest tweets from @#{twitterId} ***\n"
View
5 examples/tweets.js
@@ -1,6 +1,7 @@
// Get twitter status for given account (or for the default one, "HeadlessPhantom")
var page = require('webpage').create(),
+ system = require('system'),
twitterId = "HeadlessPhantom"; //< default value
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
@@ -9,10 +10,10 @@ page.onConsoleMessage = function(msg) {
};
// Print usage message, if no twitter ID is passed
-if (phantom.args.length < 1) {
+if (system.args.length < 2) {
console.log("Usage: tweets.js [twitter ID]");
} else {
- twitterId = phantom.args[0];
+ twitterId = system.args[1];
}
// Heading
View
7 examples/weather.coffee
@@ -1,17 +1,18 @@
# Get weather info for given address (or for the default one, "Mountain View")
page = require('webpage').create()
+system = require 'system'
address = 'Mountain View' #< default value
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
page.onConsoleMessage = (msg) ->
console.log msg
-# Print usage message, if no twitter ID is passed
-if phantom.args.length < 1
+# Print usage message, if no address is passed
+if system.args.length < 2
console.log 'Usage: weather.coffee [address]'
else
- address = phantom.args.join ' '
+ address = Array.prototype.slice.call(system.args, 1).join(' ')
# Heading
console.log "*** Loading weather information for '#{address}' ***\n"
View
7 examples/weather.js
@@ -1,6 +1,7 @@
// Get weather info for given address (or for the default one, "Mountain View")
var page = require('webpage').create(),
+ system = require('system'),
address = "Mountain View"; //< default value
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
@@ -8,11 +9,11 @@ page.onConsoleMessage = function(msg) {
console.log(msg);
};
-// Print usage message, if no twitter ID is passed
-if (phantom.args.length < 1) {
+// Print usage message, if no address is passed
+if (system.args.length < 2) {
console.log("Usage: weather.js [address]");
} else {
- address = phantom.args.join(' ');
+ address = Array.prototype.slice.call(system.args, 1).join(' ');
}
// Heading
Please sign in to comment.
Something went wrong with that request. Please try again.