diff --git a/README.md b/README.md index e61d9f7..ed8a12b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Compiled on Raspbian Hardfloat. Instruction set: __armv6__ (compatible with all raspberry pi devices) -__Note__: Due to different versions of libraries for Rasbian prior to Stretch, you'll have to use the [master branch](https://github.com/piksel/phantomjs-raspberrypi/tree/master). +__Note__: Due to different versions of libraries for Rasbian prior to Stretch, you'll have to use the [jessie branch](https://github.com/piksel/phantomjs-raspberrypi/tree/jessie). __2017-09-09__: Compiled 2.1.1 for Raspbian Stretch __2017-06-26__: Compiled the first qt5 version: 2.1.1 @@ -15,4 +15,4 @@ __Dependencies__: `libicu57`, `libssl1.0.2`, `gstreamer0.10-base`, `fontconfig`, and `freetype2` To install them: -`sudo apt install libicu57 libssl1.0.2 gstreamer0.10-base fontconfig freetype2` +`sudo apt install libicu57 libssl1.0.2 gstreamer0.10-base fontconfig freetype2` \ No newline at end of file diff --git a/examples/arguments.coffee b/examples/arguments.coffee deleted file mode 100644 index 9502439..0000000 --- a/examples/arguments.coffee +++ /dev/null @@ -1,7 +0,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 system.args - console.log i + ': ' + arg -phantom.exit() diff --git a/examples/child_process-examples.coffee b/examples/child_process-examples.coffee deleted file mode 100644 index 47e9b50..0000000 --- a/examples/child_process-examples.coffee +++ /dev/null @@ -1,20 +0,0 @@ -{spawn, execFile} = require "child_process" - -child = spawn "ls", ["-lF", "/rooot"] - -child.stdout.on "data", (data) -> - console.log "spawnSTDOUT:", JSON.stringify data - -child.stderr.on "data", (data) -> - console.log "spawnSTDERR:", JSON.stringify data - -child.on "exit", (code) -> - console.log "spawnEXIT:", code - -#child.kill "SIGKILL" - -execFile "ls", ["-lF", "/usr"], null, (err, stdout, stderr) -> - console.log "execFileSTDOUT:", JSON.stringify stdout - console.log "execFileSTDERR:", JSON.stringify stderr - -setTimeout (-> phantom.exit 0), 2000 diff --git a/examples/colorwheel.coffee b/examples/colorwheel.coffee deleted file mode 100644 index 74866e1..0000000 --- a/examples/colorwheel.coffee +++ /dev/null @@ -1,46 +0,0 @@ -page = require('webpage').create() - -page.viewportSize = { width: 400, height : 400 } -page.content = '' - -page.evaluate -> - el = document.getElementById 'surface' - context = el.getContext '2d' - width = window.innerWidth - height = window.innerHeight - cx = width / 2 - cy = height / 2 - radius = width / 2.3 - i = 0 - - el.width = width - el.height = height - imageData = context.createImageData(width, height) - pixels = imageData.data - - for y in [0...height] - for x in [0...width] - i = i + 4 - rx = x - cx - ry = y - cy - d = rx * rx + ry * ry - if d < radius * radius - hue = 6 * (Math.atan2(ry, rx) + Math.PI) / (2 * Math.PI) - sat = Math.sqrt(d) / radius - g = Math.floor(hue) - f = hue - g - u = 255 * (1 - sat) - v = 255 * (1 - sat * f) - w = 255 * (1 - sat * (1 - f)) - pixels[i] = [255, v, u, u, w, 255, 255][g] - pixels[i + 1] = [w, 255, 255, v, u, u, w][g] - pixels[i + 2] = [u, u, w, 255, 255, v, u][g] - pixels[i + 3] = 255 - - context.putImageData imageData, 0, 0 - document.body.style.backgroundColor = 'white' - document.body.style.margin = '0px' - -page.render('colorwheel.png') - -phantom.exit() diff --git a/examples/countdown.coffee b/examples/countdown.coffee deleted file mode 100644 index 821fc9f..0000000 --- a/examples/countdown.coffee +++ /dev/null @@ -1,8 +0,0 @@ -t = 10 -interval = setInterval -> - if t > 0 - console.log t-- - else - console.log 'BLAST OFF!' - phantom.exit() -, 1000 diff --git a/examples/detectsniff.coffee b/examples/detectsniff.coffee deleted file mode 100644 index b8d2719..0000000 --- a/examples/detectsniff.coffee +++ /dev/null @@ -1,42 +0,0 @@ -page = require('webpage').create() -system = require 'system' - -page.onInitialized = -> - page.evaluate -> - userAgent = window.navigator.userAgent - platform = window.navigator.platform - window.navigator = - appCodeName: 'Mozilla' - appName: 'Netscape' - cookieEnabled: false - sniffed: false - - window.navigator.__defineGetter__ 'userAgent', -> - window.navigator.sniffed = true - userAgent - - window.navigator.__defineGetter__ 'platform', -> - window.navigator.sniffed = true - platform - -if system.args.length is 1 - console.log 'Usage: detectsniff.coffee ' - phantom.exit 1 -else - address = system.args[1] - console.log 'Checking ' + address + '...' - page.open address, (status) -> - if status isnt 'success' - console.log 'FAIL to load the address' - phantom.exit() - else - window.setTimeout -> - sniffed = page.evaluate(-> - navigator.sniffed - ) - if sniffed - console.log 'The page tried to sniff the user agent.' - else - console.log 'The page did not try to sniff the user agent.' - phantom.exit() - , 1500 diff --git a/examples/direction.coffee b/examples/direction.coffee deleted file mode 100644 index 85a1cff..0000000 --- a/examples/direction.coffee +++ /dev/null @@ -1,30 +0,0 @@ -# Get driving direction using Google Directions API. - -page = require('webpage').create() -system = require 'system' - -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 = 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) -> - if status isnt 'success' - console.log 'Unable to access network' - else - steps = page.content.match(/(.*)<\/html_instructions>/ig) - if not steps - console.log 'No data available for ' + origin + ' to ' + dest - else - for ins in steps - ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>') - ins = ins.replace(/\
/g, '') - console.log(ins) - console.log '' - console.log page.content.match(/.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '') - phantom.exit() diff --git a/examples/direction.js b/examples/direction.js deleted file mode 100644 index 77044e3..0000000 --- a/examples/direction.js +++ /dev/null @@ -1,35 +0,0 @@ -// Get driving direction using Google Directions API. - -var page = require('webpage').create(), - system = require('system'), - origin, dest, steps; - -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 = 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') { - console.log('Unable to access network'); - } else { - steps = page.content.match(/(.*)<\/html_instructions>/ig); - if (steps == null) { - console.log('No data available for ' + origin + ' to ' + dest); - } else { - steps.forEach(function (ins) { - ins = ins.replace(/\</ig, '<').replace(/\>/ig, '>'); - ins = ins.replace(/\
/g, ''); - console.log(ins); - }); - console.log(''); - console.log(page.content.match(/.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '')); - } - } - phantom.exit(); - }); -} diff --git a/examples/echoToFile.coffee b/examples/echoToFile.coffee deleted file mode 100644 index e886f93..0000000 --- a/examples/echoToFile.coffee +++ /dev/null @@ -1,19 +0,0 @@ -# echoToFile.coffee - Write in a given file all the parameters passed on the CLI -fs = require 'fs' -system = require 'system' - -if system.args.length < 3 - console.log "Usage: echoToFile.coffee DESTINATION_FILE " - phantom.exit 1 -else - content = "" - f = null - i = 2 - while i < system.args.length - content += system.args[i] + (if i == system.args.length - 1 then "" else " ") - ++i - try - fs.write system.args[1], content, "w" - catch e - console.log e - phantom.exit() diff --git a/examples/features.coffee b/examples/features.coffee deleted file mode 100644 index 829beeb..0000000 --- a/examples/features.coffee +++ /dev/null @@ -1,23 +0,0 @@ -feature = undefined -supported = [] -unsupported = [] -phantom.injectJs "modernizr.js" -console.log "Detected features (using Modernizr " + Modernizr._version + "):" -for feature of Modernizr - if Modernizr.hasOwnProperty(feature) - if feature[0] isnt "_" and typeof Modernizr[feature] isnt "function" and feature isnt "input" and feature isnt "inputtypes" - if Modernizr[feature] - supported.push feature - else - unsupported.push feature -console.log "" -console.log "Supported:" -supported.forEach (e) -> - console.log " " + e - -console.log "" -console.log "Not supported:" -unsupported.forEach (e) -> - console.log " " + e - -phantom.exit() \ No newline at end of file diff --git a/examples/fibo.coffee b/examples/fibo.coffee deleted file mode 100644 index d9f9178..0000000 --- a/examples/fibo.coffee +++ /dev/null @@ -1,8 +0,0 @@ -fibs = [0, 1] -f = -> - console.log fibs[fibs.length - 1] - fibs.push fibs[fibs.length - 1] + fibs[fibs.length - 2] - if fibs.length > 10 - window.clearInterval ticker - phantom.exit() -ticker = window.setInterval(f, 300) diff --git a/examples/follow.coffee b/examples/follow.coffee deleted file mode 100644 index 4a7fbd4..0000000 --- a/examples/follow.coffee +++ /dev/null @@ -1,33 +0,0 @@ -# List following and followers from several accounts - -users = [ - 'PhantomJS' - 'ariyahidayat' - 'detronizator' - 'KDABQt' - 'lfranchi' - 'jonleighton' - '_jamesmgreene' - 'Vitalliumm' - ] - -follow = (user, callback) -> - page = require('webpage').create() - page.open 'http://mobile.twitter.com/' + user, (status) -> - if status is 'fail' - console.log user + ': ?' - else - data = page.evaluate -> document.querySelector('div.profile td.stat.stat-last div.statnum').innerText; - console.log user + ': ' + data - page.close() - callback.apply() - -process = () -> - if (users.length > 0) - user = users[0] - users.splice(0, 1) - follow(user, process) - else - phantom.exit() - -process() diff --git a/examples/follow.js b/examples/follow.js deleted file mode 100644 index 7d826f7..0000000 --- a/examples/follow.js +++ /dev/null @@ -1,38 +0,0 @@ -// List following and followers from several accounts - -var users = ['PhantomJS', - 'ariyahidayat', - 'detronizator', - 'KDABQt', - 'lfranchi', - 'jonleighton', - '_jamesmgreene', - 'Vitalliumm']; - -function follow(user, callback) { - var page = require('webpage').create(); - page.open('http://mobile.twitter.com/' + user, function (status) { - if (status === 'fail') { - console.log(user + ': ?'); - } else { - var data = page.evaluate(function () { - return document.querySelector('div.profile td.stat.stat-last div.statnum').innerText; - }); - console.log(user + ': ' + data); - } - page.close(); - callback.apply(); - }); -} - -function process() { - if (users.length > 0) { - var user = users[0]; - users.splice(0, 1); - follow(user, process); - } else { - phantom.exit(); - } -} - -process(); diff --git a/examples/hello.coffee b/examples/hello.coffee deleted file mode 100644 index 1776a06..0000000 --- a/examples/hello.coffee +++ /dev/null @@ -1,2 +0,0 @@ -console.log 'Hello, world!' -phantom.exit() diff --git a/examples/imagebin.coffee b/examples/imagebin.coffee deleted file mode 100644 index fdd8455..0000000 --- a/examples/imagebin.coffee +++ /dev/null @@ -1,20 +0,0 @@ -# Upload an image to imagebin.org - -page = require('webpage').create() -system = require 'system' - -if system.args.length isnt 2 - console.log 'Usage: imagebin.coffee filename' - phantom.exit 1 -else - fname = system.args[1] - page.open 'http://imagebin.org/index.php?page=add', -> - page.uploadFile 'input[name=image]', fname - page.evaluate -> - document.querySelector('input[name=nickname]').value = 'phantom' - document.querySelector('input[name=disclaimer_agree]').click() - document.querySelector('form').submit() - - window.setTimeout -> - phantom.exit() - , 3000 diff --git a/examples/imagebin.js b/examples/imagebin.js deleted file mode 100644 index 5446b92..0000000 --- a/examples/imagebin.js +++ /dev/null @@ -1,23 +0,0 @@ -// Upload an image to imagebin.org - -var page = require('webpage').create(), - system = require('system'), - fname; - -if (system.args.length !== 2) { - console.log('Usage: imagebin.js filename'); - phantom.exit(1); -} else { - fname = system.args[1]; - page.open("http://imagebin.org/index.php?page=add", function () { - page.uploadFile('input[name=image]', fname); - page.evaluate(function () { - document.querySelector('input[name=nickname]').value = 'phantom'; - document.querySelector('input[name=disclaimer_agree]').click() - document.querySelector('form').submit(); - }); - window.setTimeout(function () { - phantom.exit(); - }, 3000); - }); -} diff --git a/examples/injectme.coffee b/examples/injectme.coffee deleted file mode 100644 index ae4927d..0000000 --- a/examples/injectme.coffee +++ /dev/null @@ -1,23 +0,0 @@ -# Use 'page.injectJs()' to load the script itself in the Page context - -if phantom? - page = require('webpage').create() - - # Route "console.log()" calls from within the Page context to the main - # Phantom context (i.e. current "this") - page.onConsoleMessage = (msg) -> console.log(msg) - - page.onAlert = (msg) -> console.log(msg) - - console.log "* Script running in the Phantom context." - console.log "* Script will 'inject' itself in a page..." - page.open "about:blank", (status) -> - if status is "success" - if page.injectJs("injectme.coffee") - console.log "... done injecting itself!" - else - console.log "... fail! Check the $PWD?!" - phantom.exit() -else - alert "* Script running in the Page context." - diff --git a/examples/ipgeocode.coffee b/examples/ipgeocode.coffee deleted file mode 100644 index d36d6aa..0000000 --- a/examples/ipgeocode.coffee +++ /dev/null @@ -1,13 +0,0 @@ -# Give the estimated location based on the IP address. - -window.cb = (data) -> - loc = data.city - if data.region_name.length > 0 - loc = loc + ', ' + data.region_name - console.log 'IP address: ' + data.ip - console.log 'Estimated location: ' + loc - phantom.exit() - -el = document.createElement 'script' -el.src = 'http://freegeoip.net/json/?callback=window.cb' -document.body.appendChild el diff --git a/examples/ipgeocode.js b/examples/ipgeocode.js deleted file mode 100644 index aff5a20..0000000 --- a/examples/ipgeocode.js +++ /dev/null @@ -1,14 +0,0 @@ -// Give the estimated location based on the IP address. - -cb = function (data) { - var loc = data.city; - if (data.region_name.length > 0) - loc = loc + ', ' + data.region_name; - console.log('IP address: ' + data.ip); - console.log('Estimated location: ' + loc); - phantom.exit(); -}; - -var el = document.createElement('script'); -el.src = 'http://freegeoip.net/json/?callback=cb'; -document.body.appendChild(el); diff --git a/examples/loadspeed.coffee b/examples/loadspeed.coffee deleted file mode 100644 index a4c6aa7..0000000 --- a/examples/loadspeed.coffee +++ /dev/null @@ -1,18 +0,0 @@ -page = require('webpage').create() -system = require 'system' - -if system.args.length is 1 - console.log 'Usage: loadspeed.coffee ' - phantom.exit 1 -else - t = Date.now() - address = system.args[1] - page.open address, (status) -> - if status isnt 'success' - console.log('FAIL to load the address') - else - t = Date.now() - t - console.log('Page title is ' + page.evaluate( (-> document.title) )) - console.log('Loading time ' + t + ' msec') - phantom.exit() - diff --git a/examples/loadurlwithoutcss.coffee b/examples/loadurlwithoutcss.coffee deleted file mode 100644 index 36143c8..0000000 --- a/examples/loadurlwithoutcss.coffee +++ /dev/null @@ -1,20 +0,0 @@ -page = require("webpage").create() -system = require("system") - -if system.args.length < 2 - console.log "Usage: loadurlwithoutcss.js URL" - phantom.exit() - -address = system.args[1] - -page.onResourceRequested = (requestData, request) -> - if (/http:\/\/.+?\.css/g).test(requestData["url"]) or requestData["Content-Type"] is "text/css" - console.log "The url of the request is matching. Aborting: " + requestData["url"] - request.abort() - -page.open address, (status) -> - if status is "success" - phantom.exit() - else - console.log "Unable to load the address!" - phantom.exit() diff --git a/examples/module.coffee b/examples/module.coffee deleted file mode 100644 index 5278b51..0000000 --- a/examples/module.coffee +++ /dev/null @@ -1,4 +0,0 @@ -universe = require './universe' -universe.start() -console.log 'The answer is' + universe.answer -phantom.exit() diff --git a/examples/movies.coffee b/examples/movies.coffee deleted file mode 100644 index 86fb5b0..0000000 --- a/examples/movies.coffee +++ /dev/null @@ -1,13 +0,0 @@ -# List movies from kids-in-mind.com - -window.cbfunc = (data) -> - globaldata = data - list = data.query.results.movie - for item in list - console.log item.title + ' [' + item.rating.MPAA.content + ']' - phantom.exit() - -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=window.cbfunc" -document.body.appendChild el diff --git a/examples/movies.js b/examples/movies.js deleted file mode 100644 index 73c61a7..0000000 --- a/examples/movies.js +++ /dev/null @@ -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); diff --git a/examples/netlog.coffee b/examples/netlog.coffee deleted file mode 100644 index d6e5c35..0000000 --- a/examples/netlog.coffee +++ /dev/null @@ -1,18 +0,0 @@ -page = require('webpage').create() -system = require 'system' - -if system.args.length is 1 - console.log 'Usage: netlog.coffee ' - phantom.exit 1 -else - address = system.args[1] - page.onResourceRequested = (req) -> - console.log 'requested ' + JSON.stringify(req, undefined, 4) - - page.onResourceReceived = (res) -> - console.log 'received ' + JSON.stringify(res, undefined, 4) - - page.open address, (status) -> - if status isnt 'success' - console.log 'FAIL to load the address' - phantom.exit() diff --git a/examples/netsniff.coffee b/examples/netsniff.coffee deleted file mode 100644 index 092f2d2..0000000 --- a/examples/netsniff.coffee +++ /dev/null @@ -1,114 +0,0 @@ -if not Date::toISOString - Date::toISOString = -> - pad = (n) -> - if n < 10 then '0' + n else n - ms = (n) -> - if n < 10 then '00' + n else (if n < 100 then '0' + n else n) - @getFullYear() + '-' + - pad(@getMonth() + 1) + '-' + - pad(@getDate()) + 'T' + - pad(@getHours()) + ':' + - pad(@getMinutes()) + ':' + - pad(@getSeconds()) + '.' + - ms(@getMilliseconds()) + 'Z' - -createHAR = (address, title, startTime, resources) -> - entries = [] - - resources.forEach (resource) -> - request = resource.request - startReply = resource.startReply - endReply = resource.endReply - - if not request or not startReply or not endReply - return - - entries.push - startedDateTime: request.time.toISOString() - time: endReply.time - request.time - request: - method: request.method - url: request.url - httpVersion: 'HTTP/1.1' - cookies: [] - headers: request.headers - queryString: [] - headersSize: -1 - bodySize: -1 - - response: - status: endReply.status - statusText: endReply.statusText - httpVersion: 'HTTP/1.1' - cookies: [] - headers: endReply.headers - redirectURL: '' - headersSize: -1 - bodySize: startReply.bodySize - content: - size: startReply.bodySize - mimeType: endReply.contentType - - cache: {} - timings: - blocked: 0 - dns: -1 - connect: -1 - send: 0 - wait: startReply.time - request.time - receive: endReply.time - startReply.time - ssl: -1 - pageref: address - - log: - version: '1.2' - creator: - name: 'PhantomJS' - version: phantom.version.major + '.' + phantom.version.minor + '.' + phantom.version.patch - - pages: [ - startedDateTime: startTime.toISOString() - id: address - title: title - pageTimings: - onLoad: page.endTime - page.startTime - ] - entries: entries - -page = require('webpage').create() -system = require 'system' - -if system.args.length is 1 - console.log 'Usage: netsniff.coffee ' - phantom.exit 1 -else - page.address = system.args[1] - page.resources = [] - - page.onLoadStarted = -> - page.startTime = new Date() - - page.onResourceRequested = (req) -> - page.resources[req.id] = - request: req - startReply: null - endReply: null - - page.onResourceReceived = (res) -> - if res.stage is 'start' - page.resources[res.id].startReply = res - if res.stage is 'end' - page.resources[res.id].endReply = res - - page.open page.address, (status) -> - if status isnt 'success' - console.log 'FAIL to load the address' - phantom.exit(1) - else - page.endTime = new Date() - page.title = page.evaluate -> - document.title - - har = createHAR page.address, page.title, page.startTime, page.resources - console.log JSON.stringify har, undefined, 4 - phantom.exit() diff --git a/examples/outputEncoding.coffee b/examples/outputEncoding.coffee deleted file mode 100644 index 9d212ca..0000000 --- a/examples/outputEncoding.coffee +++ /dev/null @@ -1,12 +0,0 @@ -helloWorld = () -> console.log phantom.outputEncoding + ": こんにちは、世界!" - -console.log "Using default encoding..." -helloWorld() - -console.log "\nUsing other encodings..." -for enc in ["euc-jp", "sjis", "utf8", "System"] - do (enc) -> - phantom.outputEncoding = enc - helloWorld() - -phantom.exit() diff --git a/examples/page_events.coffee b/examples/page_events.coffee deleted file mode 100644 index 87e433b..0000000 --- a/examples/page_events.coffee +++ /dev/null @@ -1,132 +0,0 @@ -# The purpose of this is to show how and when events fire, considering 5 steps -# happening as follows: -# -# 1. Load URL -# 2. Load same URL, but adding an internal FRAGMENT to it -# 3. Click on an internal Link, that points to another internal FRAGMENT -# 4. Click on an external Link, that will send the page somewhere else -# 5. Close page -# -# Take particular care when going through the output, to understand when -# things happen (and in which order). Particularly, notice what DOESN'T -# happen during step 3. -# -# If invoked with "-v" it will print out the Page Resources as they are -# Requested and Received. -# -# NOTE.1: The "onConsoleMessage/onAlert/onPrompt/onConfirm" events are -# registered but not used here. This is left for you to have fun with. -# 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. -printArgs = -> - i = undefined - ilen = undefined - i = 0 - ilen = arguments_.length - - while i < ilen - console.log " arguments[" + i + "] = " + JSON.stringify(arguments_[i]) - ++i - console.log "" -sys = require("system") -page = require("webpage").create() -logResources = false -step1url = "http://en.wikipedia.org/wiki/DOM_events" -step2url = "http://en.wikipedia.org/wiki/DOM_events#Event_flow" -logResources = true if sys.args.length > 1 and sys.args[1] is "-v" - -#////////////////////////////////////////////////////////////////////////////// -page.onInitialized = -> - console.log "page.onInitialized" - printArgs.apply this, arguments_ - -page.onLoadStarted = -> - console.log "page.onLoadStarted" - printArgs.apply this, arguments_ - -page.onLoadFinished = -> - console.log "page.onLoadFinished" - printArgs.apply this, arguments_ - -page.onUrlChanged = -> - console.log "page.onUrlChanged" - printArgs.apply this, arguments_ - -page.onNavigationRequested = -> - console.log "page.onNavigationRequested" - printArgs.apply this, arguments_ - -if logResources is true - page.onResourceRequested = -> - console.log "page.onResourceRequested" - printArgs.apply this, arguments_ - - page.onResourceReceived = -> - console.log "page.onResourceReceived" - printArgs.apply this, arguments_ -page.onClosing = -> - console.log "page.onClosing" - printArgs.apply this, arguments_ - - -# window.console.log(msg); -page.onConsoleMessage = -> - console.log "page.onConsoleMessage" - printArgs.apply this, arguments_ - - -# window.alert(msg); -page.onAlert = -> - console.log "page.onAlert" - printArgs.apply this, arguments_ - - -# var confirmed = window.confirm(msg); -page.onConfirm = -> - console.log "page.onConfirm" - printArgs.apply this, arguments_ - - -# var user_value = window.prompt(msg, default_value); -page.onPrompt = -> - console.log "page.onPrompt" - printArgs.apply this, arguments_ - - -#////////////////////////////////////////////////////////////////////////////// -setTimeout (-> - console.log "" - console.log "### STEP 1: Load '" + step1url + "'" - page.open step1url -), 0 -setTimeout (-> - console.log "" - console.log "### STEP 2: Load '" + step2url + "' (load same URL plus FRAGMENT)" - page.open step2url -), 5000 -setTimeout (-> - console.log "" - console.log "### STEP 3: Click on page internal link (aka FRAGMENT)" - page.evaluate -> - ev = document.createEvent("MouseEvents") - ev.initEvent "click", true, true - document.querySelector("a[href='#Event_object']").dispatchEvent ev - -), 10000 -setTimeout (-> - console.log "" - console.log "### STEP 4: Click on page external link" - page.evaluate -> - ev = document.createEvent("MouseEvents") - ev.initEvent "click", true, true - document.querySelector("a[title='JavaScript']").dispatchEvent ev - -), 15000 -setTimeout (-> - console.log "" - console.log "### STEP 5: Close page and shutdown (with a delay)" - page.close() - setTimeout (-> - phantom.exit() - ), 100 -), 20000 \ No newline at end of file diff --git a/examples/pagecallback.coffee b/examples/pagecallback.coffee deleted file mode 100644 index 1af7a79..0000000 --- a/examples/pagecallback.coffee +++ /dev/null @@ -1,16 +0,0 @@ -p = require("webpage").create() - -p.onConsoleMessage = (msg) -> - console.log msg - -# Calls to "callPhantom" within the page 'p' arrive here -p.onCallback = (msg) -> - console.log "Received by the 'phantom' main context: " + msg - "Hello there, I'm coming to you from the 'phantom' context instead" - -p.evaluate -> - # Return-value of the "onCallback" handler arrive here - callbackResponse = window.callPhantom "Hello, I'm coming to you from the 'page' context" - console.log "Received by the 'page' context: " + callbackResponse - -phantom.exit() diff --git a/examples/phantomwebintro.coffee b/examples/phantomwebintro.coffee deleted file mode 100644 index 0c89ca7..0000000 --- a/examples/phantomwebintro.coffee +++ /dev/null @@ -1,13 +0,0 @@ -# Read the Phantom webpage '#intro' element text using jQuery and "includeJs" - -page = require('webpage').create() - -page.onConsoleMessage = (msg) -> console.log msg - -page.open "http://www.phantomjs.org", (status) -> - if status is "success" - page.includeJs "http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", -> - page.evaluate -> - console.log "$(\"#intro\").text() -> " + $("#intro").text() - phantom.exit() - diff --git a/examples/pizza.coffee b/examples/pizza.coffee deleted file mode 100644 index 6e97db7..0000000 --- a/examples/pizza.coffee +++ /dev/null @@ -1,18 +0,0 @@ -# Find pizza in Mountain View using Yelp - -page = require('webpage').create() -url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search' - -page.open url, - (status) -> - if status isnt 'success' - console.log 'Unable to access network' - else - results = page.evaluate -> - pizza = [] - list = document.querySelectorAll 'address' - for item in list - pizza.push(item.innerText) - return pizza - console.log results.join('\n') - phantom.exit() diff --git a/examples/pizza.js b/examples/pizza.js deleted file mode 100644 index 3e1af15..0000000 --- a/examples/pizza.js +++ /dev/null @@ -1,20 +0,0 @@ -// Find pizza in Mountain View using Yelp - -var page = require('webpage').create(), - url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search'; - -page.open(url, function (status) { - if (status !== 'success') { - console.log('Unable to access network'); - } else { - var results = page.evaluate(function() { - var list = document.querySelectorAll('address'), pizza = [], i; - for (i = 0; i < list.length; i++) { - pizza.push(list[i].innerText); - } - return pizza; - }); - console.log(results.join('\n')); - } - phantom.exit(); -}); diff --git a/examples/post.coffee b/examples/post.coffee deleted file mode 100644 index c3c5787..0000000 --- a/examples/post.coffee +++ /dev/null @@ -1,12 +0,0 @@ -# Example using HTTP POST operation - -page = require('webpage').create() -server = 'http://posttestserver.com/post.php?dump' -data = 'universe=expanding&answer=42' - -page.open server, 'post', data, (status) -> - if status isnt 'success' - console.log 'Unable to post!' - else - console.log page.content - phantom.exit() diff --git a/examples/postserver.coffee b/examples/postserver.coffee deleted file mode 100644 index 2dcd507..0000000 --- a/examples/postserver.coffee +++ /dev/null @@ -1,25 +0,0 @@ -# Example using HTTP POST operation -page = require("webpage").create() -server = require("webserver").create() -system = require("system") -data = "universe=expanding&answer=42" -if system.args.length isnt 2 - console.log "Usage: postserver.js " - phantom.exit 1 -port = system.args[1] -service = server.listen(port, (request, response) -> - console.log "Request received at " + new Date() - response.statusCode = 200 - response.headers = - Cache: "no-cache" - "Content-Type": "text/plain;charset=utf-8" - - response.write JSON.stringify(request, null, 4) - response.close() -) -page.open "http://localhost:" + port + "/", "post", data, (status) -> - if status isnt "success" - console.log "Unable to post!" - else - console.log page.plainText - phantom.exit() diff --git a/examples/printenv.coffee b/examples/printenv.coffee deleted file mode 100644 index 80ec5f0..0000000 --- a/examples/printenv.coffee +++ /dev/null @@ -1,6 +0,0 @@ -system = require("system") -env = system.env -key = undefined -for key of env - console.log key + "=" + env[key] if env.hasOwnProperty(key) -phantom.exit() \ No newline at end of file diff --git a/examples/printheaderfooter.coffee b/examples/printheaderfooter.coffee deleted file mode 100644 index fd82b34..0000000 --- a/examples/printheaderfooter.coffee +++ /dev/null @@ -1,88 +0,0 @@ -someCallback = (pageNum, numPages) -> - "

