Advertisement
Guest User

Untitled

a guest
Sep 12th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PostInfo(id, media) {
  2.     this.id = id;
  3.     this.media = media;
  4. }
  5.  
  6. // Loads JSON of current page and makes an id-md5 list of posts.
  7. function getPosts() {
  8.     var jsonUrl = document.URL.replace("html", "json");
  9.     var json = JSON.parse(httpGet(jsonUrl));
  10.  
  11.     var posts = json.threads[0].posts;
  12.     return posts.map(function(post) {
  13.         return getInfo(post);
  14.     });
  15. }
  16.  
  17. // Makes a GET request to a given URL and returns response text.
  18. function httpGet(url) {
  19.     var xmlHttp = new XMLHttpRequest();
  20.  
  21.     xmlHttp.open("GET", url, false);
  22.     xmlHttp.send(null);
  23.  
  24.     return xmlHttp.responseText;
  25. }
  26.  
  27. function getInfo(post) {
  28.     var media = post.files.map(function(file) {
  29.         return file.md5;
  30.     });
  31.  
  32.     return new PostInfo(post.number, media);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement