Commit c269f4fd c269f4fdfd214ead647d9501cf960581cc68e1ef by Brikou CARRE

tweaked var declaration

1 parent 34d6e3f7
......@@ -2,12 +2,11 @@
* Create a mosaic image from all headline photos on BBC homepage
*/
var buildPage, casper, currentLink, images, nbLinks, next;
casper = require("casper").create();
nbLinks = 0;
currentLink = 1;
images = [];
var casper = require("casper").create();
var nbLinks = 0;
var currentLink = 1;
var images = [];
var buildPage, next;
// helper to hide some element from remote DOM
casper.hide = function(selector) {
......
var casper, dump;
casper = require("casper").create();
dump = require("utils").dump;
var casper = require("casper").create();
var dump = require("utils").dump;
// removing default options passed by the Python executable
casper.cli.drop("cli");
......
var addLinks, casper, check, currentLink, links, searchLinks, start, upTo;
casper = require("casper").create({
var casper = require("casper").create({
verbose: true
});
// If we don't set a limit, it could go on forever
upTo = ~~casper.cli.get(0) || 10;
var upTo = ~~casper.cli.get(0) || 10;
/*
Fetch all <a> elements from the page and return
the ones which contains a href starting with 'http://'
*/
searchLinks = function() {
var searchLinks = function() {
var filter, map;
filter = Array.prototype.filter;
map = Array.prototype.map;
......@@ -23,7 +21,7 @@ searchLinks = function() {
};
// The base links array
links = [
var links = [
"http://google.com/",
"http://yahoo.com/",
"http://bing.com/"
......@@ -52,7 +50,7 @@ casper.then(function() {
this.echo("Starting");
});
currentLink = 0;
var currentLink = 0;
// As long as it has a next link, and is under the maximum limit, will keep running
function check() {
......
var casper, links;
var casper = require("casper").create();
casper = require("casper").create();
links = [
var links = [
"http://google.com/",
"http://yahoo.com/",
"http://bing.com/"
......
......@@ -2,9 +2,7 @@
* This script will add a custom HTTP status code handler, here for 404 pages.
*/
var casper, links;
casper = require("casper").create();
var casper = require("casper").create();
casper.on("http.status.200", function(resource) {
this.echo(resource.url + " is OK", "INFO");
......@@ -26,7 +24,7 @@ casper.on("http.status.500", function(resource) {
this.echo(resource.url + " is in error", "ERROR");
});
links = [
var links = [
"http://google.com/",
"http://www.google.com/",
"http://www.google.com/plop"
......
var casper, fantomas, links;
casper = require("casper").create({
var casper = require("casper").create({
loadImages: false,
logLevel: "debug",
verbose: true
});
links = {
var links = {
"http://edition.cnn.com/": 0,
"http://www.nytimes.com/": 0,
"http://www.bbc.co.uk/": 0,
"http://www.guardian.co.uk/": 0
};
fantomas = Object.create(casper);
var fantomas = Object.create(casper);
fantomas.countLinks = function() {
return this.evaluate(function() {
......
links = []
casper = require("casper").create()
getLinks = ->
links = document.querySelectorAll("h3.r a")
Array::map.call links, (e) ->
......@@ -5,13 +8,13 @@ getLinks = ->
casper.start "http://google.fr/", ->
# search for 'casperjs' from google form
@fill "form[action=\"/search\"]", q: "casperjs" , true
@fill "form[action=\"/search\"]", q: "casperjs", true
casper.then ->
# aggregate results for the 'casperjs' search
links = @evaluate(getLinks)
# now search for 'phantomjs' by fillin the form again
@fill "form[action=\"/search\"]", q: "phantomjs" , true
@fill "form[action=\"/search\"]", q: "phantomjs", true
casper.then ->
# aggregate results for the 'phantomjs' search
......@@ -20,5 +23,5 @@ casper.then ->
casper.run ->
# echo results in some pretty fashion
@echo links.length + " links found:"
@echo(" - " + links.join("\n - "))
@echo " - " + links.join("\n - ")
@exit()
......
var casper, getLinks, links;
var links = [];
var casper = require("casper").create();
getLinks = function() {
function getLinks() {
var links = document.querySelectorAll("h3.r a");
return Array.prototype.map.call(links, function(e) {
return e.getAttribute("href");
......
......@@ -10,9 +10,7 @@
* winner is "nicolas" with 69600000 results
*/
var casper, scores, terms;
casper = require("casper").create({
var casper = require("casper").create({
verbose: true
});
......@@ -23,7 +21,7 @@ casper.fetchScore = function() {
});
};
terms = casper.cli.args;
var terms = casper.cli.args;
if (terms.length < 2) {
casper
......@@ -32,7 +30,7 @@ if (terms.length < 2) {
;
}
scores = [];
var scores = [];
casper.echo("Let the match begin between \"" + (terms.join('", "')) + "\"!");
......
......@@ -6,10 +6,8 @@
* (all arguments will be used as the query)
*/
var casper, currentPage, processPage;
casper = require("casper").create();
currentPage = 1;
var casper = require("casper").create();
var currentPage = 1;
if (casper.cli.args.length === 0) {
casper
......@@ -18,13 +16,16 @@ if (casper.cli.args.length === 0) {
;
}
processPage = function() {
var processPage = function() {
var url;
this.echo("capturing page " + currentPage);
this.capture("google-results-p" + currentPage + ".png");
// don't go too far down the rabbit hole
if (currentPage >= 5) {
return;
}
if (this.exists("#pnnext")) {
currentPage++;
this.echo("requesting next page: " + currentPage);
......@@ -35,7 +36,7 @@ processPage = function() {
}, processPage);
});
} else {
return this.echo("that's all, folks.");
this.echo("that's all, folks.");
}
};
......
var casper, metas, url;
casper = require("casper").create();
url = casper.cli.get(0);
metas = [];
var casper = require("casper").create();
var url = casper.cli.get(0);
var metas = [];
if (!url) {
casper
......
var casper, check, countLinks, currentSuite, suites;
casper = require("casper").create({
var casper = require("casper").create({
verbose: true
});
countLinks = function() {
var countLinks = function() {
return document.querySelectorAll('a').length;
};
suites = [
var suites = [
function() {
this.echo("Suite 1");
this.start("http://google.com/", function() {
......@@ -42,9 +40,9 @@ casper.then(function() {
this.echo("Starting");
});
currentSuite = 0;
var currentSuite = 0;
check = function() {
var check = function() {
if (suites[currentSuite]) {
suites[currentSuite].call(this);
currentSuite++;
......
......@@ -3,17 +3,15 @@
* Usage: $ casperjs screenshot.coffee <twitter-account> <filename.[jpg|png|pdf]>
*/
var casper, filename, twitterAccount;
casper = require("casper").create({
var casper = require("casper").create({
viewportSize: {
width: 1024,
height: 768
}
});
twitterAccount = casper.cli.get(0);
filename = casper.cli.get(1);
var twitterAccount = casper.cli.get(0);
var filename = casper.cli.get(1);
if (!twitterAccount || !filename || !/\.(png|jpg|pdf)$/i.test(filename)) {
casper
......
......@@ -18,9 +18,7 @@
* YES!
*/
var casper, timeout;
casper = require("casper").create({
var casper = require("casper").create({
onTimeout: function() {
this
.echo("NOPE.", "RED_BAR")
......@@ -29,7 +27,7 @@ casper = require("casper").create({
}
});
timeout = ~~casper.cli.get(0);
var timeout = ~~casper.cli.get(0);
if (timeout < 1) {
casper
......