someCallback: " + pageNum + " / " + numPages + "

" -page = require("webpage").create() -system = require("system") -if system.args.length < 3 - console.log "Usage: printheaderfooter.js URL filename" - phantom.exit 1 -else - address = system.args[1] - output = system.args[2] - page.viewportSize = - width: 600 - height: 600 - - page.paperSize = - format: "A4" - margin: "1cm" - - # default header/footer for pages that don't have custom overwrites (see below) - header: - height: "1cm" - contents: phantom.callback((pageNum, numPages) -> - return "" if pageNum is 1 - "

Header " + pageNum + " / " + numPages + "

" - ) - - footer: - height: "1cm" - contents: phantom.callback((pageNum, numPages) -> - return "" if pageNum is numPages - "

Footer " + pageNum + " / " + numPages + "

" - ) - - page.open address, (status) -> - if status isnt "success" - console.log "Unable to load the address!" - else - - # check whether the loaded page overwrites the header/footer setting, - # i.e. whether a PhantomJSPriting object exists. Use that then instead - # of our defaults above. - # - # example: - # - # - # - # - #

asdfadsf

asdfadsfycvx

- # - # - if page.evaluate(-> - typeof PhantomJSPrinting is "object" - ) - paperSize = page.paperSize - paperSize.header.height = page.evaluate(-> - PhantomJSPrinting.header.height - ) - paperSize.header.contents = phantom.callback((pageNum, numPages) -> - page.evaluate ((pageNum, numPages) -> - PhantomJSPrinting.header.contents pageNum, numPages - ), pageNum, numPages - ) - paperSize.footer.height = page.evaluate(-> - PhantomJSPrinting.footer.height - ) - paperSize.footer.contents = phantom.callback((pageNum, numPages) -> - page.evaluate ((pageNum, numPages) -> - PhantomJSPrinting.footer.contents pageNum, numPages - ), pageNum, numPages - ) - page.paperSize = paperSize - console.log page.paperSize.header.height - console.log page.paperSize.footer.height - window.setTimeout (-> - page.render output - phantom.exit() - ), 200 diff --git a/examples/printmargins.coffee b/examples/printmargins.coffee deleted file mode 100644 index 5be7ced..0000000 --- a/examples/printmargins.coffee +++ /dev/null @@ -1,33 +0,0 @@ -page = require("webpage").create() -system = require("system") -if system.args.length < 7 - console.log "Usage: printmargins.js URL filename LEFT TOP RIGHT BOTTOM" - console.log " margin examples: \"1cm\", \"10px\", \"7mm\", \"5in\"" - phantom.exit 1 -else - address = system.args[1] - output = system.args[2] - marginLeft = system.args[3] - marginTop = system.args[4] - marginRight = system.args[5] - marginBottom = system.args[6] - page.viewportSize = - width: 600 - height: 600 - - page.paperSize = - format: "A4" - margin: - left: marginLeft - top: marginTop - right: marginRight - bottom: marginBottom - - page.open address, (status) -> - if status isnt "success" - console.log "Unable to load the address!" - else - window.setTimeout (-> - page.render output - phantom.exit() - ), 200 diff --git a/examples/rasterize.coffee b/examples/rasterize.coffee deleted file mode 100644 index aa06dbd..0000000 --- a/examples/rasterize.coffee +++ /dev/null @@ -1,23 +0,0 @@ -page = require('webpage').create() -system = require 'system' - -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 1 -else - address = system.args[1] - output = system.args[2] - page.viewportSize = { width: 600, height: 600 } - 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: system.args[3], orientation: 'portrait', border: '1cm' } - page.open address, (status) -> - if status isnt 'success' - console.log 'Unable to load the address!' - phantom.exit() - else - window.setTimeout (-> page.render output; phantom.exit()), 200 diff --git a/examples/render_multi_url.coffee b/examples/render_multi_url.coffee deleted file mode 100644 index 29afa48..0000000 --- a/examples/render_multi_url.coffee +++ /dev/null @@ -1,60 +0,0 @@ -# Render Multiple URLs to file - -system = require("system") - -# Render given urls -# @param array of URLs to render -# @param callbackPerUrl Function called after finishing each URL, including the last URL -# @param callbackFinal Function called after finishing everything -RenderUrlsToFile = (urls, callbackPerUrl, callbackFinal) -> - urlIndex = 0 # only for easy file naming - webpage = require("webpage") - page = null - getFilename = -> - "rendermulti-" + urlIndex + ".png" - - next = (status, url, file) -> - page.close() - callbackPerUrl status, url, file - retrieve() - - retrieve = -> - if urls.length > 0 - url = urls.shift() - urlIndex++ - page = webpage.create() - page.viewportSize = - width: 800 - height: 600 - - page.settings.userAgent = "Phantom.js bot" - page.open "http://" + url, (status) -> - file = getFilename() - if status is "success" - window.setTimeout (-> - page.render file - next status, url, file - ), 200 - else - next status, url, file - - else - callbackFinal() - - retrieve() -arrayOfUrls = null -if system.args.length > 1 - arrayOfUrls = Array::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"] - -RenderUrlsToFile arrayOfUrls, ((status, url, file) -> - if status isnt "success" - console.log "Unable to render '" + url + "'" - else - console.log "Rendered '" + url + "' at '" + file + "'" -), -> - phantom.exit() - diff --git a/examples/run-jasmine.coffee b/examples/run-jasmine.coffee deleted file mode 100644 index 22fb932..0000000 --- a/examples/run-jasmine.coffee +++ /dev/null @@ -1,61 +0,0 @@ -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. -# -# @param testFx javascript condition that evaluates to a boolean, -# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or -# as a callback function. -# @param onReady what to do when testFx condition is fulfilled, -# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or -# as a callback function. -# @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used. -## -waitFor = (testFx, onReady, timeOutMillis=3000) -> - start = new Date().getTime() - condition = false - f = -> - if (new Date().getTime() - start < timeOutMillis) and not condition - # If not time-out yet and condition not yet fulfilled - condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code - else - if not condition - # If condition still not fulfilled (timeout but condition is 'false') - console.log "'waitFor()' timeout" - phantom.exit 1 - else - # Condition fulfilled (timeout and/or condition is 'true') - console.log "'waitFor()' finished in #{new Date().getTime() - start}ms." - if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled - clearInterval interval #< Stop this interval - interval = setInterval f, 100 #< repeat check every 100ms - -if system.args.length isnt 2 - console.log 'Usage: run-jasmine.coffee URL' - phantom.exit 1 - -page = require('webpage').create() - -# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") -page.onConsoleMessage = (msg) -> - console.log msg - -page.open system.args[1], (status) -> - if status isnt 'success' - console.log 'Unable to access network' - phantom.exit() - else - waitFor -> - page.evaluate -> - if document.body.querySelector '.finished-at' - return true - return false - , -> - page.evaluate -> - console.log document.body.querySelector('.description').innerText - list = document.body.querySelectorAll('.failed > .description, .failed > .messages > .resultMessage') - for el in list - console.log el.innerText - - phantom.exit() diff --git a/examples/run-qunit.coffee b/examples/run-qunit.coffee deleted file mode 100644 index dcb24b9..0000000 --- a/examples/run-qunit.coffee +++ /dev/null @@ -1,64 +0,0 @@ -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. -# -# @param testFx javascript condition that evaluates to a boolean, -# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or -# as a callback function. -# @param onReady what to do when testFx condition is fulfilled, -# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or -# as a callback function. -# @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used. -## -waitFor = (testFx, onReady, timeOutMillis=3000) -> - start = new Date().getTime() - condition = false - f = -> - if (new Date().getTime() - start < timeOutMillis) and not condition - # If not time-out yet and condition not yet fulfilled - condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code - else - if not condition - # If condition still not fulfilled (timeout but condition is 'false') - console.log "'waitFor()' timeout" - phantom.exit 1 - else - # Condition fulfilled (timeout and/or condition is 'true') - console.log "'waitFor()' finished in #{new Date().getTime() - start}ms." - if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled - clearInterval interval #< Stop this interval - interval = setInterval f, 100 #< repeat check every 100ms - -if system.args.length isnt 2 - console.log 'Usage: run-qunit.coffee URL' - phantom.exit 1 - -page = require('webpage').create() - -# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") -page.onConsoleMessage = (msg) -> - console.log msg - -page.open system.args[1], (status) -> - if status isnt 'success' - console.log 'Unable to access network' - phantom.exit 1 - else - waitFor -> - page.evaluate -> - el = document.getElementById 'qunit-testresult' - if el and el.innerText.match 'completed' - return true - return false - , -> - failedNum = page.evaluate -> - el = document.getElementById 'qunit-testresult' - console.log el.innerText - try - return el.getElementsByClassName('failed')[0].innerHTML - catch e - return 10000 - - phantom.exit if parseInt(failedNum, 10) > 0 then 1 else 0 diff --git a/examples/scandir.coffee b/examples/scandir.coffee deleted file mode 100644 index 0ee4ffc..0000000 --- a/examples/scandir.coffee +++ /dev/null @@ -1,16 +0,0 @@ -# List all the files in a Tree of Directories -system = require 'system' - -if system.args.length != 2 - console.log "Usage: phantomjs scandir.coffee DIRECTORY_TO_SCAN" - phantom.exit 1 -scanDirectory = (path) -> - fs = require 'fs' - if fs.exists(path) and fs.isFile(path) - console.log path - else if fs.isDirectory(path) - fs.list(path).forEach (e) -> - scanDirectory path + "/" + e if e != "." and e != ".." - -scanDirectory system.args[1] -phantom.exit() diff --git a/examples/seasonfood.coffee b/examples/seasonfood.coffee deleted file mode 100644 index 5228c26..0000000 --- a/examples/seasonfood.coffee +++ /dev/null @@ -1,17 +0,0 @@ -# Show BBC seasonal food list. - -window.cbfunc = (data) -> - list = data.query.results.results.result - names = ['January', 'February', 'March', - 'April', 'May', 'June', - 'July', 'August', 'September', - 'October', 'November', 'December'] - for item in list - console.log [item.name.replace(/\s/ig, ' '), ':', - names[item.atItsBestUntil], 'to', - names[item.atItsBestFrom]].join(' ') - phantom.exit() - -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=window.cbfunc' -document.body.appendChild el diff --git a/examples/seasonfood.js b/examples/seasonfood.js deleted file mode 100644 index f827d46..0000000 --- a/examples/seasonfood.js +++ /dev/null @@ -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); diff --git a/examples/server.coffee b/examples/server.coffee deleted file mode 100644 index 96abdb9..0000000 --- a/examples/server.coffee +++ /dev/null @@ -1,45 +0,0 @@ -page = require("webpage").create() -server = require("webserver").create() -system = require("system") -host = undefined -port = undefined -if system.args.length isnt 2 - console.log "Usage: server.js " - phantom.exit 1 -else - port = system.args[1] - listening = server.listen(port, (request, response) -> - console.log "GOT HTTP REQUEST" - console.log JSON.stringify(request, null, 4) - - # we set the headers here - response.statusCode = 200 - response.headers = - Cache: "no-cache" - "Content-Type": "text/html" - - - # this is also possible: - response.setHeader "foo", "bar" - - # now we write the body - # note: the headers above will now be sent implictly - response.write "YES!" - - # note: writeBody can be called multiple times - response.write "

