MAL Date Fix

Script that fixes your Start/Finish Dates on MAL

目前為 2021-01-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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");
    }
  });
}
}

         }


});