Advertisement
Guest User

MAL Track Missing Relations Edit

a guest
Jun 12th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     updateNew: function(fullRefresh) {
  2.         if (mal.entries.isUpdating()) {
  3.             return;
  4.         }
  5.        
  6.         var index = 0,
  7.             links = $('#content strong + a');
  8.  
  9.         mal.entries.done = mal.entries.fail = 0;
  10.         mal.entries.total = links.length;
  11.         mal.entries.right = {};
  12.        
  13.         mal.content.done.text('');
  14.         mal.content.fail.text('');
  15.         $('#content span[class^="mr_status_id_"]').empty();
  16.        
  17.         if (links.length === 0) {
  18.             mal.content.update(true);
  19.             return;
  20.         }
  21.        
  22.         links.each(function() {
  23.             // BEGIN NEW
  24.             if ($(this).parent().parent().find("td:contains('Plan to Watch')").size() === 1)
  25.             {
  26.                 --mal.entries.total;
  27.                 return true;
  28.             }
  29.             // END NEW
  30.             var id = parseInt($(this).prop('href').match(/\d+$/)[0]),
  31.                 span = $(this).parent().find('span[class="mr_status_id_' + id + '"]');
  32.            
  33.             if (span.length === 0) {
  34.                 span = $('<span class="mr_status_id_' + id + '"></span>').appendTo($(this).parent());
  35.             }
  36.            
  37.             if (mal.entries.left.hasOwnProperty(id)) {
  38.                 mal.content.done.text('  done: ' + (++mal.entries.done) + '/' + mal.entries.total);
  39.                 return;
  40.             }
  41.            
  42.             mal.entries.title[id] = $(this).prev('strong').text().trim();
  43.            
  44.             setTimeout(function() {
  45.                 $.ajax('/' + mal.type + '/' + id)
  46.                     .done(function(data) {
  47.                         mal.entries.left[id] = true;
  48.                        
  49.                         var rels = mal.entries.findRelations(id, data);
  50.                         if (!mal.entries.checkRelation(data)) {
  51.                             mal.entries.wrong[id] = true;
  52.                         }
  53.  
  54.                         if (fullRefresh) {
  55.                             $.each(rels, function(i, id) {
  56.                                 mal.entries.right[id] = true;
  57.                             });
  58.                         }
  59.        
  60.                         span.html('<small style="color: green;">done</small>');
  61.                         mal.content.done.text('  done: ' + (++mal.entries.done) + '/' + mal.entries.total);
  62.                        
  63.                         if (fullRefresh) {
  64.                             mal.entries.updateFull();
  65.                         }
  66.                         else {
  67.                             mal.content.update(true);
  68.                         }
  69.                     })
  70.                     .fail(function() {
  71.                         span.html('<small style="color: red;">fail</small>');
  72.                         mal.content.fail.text('  fail: ' + (++mal.entries.fail));
  73.                        
  74.                         if (fullRefresh) {
  75.                             mal.entries.updateFull();
  76.                         }
  77.                         else {
  78.                             mal.content.update(true);
  79.                         }
  80.                     });
  81.             }, mal.ajax.delay * (index++));
  82.         });
  83.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement