Commit c269f4fd c269f4fdfd214ead647d9501cf960581cc68e1ef by Brikou CARRE

tweaked var declaration

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