Permalink
Browse files

update

  • Loading branch information...
1 parent 37f93b5 commit bb745caa6be82993daf85f1e9366e343180e41d5 Andris Reinman committed May 25, 2012
Showing with 14 additions and 8 deletions.
  1. +14 −8 scripts/sanitize.js
View
@@ -34,25 +34,31 @@ page.open(phantom.args[0], function (status) {
page.evaluate(function(){
// find largest image
- var image,
+ var imgarr = [],
width, height,
- images = document.body.getElementsByTagName("p");
+ images = document.body.getElementsByTagName("img");
for(var i=images.length-1; i>=0; i--){
width = (Number(images[i].width) || 0) ;
height = (Number(images[i].height) || 0);
- if(width > 30 && height > 30 && (!image || width + height > image.width + image.height)){
- image = {
+ if(width > 30 && height > 30){
+ imgarr.push({
src: images[i].src,
- width: Number(images[i].width) || 0,
- height: Number(images[i].height) || 0
- }
+ width: width,
+ height: height
+ });
}
}
+ imgarr.sort(function(a,b){
+ return (b.width+b.height) - (a.width+a.height);
+ });
+
+ imgarr = imgarr.slice(0, 5); // 5 suurimat pilti
+
console.log(JSON.stringify({
body: document.body.innerHTML,
- image: image
+ images: imgarr
}));
});

0 comments on commit bb745ca

Please sign in to comment.