MAL Date Fix

Script that fixes your Start/Finish Dates on MAL

当前为 2021-01-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MAL Date Fix
  3. // @namespace Fix your dates on MAL
  4. // @version 1.0
  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.  
  26. var how_much, startDate, endDate;
  27. 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 = [];
  28. $(window).ready(async () => {
  29.  
  30. function SendGetRequest(url) {
  31. return new Promise((resolve, reject) => {
  32. GM_xmlhttpRequest({
  33. method: "GET",
  34. url: url,
  35. onload: function(response) {
  36. resolve(response.responseText);
  37. },
  38. onerror: function(error) {
  39. reject(error);
  40. }
  41. });
  42. });
  43. }
  44. if (window.location.pathname.split('/')[2] === 'history,anime') {
  45.  
  46. $('a.entries-trigger')[0].click();
  47. how_much = parseInt($('a.entries-trigger').text());
  48.  
  49.  
  50. console.log("Start");
  51. $('#month-unknown ul li a').each(function(){
  52.  
  53. id.push(parseInt($(this).attr('href').slice(30)));
  54. });
  55. for(let f = 0; f<id.length; f++){
  56. console.log("Getting date of " + (f + 1) + " Title");
  57.  
  58. try {
  59. const response = await SendGetRequest("https://myanimelist.net/ajaxtb.php?keepThis=true&detailedaid=" +id[f] +"&TB_iframe=true&height=420&width=390");
  60. var length = $(response).find('.spaceit_pad').length;
  61. $(response).find('.spaceit_pad').each(function (x) {
  62.  
  63. if (x == 0){
  64. endDate = $(this).html().match(/\d{2}([\/.-])\d{2}\1\d{4}/g);
  65. endDate = endDate.toString();
  66.  
  67. endDay.push(parseInt(endDate.split('/')[1],10));
  68. endMonth.push(parseInt(endDate.split('/')[0],10));
  69. endYear.push(parseInt(endDate.split('/')[2],10));
  70. GM_setValue('endDay', endDay);
  71. GM_setValue('endMonth', endMonth);
  72. GM_setValue('endYear', endYear);
  73. }
  74. if (x == length - 1){
  75. startDate = $(this).html().match(/\d{2}([\/.-])\d{2}\1\d{4}/g);
  76. startDate = startDate.toString();
  77.  
  78. startDay.push(parseInt(startDate.split('/')[1],10));
  79. startMonth.push(parseInt(startDate.split('/')[0],10));
  80. startYear.push(parseInt(startDate.split('/')[2],10));
  81. GM_setValue('startYear', startYear);
  82. GM_setValue('startMonth', startMonth);
  83. GM_setValue('startDay', startDay);
  84.  
  85. }
  86.  
  87. if( f == how_much-1 && x == length - 1){ GM_setValue('id', id);
  88.  
  89. document.location = "https://myanimelist.net/ownlist/anime/"+id[0]+"/edit"; }
  90.  
  91. });
  92. } catch (error) { // in case the GET request fails
  93. if(error.status != null) console.error("Request failed with error code", error.status, ". Message is ", error.responseText);
  94. }
  95.  
  96. }
  97.  
  98. }
  99.  
  100.  
  101.  
  102.  
  103. if (window.location.pathname.split('/')[1] === 'ownlist'){
  104.  
  105. id = GM_getValue('id');
  106.  
  107. startDay = GM_getValue('startDay');
  108. startMonth = GM_getValue('startMonth');
  109. startYear = GM_getValue('startYear');
  110. endDay = GM_getValue('endDay');
  111. endMonth = GM_getValue('endMonth');
  112. endYear = GM_getValue('endYear');
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. for (let i = 0; i < id.length; i++) {
  120. console.log("Getting info about " + (i + 1) + " Title");
  121. try {
  122. const response = await SendGetRequest("https://myanimelist.net/ownlist/anime/"+id[i]+"/edit");
  123. $(response).find("#main-form :input").each(function(x) {
  124. if (x == 1)
  125. aeps.push($(this).val());
  126. if (x == 2)
  127. astatus.push($(this).val());
  128. if (x == 3)
  129. status.push($(this).val());
  130. if (x == 4)
  131. is_rewatching.push($(this).val());
  132. if (x == 5)
  133. num_watched_episodes.push($(this).val());
  134. if (x == 6)
  135. score.push($(this).val());
  136. if (x == 15)
  137. tags.push($(this).val());
  138. if (x == 16)
  139. priority.push($(this).val());
  140. if (x == 17)
  141. storage_type.push($(this).val());
  142. if (x == 18)
  143. storage_value.push($(this).val());
  144. if (x == 19)
  145. num_watched_times.push($(this).val());
  146. if (x == 20)
  147. rewatch_value.push($(this).val());
  148. if (x == 21)
  149. comments.push($(this).val());
  150. if (x == 22)
  151. is_asked_to_discuss.push($(this).val());
  152. if (x == 23)
  153. sns_post_type.push($(this).val());
  154.  
  155. });
  156. } catch (error) { // in case the GET request fails
  157. if(error.status != null) console.error("Request failed with error code", error.status, ". Message is ", error.responseText);
  158. }
  159.  
  160. }
  161. if(aeps.length == id.length){
  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': 'paste your csrf token here'
  190. },
  191. success: function(){
  192. console.log("Successfully updated "+e+" Title");
  193. },
  194. error: function(){
  195. console.log("Something went wrong");
  196. }
  197. });
  198. }
  199. }
  200.  
  201. }
  202.  
  203.  
  204. });