MAL Date Fix

Script that fixes your Start/Finish Dates on MAL

Tính đến 05-01-2021. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         MAL Date Fix
// @namespace    Fix your dates on MAL
// @version      1.1
// @description  Script that fixes your Start/Finish Dates on MAL
// @author       NurarihyonMaou
// @match        https://anime.plus/*/history,anime
// @match        https://myanimelist.net/ownlist/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @require      http://code.jquery.com/jquery-3.5.1.min.js
// ==/UserScript==

var $ = window.jQuery;

var id = [];
var startDay = [];
var startMonth = [];
var startYear = [];
var endDay = [];
var endMonth = [];
var endYear = [];

var csrf_token;

var how_much, startDate, endDate;
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 = [];
 $(window).ready(async () => {

  function SendGetRequest(url) {
    return new Promise((resolve, reject) => {
      GM_xmlhttpRequest({
        method: "GET",
        url: url,
        onload: function(response) {
          resolve(response.responseText);
        },
        onerror: function(error) {
          reject(error);
        }
      });
    });
  }
         if (window.location.pathname.split('/')[2] === 'history,anime') {

             $('a.entries-trigger')[0].click();
             how_much = parseInt($('a.entries-trigger').text());


             console.log("Start");
             $('#month-unknown ul li a').each(function(){

                id.push(parseInt($(this).attr('href').slice(30)));
             });
             for(let f = 0; f<id.length; f++){
                  console.log("Getting date of " + (f + 1) + " Title");

                  try {
                    const response = await SendGetRequest("https://myanimelist.net/ajaxtb.php?keepThis=true&detailedaid=" +id[f] +"&TB_iframe=true&height=420&width=390");
                    var length = $(response).find('.spaceit_pad').length;
                    $(response).find('.spaceit_pad').each(function (x) {

                        if (x == 0){
                            endDate = $(this).html().match(/\d{2}([\/.-])\d{2}\1\d{4}/g);
                            endDate   = endDate.toString();

                            endDay.push(parseInt(endDate.split('/')[1],10));
                            endMonth.push(parseInt(endDate.split('/')[0],10));
                            endYear.push(parseInt(endDate.split('/')[2],10));
                            GM_setValue('endDay', endDay);
                            GM_setValue('endMonth', endMonth);
                            GM_setValue('endYear', endYear);
                        }
                        if (x == length - 1){
                            startDate = $(this).html().match(/\d{2}([\/.-])\d{2}\1\d{4}/g);
                            startDate = startDate.toString();

                            startDay.push(parseInt(startDate.split('/')[1],10));
                            startMonth.push(parseInt(startDate.split('/')[0],10));
                            startYear.push(parseInt(startDate.split('/')[2],10));
                            GM_setValue('startYear', startYear);
                            GM_setValue('startMonth', startMonth);
                            GM_setValue('startDay', startDay);

                        }

                        if( f == how_much-1 && x == length - 1){ GM_setValue('id', id);

                        document.location = "https://myanimelist.net/ownlist/anime/"+id[0]+"/edit"; }

                    });
                  } catch (error) { // in case the GET request fails
                      if(error.status != null) console.error("Request failed with error code", error.status, ". Message is ", error.responseText);
                  }

                }

              }




         if (window.location.pathname.split('/')[1] === 'ownlist'){

            id = GM_getValue('id');

            startDay = GM_getValue('startDay');
            startMonth = GM_getValue('startMonth');
            startYear = GM_getValue('startYear');
            endDay = GM_getValue('endDay');
            endMonth = GM_getValue('endMonth');
            endYear = GM_getValue('endYear');


 csrf_token = $("meta[name='csrf_token']").attr('content');



for (let i = 0; i < id.length; i++) {
  console.log("Getting info about " + (i + 1) + " Title");
  try {
    const response = await SendGetRequest("https://myanimelist.net/ownlist/anime/"+id[i]+"/edit");
    $(response).find("#main-form :input").each(function(x) {
                         if (x == 1)
                             aeps.push($(this).val());
                         if (x == 2)
                             astatus.push($(this).val());
                         if (x == 3)
                             status.push($(this).val());
                         if (x == 4)
                             is_rewatching.push($(this).val());
                         if (x == 5)
                             num_watched_episodes.push($(this).val());
                         if (x == 6)
                             score.push($(this).val());
                         if (x == 15)
                             tags.push($(this).val());
                         if (x == 16)
                             priority.push($(this).val());
                         if (x == 17)
                             storage_type.push($(this).val());
                         if (x == 18)
                             storage_value.push($(this).val());
                         if (x == 19)
                             num_watched_times.push($(this).val());
                         if (x == 20)
                             rewatch_value.push($(this).val());
                         if (x == 21)
                             comments.push($(this).val());
                         if (x == 22)
                             is_asked_to_discuss.push($(this).val());
                         if (x == 23)
                             sns_post_type.push($(this).val());

    });
  } catch (error) { // in case the GET request fails
      if(error.status != null) console.error("Request failed with error code", error.status, ". Message is ", error.responseText);
  }

}
if(aeps.length == id.length){
  for(let e = 0; e<id.length; e++){
$.ajax({
method: 'POST',
    url: 'https://myanimelist.net/ownlist/anime/'+id[e]+'/edit',
    data: {
'anime_id': id[e],
'aeps': aeps[e],
'astatus': astatus[e],
'add_anime[status]': status[e],
'add_anime[num_watched_episodes]': num_watched_episodes[e],
'add_anime[score]': score[e],
'add_anime[start_date][month]': startMonth[e],
'add_anime[start_date][day]': startDay[e],
'add_anime[start_date][year]': startYear[e],
'add_anime[finish_date][month]': endMonth[e],
'add_anime[finish_date][day]': endDay[e],
'add_anime[finish_date][year]': endYear[e],
'add_anime[tags]': tags[e],
'add_anime[priority]': priority[e],
'add_anime[storage_type]': storage_type[e],
'add_anime[storage_value]': storage_value[e],
'add_anime[num_watched_times]': num_watched_times[e],
'add_anime[rewatch_value]': rewatch_value[e],
'add_anime[comments]': comments[e],
'add_anime[is_asked_to_discuss]': is_asked_to_discuss[e],
'add_anime[sns_post_type]': sns_post_type[e],
'submitIt': 0,
'csrf_token': csrf_token
    },
    success: function(){
      console.log("Successfully updated "+e+" Title");
    },
    error: function(){
      console.log("Something went wrong");
    }
  });
}
}

         }


});