mirror of
https://github.com/ariya/phantomjs.git
synced 2024-08-15 15:50:34 +03:00
Add "use strict"; declaration to all example scripts.
modernizr.js is not modified because it's not our code. En passant fixes: * Delete two scripts that depended on a Yahoo service that appears no longer to exist. * The PhantomJS website no longer has a leading www. * One script needed correction to *work* in strict mode. * One script would only exit if a page loaded successfully. (There may be other instances of this problem, this is the one I noticed.)
This commit is contained in:
parent
efd8dedfb5
commit
9ac8cccf0a
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
if (system.args.length === 1) {
|
||||
console.log('Try to pass some args when invoking this script!');
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var spawn = require("child_process").spawn
|
||||
var execFile = require("child_process").execFile
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create();
|
||||
page.viewportSize = { width: 400, height : 400 };
|
||||
page.content = '<html><body><canvas id="surface"></canvas></body></html>';
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var t = 10,
|
||||
interval = setInterval(function(){
|
||||
if ( t > 0 ) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Detect if a web page sniffs the user agent or not.
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
sniffed,
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Get driving direction using Google Directions API.
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
origin, dest, steps;
|
||||
|
@ -1,4 +1,5 @@
|
||||
// echoToFile.js - Write in a given file all the parameters passed on the CLI
|
||||
"use strict";
|
||||
var fs = require('fs'),
|
||||
system = require('system');
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var feature, supported = [], unsupported = [];
|
||||
|
||||
phantom.injectJs('modernizr.js');
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var fibs = [0, 1];
|
||||
var ticker = window.setInterval(function () {
|
||||
console.log(fibs[fibs.length - 1]);
|
||||
|
@ -1,5 +1,6 @@
|
||||
// List following and followers from several accounts
|
||||
|
||||
"use strict";
|
||||
var users = ['PhantomJS',
|
||||
'ariyahidayat',
|
||||
'detronizator',
|
||||
|
@ -1,2 +1,3 @@
|
||||
"use strict";
|
||||
console.log('Hello, world!');
|
||||
phantom.exit();
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Upload an image to imagebin.org
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
fname;
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Use 'page.injectJs()' to load the script itself in the Page context
|
||||
|
||||
"use strict";
|
||||
if ( typeof(phantom) !== "undefined" ) {
|
||||
var page = require('webpage').create();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Give the estimated location based on the IP address.
|
||||
|
||||
cb = function (data) {
|
||||
"use strict";
|
||||
window.cb = function (data) {
|
||||
var loc = data.city;
|
||||
if (data.region_name.length > 0)
|
||||
loc = loc + ', ' + data.region_name;
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
t, address;
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system');
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var universe = require('./universe');
|
||||
universe.start();
|
||||
console.log('The answer is ' + universe.answer);
|
||||
|
@ -1,14 +0,0 @@
|
||||
// List movies from kids-in-mind.com
|
||||
|
||||
var cbfunc = function (data) {
|
||||
globaldata= data;
|
||||
var list = data.query.results.movie;
|
||||
list.forEach(function (item) {
|
||||
console.log(item.title + ' [' + item.rating.MPAA.content + ']');
|
||||
});
|
||||
phantom.exit();
|
||||
};
|
||||
|
||||
var el = document.createElement('script');
|
||||
el.src = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20movies.kids-in-mind&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc';
|
||||
document.body.appendChild(el);
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
address;
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
if (!Date.prototype.toISOString) {
|
||||
Date.prototype.toISOString = function () {
|
||||
function pad(n) { return n < 10 ? '0' + n : n; }
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
host, port, address;
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
function helloWorld() {
|
||||
console.log(phantom.outputEncoding + ": こんにちは、世界!");
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
// NOTE.2: This script is not here to teach you ANY JavaScript. It's aweful!
|
||||
// NOTE.3: Main audience for this are people new to PhantomJS.
|
||||
|
||||
"use strict";
|
||||
var sys = require("system"),
|
||||
page = require("webpage").create(),
|
||||
logResources = false,
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var p = require("webpage").create();
|
||||
|
||||
p.onConsoleMessage = function(msg) { console.log(msg); };
|
||||
|
@ -1,19 +1,22 @@
|
||||
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create();
|
||||
|
||||
page.onConsoleMessage = function(msg) {
|
||||
console.log(msg);
|
||||
};
|
||||
|
||||
page.open("http://phantomjs.org", function(status) {
|
||||
if ( status === "success" ) {
|
||||
page.open("http://phantomjs.org/", function(status) {
|
||||
if (status === "success") {
|
||||
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
|
||||
page.evaluate(function() {
|
||||
console.log("$(\".explanation\").text() -> " + $(".explanation").text());
|
||||
});
|
||||
phantom.exit();
|
||||
phantom.exit(0);
|
||||
});
|
||||
} else {
|
||||
phantom.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Find pizza in Mountain View using Yelp
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search';
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Example using HTTP POST operation
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
server = 'http://posttestserver.com/post.php?dump',
|
||||
data = 'universe=expanding&answer=42';
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Example using HTTP POST operation
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
server = 'http://posttestserver.com/post.php?dump',
|
||||
data = '{"universe": "expanding", "answer": 42}';
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Example using HTTP POST operation
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
server = require('webserver').create(),
|
||||
system = require('system'),
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system');
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system');
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
address, output, size;
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Render Multiple URLs to file
|
||||
|
||||
"use strict";
|
||||
var RenderUrlsToFile, arrayOfUrls, system;
|
||||
|
||||
system = require("system");
|
||||
@ -59,7 +60,7 @@ if (system.args.length > 1) {
|
||||
arrayOfUrls = Array.prototype.slice.call(system.args, 1);
|
||||
} else {
|
||||
console.log("Usage: phantomjs render_multi_url.js [domain.name1, domain.name2, ...]");
|
||||
arrayOfUrls = ["www.google.com", "www.bbc.co.uk", "www.phantomjs.org"];
|
||||
arrayOfUrls = ["www.google.com", "www.bbc.co.uk", "phantomjs.org"];
|
||||
}
|
||||
|
||||
RenderUrlsToFile(arrayOfUrls, (function(status, url, file) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
|
||||
/**
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,6 @@
|
||||
// List all the files in a Tree of Directories
|
||||
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
|
||||
if (system.args.length !== 2) {
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Show BBC seasonal food list.
|
||||
|
||||
var cbfunc = function (data) {
|
||||
var list = data.query.results.results.result,
|
||||
names = ['January', 'February', 'March',
|
||||
'April', 'May', 'June',
|
||||
'July', 'August', 'September',
|
||||
'October', 'November', 'December'];
|
||||
list.forEach(function (item) {
|
||||
console.log([item.name.replace(/\s/ig, ' '), ':',
|
||||
names[item.atItsBestUntil], 'to',
|
||||
names[item.atItsBestFrom]].join(' '));
|
||||
});
|
||||
phantom.exit();
|
||||
};
|
||||
|
||||
var el = document.createElement('script');
|
||||
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';
|
||||
document.body.appendChild(el);
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create();
|
||||
var server = require('webserver').create();
|
||||
var system = require('system');
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var port, server, service,
|
||||
system = require('system');
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var port, server, service,
|
||||
system = require('system');
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
// sleepsort.js - Sort integers from the commandline in a very ridiculous way: leveraging timeouts :P
|
||||
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
|
||||
function sleepSort(array, callback) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var system = require('system');
|
||||
|
||||
system.stdout.write('Hello, system.stdout.write!');
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create();
|
||||
page.viewportSize = { width: 320, height: 480 };
|
||||
page.open('http://news.google.com/news/i/section?&topic=t', function (status) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
// Get twitter status for given account (or for the default one, "PhantomJS")
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
twitterId = "PhantomJS"; //< default value
|
||||
|
@ -2,6 +2,7 @@
|
||||
// There should NOT be a "universe.coffee" as only 1 of the 2 would
|
||||
// ever be loaded unless the file extension was specified.
|
||||
|
||||
"use strict";
|
||||
exports.answer = 42;
|
||||
|
||||
exports.start = function () {
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Modify global object at the page initialization.
|
||||
// In this example, effectively Math.random() always returns 0.42.
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create();
|
||||
|
||||
page.onInitialized = function () {
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create();
|
||||
console.log('The default user agent is ' + page.settings.userAgent);
|
||||
page.settings.userAgent = 'SpecialAgent';
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
console.log('using PhantomJS version ' +
|
||||
phantom.version.major + '.' +
|
||||
phantom.version.minor + '.' +
|
||||
|
@ -10,6 +10,8 @@
|
||||
* as a callback function.
|
||||
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
function waitFor(testFx, onReady, timeOutMillis) {
|
||||
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, //< Default Max Timout is 3s
|
||||
start = new Date().getTime(),
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var p = require("webpage").create();
|
||||
|
||||
function pageTitle(page) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
city,
|
||||
|
Loading…
Reference in New Issue
Block a user