Guest User

Untitled

a guest
Jul 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.65 KB | None | 0 0
  1. (function($){
  2.     var anime;
  3.     var anidbvals;
  4.     var en = 0;
  5.     var xjat= 1;
  6.     var ja = 2;
  7.     var de = 3;
  8.     var official = 0;
  9.     var main = 1;
  10.     var short= 2;
  11.     var syn = 3;
  12.     var title= 0;
  13.     var language= 1;
  14.     var type= 2;
  15.     var titles= new Array();
  16.     function _init(){
  17.         $.jStorage.flush();
  18.         if($.jStorage.get('cached')== true){
  19.             anidbvals= $.jStorage.get('anidblist');
  20.         }
  21.         else if($.jStorage.get('cached')==false && $.jStorage.get('anidblist')){
  22.             anidbvals= $.jStorage.get('anidblist');
  23.             $.getJSON('anidbcache.php?updatelist='+anidbvals.length(), function(data) {
  24.                 anidbvals.push(data);
  25.                 $.jStorage.set('anidblist', anidbvals);
  26.                 $.jStorage.set('cached', true);
  27.                 $.jStorage.setTTL('cached', 172800000);
  28.             });
  29.         }
  30.         else{
  31.             $.getJSON('anidbcache.php?list=true', function(data) {
  32.                 $.jStorage.set('anidblist', data);
  33.                 $.jStorage.set('cached', true);
  34.                 $.jStorage.setTTL('cached', 172800000);
  35.                 anidbvals = data;
  36.             });
  37.         }
  38.  
  39.     };
  40.     $.cache = {
  41.            
  42.     };
  43.     $.anidb = {
  44.        
  45.         get_title: function(anidbid){
  46.             titles[0] = 0;
  47.             titles[1] = 0;
  48.             if(!(anidbid < 1))
  49.             if(anidbvals[anidbid] != undefined){
  50.                 $.each(anidbvals[anidbid-1], function(index, value){
  51.                     if(value[type] == 1){
  52.                         titles[0] = value[0];
  53.                     }
  54.                     else if(value[1]== 0 && value[2] == 0){
  55.                         titles[1] = value[0];
  56.                     }
  57.                 });
  58.                 if(titles[1]== 0){
  59.                     $.each(anidbvals[anidbid-1], function(index, value){
  60.                         if(value[1]== 2 && value[2] == 0){
  61.                             titles[1] = value[0];
  62.                         }
  63.                     });
  64.                 }
  65.                 if(titles[1]== 0){
  66.                     $.each(anidbvals[anidbid-1], function(index, value){
  67.                         if(value[language]== 1 && value[type] == 0){
  68.                             titles[1] = value[0];
  69.                         }
  70.                     });
  71.                 }
  72.                 return titles;
  73.             }
  74.         },
  75.         search_title: function(search_string, limit){
  76.             var results = new Array();
  77.             var counter = 0;
  78.             var regex = new RegExp(search_string + "[a-z0-9]*", "i");
  79.             $.each(anidbvals, function( index,value){
  80.                 $.each(value, function(index2, value2){
  81.                     if(value2['language'] == 'en' || value2['language'] == 'ja'|| value2['language'] =='x-jat'){
  82.                         if(value2['title'].match(regex) != null){
  83.                             results[counter] = +index+1;
  84.                             counter++;
  85.                             return false;
  86.                         }
  87.                     }
  88.                 });
  89.                 if(limit == counter-1){
  90.                     return false;  
  91.                 }
  92.             });
  93.             counter = 0;
  94.             $.each(results, function(index,value){
  95.                 if($.anidb.get_title(value) == search_string){
  96.                     temp= results[counter];
  97.                     results[counter] = results[index];
  98.                     results[index] = temp;
  99.                 }
  100.             });
  101.             return results;
  102.         },
  103.         get_anime: function(anidbid){
  104.             anime = new Array();
  105.            
  106.         }
  107.     };
  108.     _init();
  109. })(window.jQuery || window.$);
Add Comment
Please, Sign In to add comment