Advertisement
rg443

500px following recursive, callback

Jan 19th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 500px page through image gallery (following)
  2. var t1=new Date(),stack=0;tag="following",page=6511;
  3. //tag="following",page=6511;
  4. //tag="rg443/favorites",page=884;
  5. //tag="popular",page=1112;
  6. //tag="editors",page=324;
  7. //tag="upcoming",page=1065;
  8. //tag="fresh/today",page=3361;
  9. //tag="fresh/yesterday",page=1421;
  10. //tag="fresh/week",page=5749;
  11. // tag="blog",page=61;
  12. tag="following",page=100;
  13.  
  14. /* fetch url */
  15. function get_url(url,callback) {
  16.         var r=new XMLHttpRequest();
  17.         r.open("GET",url,true);
  18.         //r.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  19.         //r.setRequestHeader("Accept-Encoding", "gzip");
  20.         r.onreadystatechange=function(){
  21.        if (this.readyState==4 && this.status==200 && callback) callback.call(this.responseText);
  22.        }
  23.     r.send();      
  24.  
  25. }
  26. /*
  27. Array.prototype.unique = function(){
  28. return this.filter(function(s, i, a){ return i == a.lastIndexOf(s); });
  29. }
  30. */
  31. function post_imgur(a,callback) {        
  32. var r=new XMLHttpRequest();
  33. r.posted=a.length;
  34. r.open("POST","http://176.34.162.148/jabry/imgur1.asp?u=&b=",true);
  35. //r.open("POST","http://notebook1.lan:8000/jabry/imgur1.asp?u=&b=",true);
  36. r.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  37. r.onreadystatechange=function(){if (this.readyState==4 && this.status==200 && callback) callback.call(this.responseText); }
  38. r.send("u=" + a.join(","));
  39. stack++;
  40. }
  41.  
  42. function parse_page(s){
  43.    var m=s.toString().match(/http:\/\/pcdn.500px.net\/\d+\/\w+\/\d.jpg/gim);
  44.    m && m.forEach(function(v,i,a){a[i]=v.replace(/\d.jpg$/,"4.jpg")});
  45.    //console.log(m);
  46.    m && post_imgur(m,function(){console.log("imgur rcvd: "+ (this.split("\n").length-1),--stack) });
  47. };
  48. function callback1(s){
  49.   parse_page(s.toString());
  50.   console.log(page,(new Date()-t1));
  51.   if (--page>0) get_url("http://500px.com/"+tag+"?page="+page,function(){callback1(this.toString())})
  52.   t1=new Date();
  53.   }
  54.  
  55. callback1("");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement