Advertisement
Xch3l

eSix_UserQuickSearch

Nov 13th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var pagno = 1; // Current page
  2.  
  3. var req = new XMLHttpRequest();
  4. req.onreadystatechange=function() {
  5.   if(req.readyState==4 && req.status==200)
  6.     gotIt(req.responseText);
  7. }
  8.  
  9. function request() { // Use an URL to help narrow even more the results instead of searching in the entire database
  10.   var url = "http://e621.net/user/index.json?name="+escape(serch)+"&page="+pagno+"&order=name&level=-1";
  11.   req.open("GET",url,true);
  12.   req.send();
  13. }
  14.  
  15. function gotIt(text) {
  16.   if(text==="[]") { // No more pages
  17.     // Notify that the specified user couldn't be found
  18.     alert("User \""+serch+"\" does not exist");
  19.   } else {
  20.     var users = eval("("+text+")");
  21.     var uname = "";
  22.     var pos = 0;
  23.  
  24.     while(uname!=serch && pos<users.length) {
  25.       uname = users[pos].name;
  26.       pos++;
  27.     }
  28.  
  29.     if(uname===serch)
  30.       alert("\""+serch+"\" found at index "+pos+" on page "+pagno);
  31.     else { // Advance to the next page and search again
  32.       pagno++;
  33.       request();
  34.     }
  35.   }
  36. }
  37.  
  38. var serch = "e621"; // Username to look for (case sensitive)
  39. request();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement