phantomjs.rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/.autotest +7 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +4 -0
  4. data/README.md +16 -0
  5. data/Rakefile +1 -0
  6. data/lib/phantomjs.rb +53 -0
  7. data/lib/phantomjs/version.rb +3 -0
  8. data/phantomjs.rb.gemspec +24 -0
  9. data/spec/phantomjs_spec.rb +13 -0
  10. data/spec/runner.js +2 -0
  11. data/vendor/phantomjs-1.4.1_OSX/ChangeLog +145 -0
  12. data/vendor/phantomjs-1.4.1_OSX/LICENSE.BSD +22 -0
  13. data/vendor/phantomjs-1.4.1_OSX/README.md +33 -0
  14. data/vendor/phantomjs-1.4.1_OSX/bin/Info.plist +12 -0
  15. data/vendor/phantomjs-1.4.1_OSX/bin/phantomjs +0 -0
  16. data/vendor/phantomjs-1.4.1_OSX/examples/arguments.coffee +6 -0
  17. data/vendor/phantomjs-1.4.1_OSX/examples/arguments.js +8 -0
  18. data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.coffee +46 -0
  19. data/vendor/phantomjs-1.4.1_OSX/examples/colorwheel.js +51 -0
  20. data/vendor/phantomjs-1.4.1_OSX/examples/countdown.coffee +8 -0
  21. data/vendor/phantomjs-1.4.1_OSX/examples/countdown.js +9 -0
  22. data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.coffee +40 -0
  23. data/vendor/phantomjs-1.4.1_OSX/examples/detectsniff.js +57 -0
  24. data/vendor/phantomjs-1.4.1_OSX/examples/direction.coffee +29 -0
  25. data/vendor/phantomjs-1.4.1_OSX/examples/direction.js +34 -0
  26. data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.coffee +19 -0
  27. data/vendor/phantomjs-1.4.1_OSX/examples/echoToFile.js +22 -0
  28. data/vendor/phantomjs-1.4.1_OSX/examples/features.js +30 -0
  29. data/vendor/phantomjs-1.4.1_OSX/examples/fibo.coffee +8 -0
  30. data/vendor/phantomjs-1.4.1_OSX/examples/fibo.js +9 -0
  31. data/vendor/phantomjs-1.4.1_OSX/examples/follow.coffee +54 -0
  32. data/vendor/phantomjs-1.4.1_OSX/examples/follow.js +59 -0
  33. data/vendor/phantomjs-1.4.1_OSX/examples/hello.coffee +2 -0
  34. data/vendor/phantomjs-1.4.1_OSX/examples/hello.js +2 -0
  35. data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.coffee +19 -0
  36. data/vendor/phantomjs-1.4.1_OSX/examples/imagebin.js +22 -0
  37. data/vendor/phantomjs-1.4.1_OSX/examples/injectme.coffee +23 -0
  38. data/vendor/phantomjs-1.4.1_OSX/examples/injectme.js +25 -0
  39. data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.coffee +13 -0
  40. data/vendor/phantomjs-1.4.1_OSX/examples/ipgeocode.js +14 -0
  41. data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.coffee +17 -0
  42. data/vendor/phantomjs-1.4.1_OSX/examples/loadspeed.js +22 -0
  43. data/vendor/phantomjs-1.4.1_OSX/examples/modernizr.js +1116 -0
  44. data/vendor/phantomjs-1.4.1_OSX/examples/movies.coffee +13 -0
  45. data/vendor/phantomjs-1.4.1_OSX/examples/movies.js +14 -0
  46. data/vendor/phantomjs-1.4.1_OSX/examples/netlog.coffee +17 -0
  47. data/vendor/phantomjs-1.4.1_OSX/examples/netlog.js +23 -0
  48. data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.coffee +109 -0
  49. data/vendor/phantomjs-1.4.1_OSX/examples/netsniff.js +131 -0
  50. data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.coffee +12 -0
  51. data/vendor/phantomjs-1.4.1_OSX/examples/outputEncoding.js +16 -0
  52. data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.coffee +13 -0
  53. data/vendor/phantomjs-1.4.1_OSX/examples/phantomwebintro.js +19 -0
  54. data/vendor/phantomjs-1.4.1_OSX/examples/pizza.coffee +18 -0
  55. data/vendor/phantomjs-1.4.1_OSX/examples/pizza.js +20 -0
  56. data/vendor/phantomjs-1.4.1_OSX/examples/post.coffee +12 -0
  57. data/vendor/phantomjs-1.4.1_OSX/examples/post.js +14 -0
  58. data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.coffee +22 -0
  59. data/vendor/phantomjs-1.4.1_OSX/examples/rasterize.js +27 -0
  60. data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.coffee +48 -0
  61. data/vendor/phantomjs-1.4.1_OSX/examples/render_multi_url.js +60 -0
  62. data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.coffee +59 -0
  63. data/vendor/phantomjs-1.4.1_OSX/examples/run-jasmine.js +77 -0
  64. data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.coffee +62 -0
  65. data/vendor/phantomjs-1.4.1_OSX/examples/run-qunit.js +74 -0
  66. data/vendor/phantomjs-1.4.1_OSX/examples/scandir.coffee +15 -0
  67. data/vendor/phantomjs-1.4.1_OSX/examples/scandir.js +21 -0
  68. data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.coffee +17 -0
  69. data/vendor/phantomjs-1.4.1_OSX/examples/seasonfood.js +19 -0
  70. data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.coffee +35 -0
  71. data/vendor/phantomjs-1.4.1_OSX/examples/simpleserver.js +40 -0
  72. data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.coffee +17 -0
  73. data/vendor/phantomjs-1.4.1_OSX/examples/sleepsort.js +24 -0
  74. data/vendor/phantomjs-1.4.1_OSX/examples/technews.coffee +17 -0
  75. data/vendor/phantomjs-1.4.1_OSX/examples/technews.js +16 -0
  76. data/vendor/phantomjs-1.4.1_OSX/examples/tweets.coffee +30 -0
  77. data/vendor/phantomjs-1.4.1_OSX/examples/tweets.js +36 -0
  78. data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.coffee +18 -0
  79. data/vendor/phantomjs-1.4.1_OSX/examples/unrandomize.js +24 -0
  80. data/vendor/phantomjs-1.4.1_OSX/examples/useragent.coffee +11 -0
  81. data/vendor/phantomjs-1.4.1_OSX/examples/useragent.js +14 -0
  82. data/vendor/phantomjs-1.4.1_OSX/examples/version.coffee +5 -0
  83. data/vendor/phantomjs-1.4.1_OSX/examples/version.js +5 -0
  84. data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.coffee +48 -0
  85. data/vendor/phantomjs-1.4.1_OSX/examples/waitfor.js +57 -0
  86. data/vendor/phantomjs-1.4.1_OSX/examples/weather.coffee +48 -0
  87. data/vendor/phantomjs-1.4.1_OSX/examples/weather.js +57 -0
  88. data/vendor/phantomjs-1.4.1_OSX/lib/jquery.js +8374 -0
  89. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/ChangeLog +177 -0
  90. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/LICENSE.BSD +22 -0
  91. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/README.md +33 -0
  92. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/Info.plist +12 -0
  93. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/bin/phantomjs +0 -0
  94. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.coffee +7 -0
  95. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/arguments.js +9 -0
  96. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.coffee +46 -0
  97. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/colorwheel.js +51 -0
  98. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.coffee +8 -0
  99. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/countdown.js +9 -0
  100. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.coffee +41 -0
  101. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/detectsniff.js +58 -0
  102. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.coffee +30 -0
  103. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/direction.js +35 -0
  104. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.coffee +20 -0
  105. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/echoToFile.js +24 -0
  106. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/features.js +30 -0
  107. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.coffee +8 -0
  108. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/fibo.js +9 -0
  109. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.coffee +29 -0
  110. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/follow.js +34 -0
  111. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.coffee +2 -0
  112. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/hello.js +2 -0
  113. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.coffee +20 -0
  114. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/imagebin.js +23 -0
  115. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.coffee +23 -0
  116. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/injectme.js +25 -0
  117. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.coffee +13 -0
  118. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/ipgeocode.js +14 -0
  119. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.coffee +18 -0
  120. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/loadspeed.js +23 -0
  121. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/modernizr.js +1116 -0
  122. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.coffee +13 -0
  123. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/movies.js +14 -0
  124. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.coffee +18 -0
  125. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netlog.js +25 -0
  126. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.coffee +110 -0
  127. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/netsniff.js +132 -0
  128. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.coffee +12 -0
  129. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/outputEncoding.js +16 -0
  130. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.coffee +13 -0
  131. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/phantomwebintro.js +19 -0
  132. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.coffee +18 -0
  133. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/pizza.js +20 -0
  134. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.coffee +12 -0
  135. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/post.js +14 -0
  136. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/postserver.js +34 -0
  137. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printenv.js +10 -0
  138. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/printmargins.js +35 -0
  139. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.coffee +23 -0
  140. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/rasterize.js +28 -0
  141. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.coffee +50 -0
  142. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/render_multi_url.js +62 -0
  143. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.coffee +61 -0
  144. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-jasmine.js +79 -0
  145. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.coffee +64 -0
  146. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/run-qunit.js +76 -0
  147. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.coffee +16 -0
  148. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/scandir.js +22 -0
  149. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.coffee +17 -0
  150. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/seasonfood.js +19 -0
  151. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/server.js +43 -0
  152. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/serverkeepalive.js +34 -0
  153. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.coffee +38 -0
  154. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/simpleserver.js +42 -0
  155. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.coffee +20 -0
  156. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/sleepsort.js +25 -0
  157. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.coffee +17 -0
  158. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/technews.js +16 -0
  159. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.coffee +31 -0
  160. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/tweets.js +37 -0
  161. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.coffee +18 -0
  162. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/unrandomize.js +24 -0
  163. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.coffee +11 -0
  164. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/useragent.js +14 -0
  165. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.coffee +5 -0
  166. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/version.js +5 -0
  167. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.coffee +48 -0
  168. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/waitfor.js +57 -0
  169. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.coffee +49 -0
  170. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/examples/weather.js +58 -0
  171. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.la +28 -0
  172. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.prl +7 -0
  173. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so +0 -0
  174. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4 +0 -0
  175. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8 +0 -0
  176. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtCore.so.4.8.0 +0 -0
  177. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.la +28 -0
  178. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.prl +7 -0
  179. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so +0 -0
  180. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4 +0 -0
  181. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8 +0 -0
  182. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtGui.so.4.8.0 +0 -0
  183. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.la +28 -0
  184. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.prl +7 -0
  185. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so +0 -0
  186. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4 +0 -0
  187. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8 +0 -0
  188. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtNetwork.so.4.8.0 +0 -0
  189. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.la +28 -0
  190. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.prl +6 -0
  191. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so +0 -0
  192. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4 +0 -0
  193. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9 +0 -0
  194. data/vendor/phantomjs-1.5.0-liunx-x86-dynamic/lib/libQtWebKit.so.4.9.0 +0 -0
  195. metadata +252 -0
@@ -0,0 +1,8 @@
1
+ t = 10
2
+ interval = setInterval ->
3
+ if t > 0
4
+ console.log t--
5
+ else
6
+ console.log 'BLAST OFF!'
7
+ phantom.exit()
8
+ , 1000
@@ -0,0 +1,9 @@
1
+ var t = 10,
2
+ interval = setInterval(function(){
3
+ if ( t > 0 ) {
4
+ console.log(t--);
5
+ } else {
6
+ console.log("BLAST OFF!");
7
+ phantom.exit();
8
+ }
9
+ }, 1000);
@@ -0,0 +1,40 @@
1
+ page = require('webpage').create()
2
+
3
+ page.onInitialized = ->
4
+ page.evaluate ->
5
+ userAgent = window.navigator.userAgent
6
+ platform = window.navigator.platform
7
+ window.navigator =
8
+ appCodeName: 'Mozilla'
9
+ appName: 'Netscape'
10
+ cookieEnabled: false
11
+ sniffed: false
12
+
13
+ window.navigator.__defineGetter__ 'userAgent', ->
14
+ window.navigator.sniffed = true
15
+ userAgent
16
+
17
+ window.navigator.__defineGetter__ 'platform', ->
18
+ window.navigator.sniffed = true
19
+ platform
20
+
21
+ if phantom.args.length is 0
22
+ console.log 'Usage: unsniff.js <some URL>'
23
+ phantom.exit()
24
+ else
25
+ address = phantom.args[0]
26
+ console.log 'Checking ' + address + '...'
27
+ page.open address, (status) ->
28
+ if status isnt 'success'
29
+ console.log 'FAIL to load the address'
30
+ else
31
+ window.setTimeout ->
32
+ sniffed = page.evaluate(->
33
+ navigator.sniffed
34
+ )
35
+ if sniffed
36
+ console.log 'The page tried to sniff the user agent.'
37
+ else
38
+ console.log 'The page did not try to sniff the user agent.'
39
+ phantom.exit()
40
+ , 1500
@@ -0,0 +1,57 @@
1
+ // Detect if a web page sniffs the user agent or not.
2
+
3
+ var page = require('webpage').create(),
4
+ sniffed,
5
+ address;
6
+
7
+ page.onInitialized = function () {
8
+ page.evaluate(function () {
9
+
10
+ (function () {
11
+ var userAgent = window.navigator.userAgent,
12
+ platform = window.navigator.platform;
13
+
14
+ window.navigator = {
15
+ appCodeName: 'Mozilla',
16
+ appName: 'Netscape',
17
+ cookieEnabled: false,
18
+ sniffed: false
19
+ };
20
+
21
+ window.navigator.__defineGetter__('userAgent', function () {
22
+ window.navigator.sniffed = true;
23
+ return userAgent;
24
+ });
25
+
26
+ window.navigator.__defineGetter__('platform', function () {
27
+ window.navigator.sniffed = true;
28
+ return platform;
29
+ });
30
+ })();
31
+ });
32
+ };
33
+
34
+ if (phantom.args.length === 0) {
35
+ console.log('Usage: unsniff.js <some URL>');
36
+ phantom.exit();
37
+ } else {
38
+ address = phantom.args[0];
39
+ console.log('Checking ' + address + '...');
40
+ page.open(address, function (status) {
41
+ if (status !== 'success') {
42
+ console.log('FAIL to load the address');
43
+ } else {
44
+ window.setTimeout(function () {
45
+ sniffed = page.evaluate(function () {
46
+ return navigator.sniffed;
47
+ });
48
+ if (sniffed) {
49
+ console.log('The page tried to sniff the user agent.');
50
+ } else {
51
+ console.log('The page did not try to sniff the user agent.');
52
+ }
53
+ phantom.exit();
54
+ }, 1500);
55
+ }
56
+ });
57
+ }
@@ -0,0 +1,29 @@
1
+ # Get driving direction using Google Directions API.
2
+
3
+ page = require('webpage').create()
4
+
5
+ if phantom.args.length < 2
6
+ console.log 'Usage: direction.js origin destination'
7
+ console.log 'Example: direction.js "San Diego" "Palo Alto"'
8
+ phantom.exit(1)
9
+ else
10
+ origin = phantom.args[0]
11
+ dest = phantom.args[1]
12
+ page.open encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
13
+ '&destination=' + dest + '&units=imperial&mode=driving&sensor=false'),
14
+ (status) ->
15
+ if status isnt 'success'
16
+ console.log 'Unable to access network'
17
+ else
18
+ steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig)
19
+ if not steps
20
+ console.log 'No data available for ' + origin + ' to ' + dest
21
+ else
22
+ for ins in steps
23
+ ins = ins.replace(/\&lt;/ig, '<').replace(/\&gt;/ig, '>')
24
+ ins = ins.replace(/\<div/ig, '\n<div')
25
+ ins = ins.replace(/<.*?>/g, '')
26
+ console.log(ins)
27
+ console.log ''
28
+ console.log page.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, '')
29
+ phantom.exit()
@@ -0,0 +1,34 @@
1
+ // Get driving direction using Google Directions API.
2
+
3
+ var page = require('webpage').create(),
4
+ origin, dest, steps;
5
+
6
+ if (phantom.args.length < 2) {
7
+ console.log('Usage: direction.js origin destination');
8
+ console.log('Example: direction.js "San Diego" "Palo Alto"');
9
+ phantom.exit(1);
10
+ } else {
11
+ origin = phantom.args[0];
12
+ dest = phantom.args[1];
13
+ page.open(encodeURI('http://maps.googleapis.com/maps/api/directions/xml?origin=' + origin +
14
+ '&destination=' + dest + '&units=imperial&mode=driving&sensor=false'), function (status) {
15
+ if (status !== 'success') {
16
+ console.log('Unable to access network');
17
+ } else {
18
+ steps = page.content.match(/<html_instructions>(.*)<\/html_instructions>/ig);
19
+ if (steps == null) {
20
+ console.log('No data available for ' + origin + ' to ' + dest);
21
+ } else {
22
+ steps.forEach(function (ins) {
23
+ ins = ins.replace(/\&lt;/ig, '<').replace(/\&gt;/ig, '>');
24
+ ins = ins.replace(/\<div/ig, '\n<div');
25
+ ins = ins.replace(/<.*?>/g, '');
26
+ console.log(ins);
27
+ });
28
+ console.log('');
29
+ console.log(page.content.match(/<copyrights>.*<\/copyrights>/ig).join('').replace(/<.*?>/g, ''));
30
+ }
31
+ }
32
+ phantom.exit();
33
+ });
34
+ }
@@ -0,0 +1,19 @@
1
+ # echoToFile.coffee - Write in a given file all the parameters passed on the CLI
2
+ fs = require 'fs'
3
+
4
+ if phantom.args.length < 2
5
+ console.log "Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>"
6
+ phantom.exit()
7
+ else
8
+ content = ""
9
+ f = null
10
+ i = 1
11
+ while i < phantom.args.length
12
+ content += phantom.args[i] + (if i == phantom.args.length - 1 then "" else " ")
13
+ ++i
14
+ try
15
+ f = fs.open(phantom.args[0], "w")
16
+ f.writeLine content
17
+ catch e
18
+ console.log e
19
+ phantom.exit()
@@ -0,0 +1,22 @@
1
+ // echoToFile.js - Write in a given file all the parameters passed on the CLI
2
+ var fs = require('fs');
3
+
4
+ if (phantom.args.length < 2) {
5
+ console.log("Usage: echoToFile.js DESTINATION_FILE <arguments to echo...>");
6
+ phantom.exit();
7
+ } else {
8
+ var content = '',
9
+ f = null;
10
+ for ( i= 1; i < phantom.args.length; ++i ) {
11
+ content += phantom.args[i] + (i === phantom.args.length-1 ? '' : ' ');
12
+ }
13
+
14
+ try {
15
+ f = fs.open(phantom.args[0], "w");
16
+ f.writeLine(content);
17
+ } catch (e) {
18
+ console.log(e);
19
+ }
20
+
21
+ phantom.exit();
22
+ }
@@ -0,0 +1,30 @@
1
+ var feature, supported = [], unsupported = [];
2
+
3
+ phantom.injectJs('modernizr.js');
4
+ console.log('Detected features (using Modernizr ' + Modernizr._version + '):');
5
+ for (feature in Modernizr) {
6
+ if (Modernizr.hasOwnProperty(feature)) {
7
+ if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' &&
8
+ feature !== 'input' && feature !== 'inputtypes') {
9
+ if (Modernizr[feature]) {
10
+ supported.push(feature);
11
+ } else {
12
+ unsupported.push(feature);
13
+ }
14
+ }
15
+ }
16
+ }
17
+
18
+ console.log('');
19
+ console.log('Supported:');
20
+ supported.forEach(function (e) {
21
+ console.log(' ' + e);
22
+ });
23
+
24
+ console.log('');
25
+ console.log('Not supported:');
26
+ unsupported.forEach(function (e) {
27
+ console.log(' ' + e);
28
+ });
29
+ phantom.exit();
30
+
@@ -0,0 +1,8 @@
1
+ fibs = [0, 1]
2
+ f = ->
3
+ console.log fibs[fibs.length - 1]
4
+ fibs.push fibs[fibs.length - 1] + fibs[fibs.length - 2]
5
+ if fibs.length > 10
6
+ window.clearInterval ticker
7
+ phantom.exit()
8
+ ticker = window.setInterval(f, 300)
@@ -0,0 +1,9 @@
1
+ var fibs = [0, 1];
2
+ var ticker = window.setInterval(function () {
3
+ console.log(fibs[fibs.length - 1]);
4
+ fibs.push(fibs[fibs.length - 1] + fibs[fibs.length - 2]);
5
+ if (fibs.length > 10) {
6
+ window.clearInterval(ticker);
7
+ phantom.exit();
8
+ }
9
+ }, 300);
@@ -0,0 +1,54 @@
1
+ # List following and followers from several accounts
2
+
3
+ users= [
4
+ 'sencha'
5
+ 'aconran'
6
+ 'adityabansod'
7
+ 'ambisinister'
8
+ 'arnebech'
9
+ 'ariyahidayat'
10
+ 'arthurakay'
11
+ 'bmoeskau'
12
+ 'darrellmeyer'
13
+ 'davidfoelber'
14
+ 'DavidKaneda'
15
+ 'donovanerba'
16
+ 'edspencer'
17
+ 'evantrimboli'
18
+ 'ExtAnimal'
19
+ 'jamieavins'
20
+ 'jarrednicholls'
21
+ 'jayrobinson'
22
+ 'lojjic'
23
+ 'luckymethod'
24
+ 'merrells'
25
+ 'mmullany'
26
+ 'philogb'
27
+ 'philstrong'
28
+ 'rdougan'
29
+ 'SubtleGradient'
30
+ '__ted__'
31
+ 'tmaintz'
32
+ 'WesleyMoy'
33
+ 'whereisthysting'
34
+ ]
35
+
36
+ follow = (user, callback) ->
37
+ page = require('webpage').create()
38
+ page.open 'http://mobile.twitter.com/' + user, (status) ->
39
+ if status is 'fail'
40
+ console.log user + ': ?'
41
+ else
42
+ data = page.evaluate -> document.querySelector('div.timeline-following').innerText
43
+ console.log user + ': ' + data
44
+ callback.apply()
45
+
46
+ process = () ->
47
+ if (users.length > 0)
48
+ user = users[0]
49
+ users.splice(0, 1)
50
+ follow(user, process)
51
+ else
52
+ phantom.exit()
53
+
54
+ process()
@@ -0,0 +1,59 @@
1
+ // List following and followers from several accounts
2
+
3
+ var users = ['sencha',
4
+ 'aconran',
5
+ 'adityabansod',
6
+ 'ambisinister',
7
+ 'arnebech',
8
+ 'ariyahidayat',
9
+ 'arthurakay',
10
+ 'bmoeskau',
11
+ 'darrellmeyer',
12
+ 'davidfoelber',
13
+ 'DavidKaneda',
14
+ 'donovanerba',
15
+ 'edspencer',
16
+ 'evantrimboli',
17
+ 'ExtAnimal',
18
+ 'jamieavins',
19
+ 'jarrednicholls',
20
+ 'jayrobinson',
21
+ 'lojjic',
22
+ 'luckymethod',
23
+ 'merrells',
24
+ 'mmullany',
25
+ 'philogb',
26
+ 'philstrong',
27
+ 'rdougan',
28
+ 'SubtleGradient',
29
+ '__ted__',
30
+ 'tmaintz',
31
+ 'WesleyMoy',
32
+ 'whereisthysting'];
33
+
34
+ function follow(user, callback) {
35
+ var page = require('webpage').create();
36
+ page.open('http://mobile.twitter.com/' + user, function (status) {
37
+ if (status === 'fail') {
38
+ console.log(user + ': ?');
39
+ } else {
40
+ var data = page.evaluate(function () {
41
+ return document.querySelector('div.timeline-following').innerText;
42
+ });
43
+ console.log(user + ': ' + data);
44
+ }
45
+ callback.apply();
46
+ });
47
+ }
48
+
49
+ function process() {
50
+ if (users.length > 0) {
51
+ var user = users[0];
52
+ users.splice(0, 1);
53
+ follow(user, process);
54
+ } else {
55
+ phantom.exit();
56
+ }
57
+ }
58
+
59
+ process();
@@ -0,0 +1,2 @@
1
+ console.log 'Hello, world!'
2
+ phantom.exit()
@@ -0,0 +1,2 @@
1
+ console.log('Hello, world!');
2
+ phantom.exit();
@@ -0,0 +1,19 @@
1
+ # Upload an image to imagebin.org
2
+
3
+ page = require('webpage').create()
4
+
5
+ if phantom.args.length isnt 1
6
+ console.log 'Usage: imagebin.coffee filename'
7
+ phantom.exit()
8
+ else
9
+ fname = phantom.args[0]
10
+ page.open 'http://imagebin.org/index.php?page=add', ->
11
+ page.uploadFile 'input[name=image]', fname
12
+ page.evaluate ->
13
+ document.querySelector('input[name=nickname]').value = 'phantom'
14
+ document.querySelector('input[name=disclaimer_agree]').click()
15
+ document.querySelector('form').submit()
16
+
17
+ window.setTimeout ->
18
+ phantom.exit()
19
+ , 3000
@@ -0,0 +1,22 @@
1
+ // Upload an image to imagebin.org
2
+
3
+ var page = require('webpage').create(),
4
+ fname;
5
+
6
+ if (phantom.args.length !== 1) {
7
+ console.log('Usage: imagebin.js filename');
8
+ phantom.exit();
9
+ } else {
10
+ fname = phantom.args[0];
11
+ page.open("http://imagebin.org/index.php?page=add", function () {
12
+ page.uploadFile('input[name=image]', fname);
13
+ page.evaluate(function () {
14
+ document.querySelector('input[name=nickname]').value = 'phantom';
15
+ document.querySelector('input[name=disclaimer_agree]').click()
16
+ document.querySelector('form').submit();
17
+ });
18
+ window.setTimeout(function () {
19
+ phantom.exit();
20
+ }, 3000);
21
+ });
22
+ }