pretty cool :)" - response.close() - ) - unless listening - console.log "could not create web server listening on port " + port - phantom.exit() - url = "http://localhost:" + port + "/foo/bar.php?asdf=true" - console.log "SENDING REQUEST TO:" - console.log url - page.open url, (status) -> - if status isnt "success" - console.log "FAIL to load the address" - else - console.log "GOT REPLY FROM SERVER:" - console.log page.content - phantom.exit() diff --git a/examples/serverkeepalive.coffee b/examples/serverkeepalive.coffee deleted file mode 100644 index ed33224..0000000 --- a/examples/serverkeepalive.coffee +++ /dev/null @@ -1,32 +0,0 @@ -port = undefined -server = undefined -service = undefined -system = require("system") -if system.args.length isnt 2 - console.log "Usage: serverkeepalive.js " - phantom.exit 1 -else - port = system.args[1] - server = require("webserver").create() - service = server.listen(port, - keepAlive: true - , (request, response) -> - console.log "Request at " + new Date() - console.log JSON.stringify(request, null, 4) - body = JSON.stringify(request, null, 4) - response.statusCode = 200 - response.headers = - Cache: "no-cache" - "Content-Type": "text/plain" - Connection: "Keep-Alive" - "Keep-Alive": "timeout=5, max=100" - "Content-Length": body.length - - response.write body - response.close() - ) - if service - console.log "Web server running on port " + port - else - console.log "Error: Could not create web server listening on port " + port - phantom.exit() \ No newline at end of file diff --git a/examples/simpleserver.coffee b/examples/simpleserver.coffee deleted file mode 100644 index 9b4cf7a..0000000 --- a/examples/simpleserver.coffee +++ /dev/null @@ -1,38 +0,0 @@ -system = require 'system' - -if system.args.length is 1 - console.log "Usage: simpleserver.coffee " - phantom.exit 1 -else - port = system.args[1] - server = require("webserver").create() - - service = server.listen(port, (request, response) -> - - console.log "Request at " + new Date() - console.log JSON.stringify(request, null, 4) - - response.statusCode = 200 - response.headers = - Cache: "no-cache" - "Content-Type": "text/html" - - response.write "" - response.write "" - response.write "Hello, world!" - response.write "" - response.write "" - response.write "

This is from PhantomJS web server.

" - response.write "

Request data:

" - response.write "
"
-    response.write JSON.stringify(request, null, 4)
-    response.write "
" - response.write "" - response.write "" - response.close() - ) - if service - console.log "Web server running on port " + port - else - console.log "Error: Could not create web server listening on port " + port - phantom.exit() diff --git a/examples/sleepsort.coffee b/examples/sleepsort.coffee deleted file mode 100644 index 863ad14..0000000 --- a/examples/sleepsort.coffee +++ /dev/null @@ -1,20 +0,0 @@ -### -Sort integers from the command line in a very ridiculous way: leveraging timeouts :P -### - -system = require 'system' - -if system.args.length < 2 - console.log "Usage: phantomjs sleepsort.coffee PUT YOUR INTEGERS HERE SEPARATED BY SPACES" - phantom.exit 1 -else - sortedCount = 0 - args = Array.prototype.slice.call(system.args, 1) - for int in args - setTimeout (do (int) -> - -> - console.log int - ++sortedCount - phantom.exit() if sortedCount is args.length), - int - diff --git a/examples/stdin-stdout-stderr.coffee b/examples/stdin-stdout-stderr.coffee deleted file mode 100644 index 60723e0..0000000 --- a/examples/stdin-stdout-stderr.coffee +++ /dev/null @@ -1,18 +0,0 @@ -system = require 'system' - -system.stdout.write 'Hello, system.stdout.write!' -system.stdout.writeLine '\nHello, system.stdout.writeLine!' - -system.stderr.write 'Hello, system.stderr.write!' -system.stderr.writeLine '\nHello, system.stderr.writeLine!' - -system.stdout.writeLine 'system.stdin.readLine(): ' -line = system.stdin.readLine() -system.stdout.writeLine JSON.stringify line - -# This is essentially a `readAll` -system.stdout.writeLine 'system.stdin.read(5): (ctrl+D to end)' -input = system.stdin.read 5 -system.stdout.writeLine JSON.stringify input - -phantom.exit 0 diff --git a/examples/technews.coffee b/examples/technews.coffee deleted file mode 100644 index 7a9807e..0000000 --- a/examples/technews.coffee +++ /dev/null @@ -1,17 +0,0 @@ -page = require('webpage').create() - -page.viewportSize = { width: 320, height: 480 } - -page.open 'http://news.google.com/news/i/section?&topic=t', - (status) -> - if status isnt 'success' - console.log 'Unable to access the network!' - else - page.evaluate -> - body = document.body - body.style.backgroundColor = '#fff' - body.querySelector('div#title-block').style.display = 'none' - body.querySelector('form#edition-picker-form') - .parentElement.parentElement.style.display = 'none' - page.render 'technews.png' - phantom.exit() diff --git a/examples/technews.js b/examples/technews.js deleted file mode 100644 index ba7cd94..0000000 --- a/examples/technews.js +++ /dev/null @@ -1,16 +0,0 @@ -var page = require('webpage').create(); -page.viewportSize = { width: 320, height: 480 }; -page.open('http://news.google.com/news/i/section?&topic=t', function (status) { - if (status !== 'success') { - console.log('Unable to access the network!'); - } else { - page.evaluate(function () { - var body = document.body; - body.style.backgroundColor = '#fff'; - body.querySelector('div#title-block').style.display = 'none'; - body.querySelector('form#edition-picker-form').parentElement.parentElement.style.display = 'none'; - }); - page.render('technews.png'); - } - phantom.exit(); -}); diff --git a/examples/tweets.coffee b/examples/tweets.coffee deleted file mode 100644 index a6c064c..0000000 --- a/examples/tweets.coffee +++ /dev/null @@ -1,31 +0,0 @@ -# Get twitter status for given account (or for the default one, "PhantomJS") - -page = require('webpage').create() -system = require 'system' -twitterId = 'PhantomJS' #< 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 system.args.length < 2 - console.log 'Usage: tweets.coffee [twitter ID]' -else - twitterId = system.args[1] - -# Heading -console.log "*** Latest tweets from @#{twitterId} ***\n" - -# Open Twitter Mobile and, onPageLoad, do... -page.open encodeURI("http://mobile.twitter.com/#{twitterId}"), (status) -> - # Check for page load success - if status isnt 'success' - console.log 'Unable to access network' - else - # Execute some DOM inspection within the page context - page.evaluate -> - list = document.querySelectorAll 'div.tweet-text' - for i, j in list - console.log "#{j + 1}: #{i.innerText}" - phantom.exit() diff --git a/examples/tweets.js b/examples/tweets.js deleted file mode 100644 index d3f18c5..0000000 --- a/examples/tweets.js +++ /dev/null @@ -1,37 +0,0 @@ -// Get twitter status for given account (or for the default one, "PhantomJS") - -var page = require('webpage').create(), - system = require('system'), - twitterId = "PhantomJS"; //< default value - -// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") -page.onConsoleMessage = function(msg) { - console.log(msg); -}; - -// Print usage message, if no twitter ID is passed -if (system.args.length < 2) { - console.log("Usage: tweets.js [twitter ID]"); -} else { - twitterId = system.args[1]; -} - -// Heading -console.log("*** Latest tweets from @" + twitterId + " ***\n"); - -// Open Twitter Mobile and, onPageLoad, do... -page.open(encodeURI("http://mobile.twitter.com/" + twitterId), function (status) { - // Check for page load success - if (status !== "success") { - console.log("Unable to access network"); - } else { - // Execute some DOM inspection within the page context - page.evaluate(function() { - var list = document.querySelectorAll('div.tweet-text'); - for (var i = 0; i < list.length; ++i) { - console.log((i + 1) + ": " + list[i].innerText); - } - }); - } - phantom.exit(); -}); diff --git a/examples/unrandomize.coffee b/examples/unrandomize.coffee deleted file mode 100644 index 841ffc7..0000000 --- a/examples/unrandomize.coffee +++ /dev/null @@ -1,18 +0,0 @@ -# Modify global object at the page initialization. -# In this example, effectively Math.random() always returns 0.42. - -page = require('webpage').create() -page.onInitialized = -> - page.evaluate -> - Math.random = -> - 42 / 100 - -page.open "http://ariya.github.com/js/random/", (status) -> - if status != "success" - console.log "Network error." - else - console.log page.evaluate(-> - document.getElementById("numbers").textContent - ) - phantom.exit() - diff --git a/examples/useragent.coffee b/examples/useragent.coffee deleted file mode 100644 index d401c7f..0000000 --- a/examples/useragent.coffee +++ /dev/null @@ -1,11 +0,0 @@ -page = require('webpage').create() - -console.log 'The default user agent is ' + page.settings.userAgent - -page.settings.userAgent = 'SpecialAgent' -page.open 'http://www.httpuseragent.org', (status) -> - if status isnt 'success' - console.log 'Unable to access network' - else - console.log page.evaluate -> document.getElementById('myagent').innerText - phantom.exit() diff --git a/examples/version.coffee b/examples/version.coffee deleted file mode 100644 index ce20269..0000000 --- a/examples/version.coffee +++ /dev/null @@ -1,5 +0,0 @@ -console.log 'using PhantomJS version ' + - phantom.version.major + '.' + - phantom.version.minor + '.' + - phantom.version.patch -phantom.exit() diff --git a/examples/waitfor.coffee b/examples/waitfor.coffee deleted file mode 100644 index 90773c6..0000000 --- a/examples/waitfor.coffee +++ /dev/null @@ -1,48 +0,0 @@ -## -# 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. -# -# @param testFx javascript condition that evaluates to a boolean, -# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or -# as a callback function. -# @param onReady what to do when testFx condition is fulfilled, -# it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or -# as a callback function. -# @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used. -## -waitFor = (testFx, onReady, timeOutMillis=3000) -> - start = new Date().getTime() - condition = false - f = -> - if (new Date().getTime() - start < timeOutMillis) and not condition - # If not time-out yet and condition not yet fulfilled - condition = (if typeof testFx is 'string' then eval testFx else testFx()) #< defensive code - else - if not condition - # If condition still not fulfilled (timeout but condition is 'false') - console.log "'waitFor()' timeout" - phantom.exit 1 - else - # Condition fulfilled (timeout and/or condition is 'true') - console.log "'waitFor()' finished in #{new Date().getTime() - start}ms." - if typeof onReady is 'string' then eval onReady else onReady() #< Do what it's supposed to do once the condition is fulfilled - clearInterval interval #< Stop this interval - interval = setInterval f, 250 #< repeat check every 250ms - - -page = require('webpage').create() - -# Open Twitter on 'sencha' profile and, onPageLoad, do... -page.open 'http://twitter.com/#!/sencha', (status) -> - # Check for page load success - if status isnt 'success' - console.log 'Unable to access network' - else - # Wait for 'signin-dropdown' to be visible - waitFor -> - # Check in the page if a specific element is now visible - page.evaluate -> - $('#signin-dropdown').is ':visible' - , -> - console.log 'The sign-in dialog should be visible now.' - phantom.exit() diff --git a/examples/walk_through_frames.coffee b/examples/walk_through_frames.coffee deleted file mode 100644 index 1838fa2..0000000 --- a/examples/walk_through_frames.coffee +++ /dev/null @@ -1,66 +0,0 @@ -pageTitle = (page) -> - page.evaluate -> - window.document.title -setPageTitle = (page, newTitle) -> - page.evaluate ((newTitle) -> - window.document.title = newTitle - ), newTitle -p = require("webpage").create() -p.open "../test/webpage-spec-frames/index.html", (status) -> - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - console.log "p.switchToChildFrame(\"frame1\"): " + p.switchToChildFrame("frame1") - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - console.log "p.switchToChildFrame(\"frame1-2\"): " + p.switchToChildFrame("frame1-2") - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - console.log "p.switchToParentFrame(): " + p.switchToParentFrame() - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - console.log "p.switchToChildFrame(0): " + p.switchToChildFrame(0) - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - console.log "p.switchToMainFrame()" - p.switchToMainFrame() - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - console.log "p.switchToChildFrame(\"frame2\"): " + p.switchToChildFrame("frame2") - console.log "pageTitle(): " + pageTitle(p) - console.log "currentFrameName(): " + p.currentFrameName() - console.log "childFramesCount(): " + p.childFramesCount() - console.log "childFramesName(): " + p.childFramesName() - console.log "setPageTitle(CURRENT TITLE+'-visited')" - setPageTitle p, pageTitle(p) + "-visited" - console.log "" - phantom.exit() diff --git a/examples/weather.coffee b/examples/weather.coffee deleted file mode 100644 index d8da90d..0000000 --- a/examples/weather.coffee +++ /dev/null @@ -1,29 +0,0 @@ -page = require('webpage').create() -system = require 'system' - -city = 'Mountain View, California'; # default -if system.args.length > 1 - city = Array.prototype.slice.call(system.args, 1).join(' ') -url = encodeURI 'http://api.openweathermap.org/data/2.1/find/name?q=' + city - -console.log 'Checking weather condition for', city, '...' - -page.open url, (status) -> - if status isnt 'success' - console.log 'Error: Unable to access network!' - else - result = page.evaluate -> - return document.body.innerText - try - data = JSON.parse result - data = data.list[0] - console.log '' - console.log 'City:', data.name - console.log 'Condition:', data.weather.map (entry) -> - return entry.main - console.log 'Temperature:', Math.round(data.main.temp - 273.15), 'C' - console.log 'Humidity:', Math.round(data.main.humidity), '%' - catch e - console.log 'Error:', e.toString() - - phantom.exit() diff --git a/examples/weather.js b/examples/weather.js deleted file mode 100644 index 2b4e611..0000000 --- a/examples/weather.js +++ /dev/null @@ -1,37 +0,0 @@ -var page = require('webpage').create(), - system = require('system'), - city, - url; - -city = 'Mountain View, California'; // default -if (system.args.length > 1) { - city = Array.prototype.slice.call(system.args, 1).join(' '); -} -url = encodeURI('http://api.openweathermap.org/data/2.1/find/name?q=' + city); - -console.log('Checking weather condition for', city, '...'); - -page.open(url, function(status) { - var result, data; - if (status !== 'success') { - console.log('Error: Unable to access network!'); - } else { - result = page.evaluate(function () { - return document.body.innerText; - }); - try { - data = JSON.parse(result); - data = data.list[0]; - console.log(''); - console.log('City:', data.name); - console.log('Condition:', data.weather.map(function(entry) { - return entry.main; - }).join(', ')); - console.log('Temperature:', Math.round(data.main.temp - 273.15), 'C'); - console.log('Humidity:', Math.round(data.main.humidity), '%'); - } catch (e) { - console.log('Error:', e.toString()); - } - } - phantom.exit(); -});