MAL Date Fix

Script that fixes your Start/Finish Dates on MAL

当前为 2021-02-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MAL Date Fix
  3. // @namespace Fix your dates on MAL
  4. // @version 1.22
  5. // @description Script that fixes your Start/Finish Dates on MAL
  6. // @author NurarihyonMaou
  7. // @match https://anime.plus/*/history,anime
  8. // @match https://myanimelist.net/ownlist/*
  9. // @grant GM_xmlhttpRequest
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @require http://code.jquery.com/jquery-3.5.1.min.js
  13. // ==/UserScript==
  14.  
  15. var $ = window.jQuery;
  16.  
  17. var id = [];
  18. var startDay = [];
  19. var startMonth = [];
  20. var startYear = [];
  21. var endDay = [];
  22. var endMonth = [];
  23. var endYear = [];
  24.  
  25. var csrf_token;
  26.  
  27. var how_much, startDate, endDate;
  28. let aeps = [], astatus = [], status = [], num_watched_episodes = [], score = [], tags = [], priority = [], storage_type = [], storage_value = [], num_watched_times = [], rewatch_value = [], comments = [], is_asked_to_discuss = [], sns_post_type = [], is_rewatching = [], submitIt = [];
  29. $(window).ready(async () => {
  30.  
  31. function SendGetRequest(url) {
  32. return new Promise((resolve, reject) => {
  33. GM_xmlhttpRequest({
  34. method: "GET",
  35. url: url,
  36. onload: function(response) {
  37. resolve(response.responseText);
  38. },
  39. onerror: function(error) {
  40. reject(error);
  41. }
  42. });
  43. });
  44. }
  45. if (window.location.pathname.split('/')[2] === 'history,anime') {
  46.  
  47. $('a.entries-trigger')[0].click();
  48. how_much = parseInt($('a.entries-trigger').text());
  49.  
  50.  
  51. console.log("Start");
  52. $('#month-unknown ul li a').each(function(){
  53.  
  54. id.push(parseInt($(this).attr('href').slice(30)));
  55. });
  56.  
  57. if(id.length == how_much){ GM_setValue('id', id);
  58.  
  59. document.location = "https://myanimelist.net/ownlist/anime/"+id[0]+"/edit"; }
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66. if (window.location.pathname.split('/')[1] === 'ownlist'){
  67.  
  68. id = GM_getValue('id');
  69.  
  70.  
  71.  
  72.  
  73. csrf_token = $("meta[name='csrf_token']").attr('content');
  74.  
  75.  
  76.  
  77.  
  78. for (let i = 0; i < id.length; i++) {
  79. console.log("Getting info about " + (i + 1) + " Title");
  80. try {
  81. const response = await SendGetRequest("https://myanimelist.net/ownlist/anime/"+id[i]+"/edit");
  82. $(response).find("#main-form :input").each(function(x) {
  83. if (x == 1)
  84. aeps.push($(this).val());
  85. if (x == 2)
  86. astatus.push($(this).val());
  87. if (x == 3)
  88. status.push($(this).val());
  89. if (x == 4)
  90. is_rewatching.push($(this).val());
  91. if (x == 5)
  92. num_watched_episodes.push($(this).val());
  93. if (x == 6)
  94. score.push($(this).val());
  95. if (x == 15)
  96. tags.push($(this).val());
  97. if (x == 16)
  98. priority.push($(this).val());
  99. if (x == 17)
  100. storage_type.push($(this).val());
  101. if (x == 18)
  102. storage_value.push($(this).val());
  103. if (x == 19)
  104. num_watched_times.push($(this).val());
  105. if (x == 20)
  106. rewatch_value.push($(this).val());
  107. if (x == 21)
  108. comments.push($(this).val());
  109. if (x == 22)
  110. is_asked_to_discuss.push($(this).val());
  111. if (x == 23)
  112. sns_post_type.push($(this).val());
  113.  
  114. });
  115. } catch (error) {
  116. if(error.status != null) console.error("Request failed with error code", error.status, ". Message is ", error.responseText);
  117. }
  118.  
  119. }
  120. if(aeps.length == id.length){
  121.  
  122. for(let f = 0; f<id.length; f++){
  123. console.log("Getting date of " + (f + 1) + " Title");
  124.  
  125. try {
  126. const response = await SendGetRequest("https://myanimelist.net/ajaxtb.php?keepThis=true&detailedaid=" +id[f] +"&TB_iframe=true&height=420&width=390");
  127. var length = $(response).find('.spaceit_pad').length;
  128. $($(response).find('.spaceit_pad').get().reverse()).each(function (x) {
  129.  
  130. if (x == 0){
  131. startDate = $(this).html().match(/\d{2}([\/.-])\d{2}\1\d{4}/g);
  132. startDate = startDate.toString();
  133.  
  134. startDay.push(parseInt(startDate.split('/')[1],10));
  135. startMonth.push(parseInt(startDate.split('/')[0],10));
  136. startYear.push(parseInt(startDate.split('/')[2],10));
  137. }
  138.  
  139. if (x<length && $(this).html().indexOf("Ep "+aeps[f]) == 0){
  140. endDate = $(this).html().match(/\d{2}([\/.-])\d{2}\1\d{4}/g);
  141. endDate = endDate.toString();
  142.  
  143. endDay.push(parseInt(endDate.split('/')[1],10));
  144. endMonth.push(parseInt(endDate.split('/')[0],10));
  145. endYear.push(parseInt(endDate.split('/')[2],10));
  146.  
  147. return false;
  148. }
  149. x++
  150.  
  151.  
  152. });
  153. } catch (error) {
  154. if(error.status != null) console.error("Request failed with error code", error.status, ". Message is ", error.responseText);
  155. }
  156.  
  157. }
  158. }
  159.  
  160. if(endYear.length == id.length){
  161. console.log("Last Stage");
  162. for(let e = 0; e<id.length; e++){
  163. $.ajax({
  164. method: 'POST',
  165. url: 'https://myanimelist.net/ownlist/anime/'+id[e]+'/edit',
  166. data: {
  167. 'anime_id': id[e],
  168. 'aeps': aeps[e],
  169. 'astatus': astatus[e],
  170. 'add_anime[status]': status[e],
  171. 'add_anime[num_watched_episodes]': num_watched_episodes[e],
  172. 'add_anime[score]': score[e],
  173. 'add_anime[start_date][month]': startMonth[e],
  174. 'add_anime[start_date][day]': startDay[e],
  175. 'add_anime[start_date][year]': startYear[e],
  176. 'add_anime[finish_date][month]': endMonth[e],
  177. 'add_anime[finish_date][day]': endDay[e],
  178. 'add_anime[finish_date][year]': endYear[e],
  179. 'add_anime[tags]': tags[e],
  180. 'add_anime[priority]': priority[e],
  181. 'add_anime[storage_type]': storage_type[e],
  182. 'add_anime[storage_value]': storage_value[e],
  183. 'add_anime[num_watched_times]': num_watched_times[e],
  184. 'add_anime[rewatch_value]': rewatch_value[e],
  185. 'add_anime[comments]': comments[e],
  186. 'add_anime[is_asked_to_discuss]': is_asked_to_discuss[e],
  187. 'add_anime[sns_post_type]': sns_post_type[e],
  188. 'submitIt': 0,
  189. 'csrf_token': csrf_token
  190. },
  191. complete: function(){
  192. console.log("Successfully updated "+(e+1)+" Title");
  193. if(e == id.length-1) setTimeout(function(){console.log("The End -> verify in the Network tab that all edit requests returned a status of 200");}, 500);
  194. },
  195. error: function(){
  196. console.log("Something went wrong");
  197. }
  198. });
  199.  
  200. }
  201. }
  202.  
  203. }
  204.  
  205.  
  206. });