Automatically Add Start/Finish Dates For Animes/Mangas + Helpful Buttons

Select Watching/Reading to auto add the start date, select Completed to auto add the finish date. The script will show the actual Anime/Manga dates below the Anime/Manga image, that's updated every time you reload or click on Watching//Reading/Completed. Hover the mouse on the date and click to reset. This script also adds 6 helpful buttons on the Anime/Manga Edit Page.

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

  1. // ==UserScript==
  2. // @name Automatically Add Start/Finish Dates For Animes/Mangas + Helpful Buttons
  3. // @namespace Add End And Start Dates In 1 Click + Reset Dates/All Buttons,
  4. // @version 2.0.0.5
  5. // @description Select Watching/Reading to auto add the start date, select Completed to auto add the finish date. The script will show the actual Anime/Manga dates below the Anime/Manga image, that's updated every time you reload or click on Watching//Reading/Completed. Hover the mouse on the date and click to reset. This script also adds 6 helpful buttons on the Anime/Manga Edit Page.
  6. // @author hacker09
  7. // @match https://myanimelist.net/ownlist/*
  8. // @include /^https:\/\/myanimelist\.net\/anime\/[\d]+(\/.*)?/
  9. // @include /^https:\/\/myanimelist\.net\/manga\/[\d]+(\/.*)?/
  10. // @icon https://www.google.com/s2/favicons?domain=myanimelist.net
  11. // @run-at document-end
  12. // @grant GM_addStyle
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. if (window.location.pathname.split('/')[1] === 'ownlist') //Check If The User Is On https://myanimelist.net/ownlist/ ,And If Yes These Codes Will Run
  18. {
  19. var entrytype = window.location.pathname.split('/')[2]; //Get the entry type
  20. var $ = window.jQuery; //Defines That The Symbol $ Is A jQuery
  21. //**********************************************************************************************************************************************************************
  22. var ResetBTNStart = document.createElement("a"); //Creates an a element
  23. ResetBTNStart.innerHTML = "Reset"; //Adds the text to the element
  24. document.querySelector("#start_date_insert_today").parentElement.appendChild(ResetBTNStart); //Shows the button
  25. ResetBTNStart.setAttribute("id", "resetstart"); //Adds an id to the button
  26. ResetBTNStart.setAttribute("style", "cursor: pointer;margin-left: 5px;height: 10px;width: 10px;top: 10px;"); //Sets the button css style
  27. document.getElementById('resetstart').onclick = function() { //Adds an advent listener to the button
  28. document.getElementById("add_" + entrytype + "_start_date_year").selectedIndex = -1; //Reset the start year
  29. document.getElementById("add_" + entrytype + "_start_date_day").selectedIndex = -1; //Reset the start day
  30. document.getElementById("add_" + entrytype + "_start_date_month").selectedIndex = -1; //Reset the start month
  31. }; //Finishes the advent listener
  32. //**********************************************************************************************************************************************************************
  33. var ResetBTNEnd = document.createElement("a"); //Creates an a element
  34. ResetBTNEnd.innerHTML = "Reset"; //Adds the text to the element
  35. document.querySelector("#end_date_insert_today").parentElement.appendChild(ResetBTNEnd); //Shows the button
  36. ResetBTNEnd.setAttribute("id", "resetend"); //Adds an id to the button
  37. ResetBTNEnd.setAttribute("style", "cursor: pointer;margin-left: 5px;height: 10px;width: 10px;top: 10px;"); //Sets the button css style
  38. document.getElementById('resetend').onclick = function() { //Adds an advent listener to the button
  39. document.getElementById("add_" + entrytype + "_finish_date_year").selectedIndex = -1; //Reset the finish year
  40. document.getElementById("add_" + entrytype + "_finish_date_day").selectedIndex = -1; //Reset the finish day
  41. document.getElementById("add_" + entrytype + "_finish_date_month").selectedIndex = -1; //Reset the finish month
  42. }; //Finishes the advent listener
  43. //**********************************************************************************************************************************************************************
  44. var AddDates = document.createElement("a"); //Creates an a element
  45. AddDates.innerHTML = "Add End And Start Dates + Submit"; //Adds the text to the element
  46. document.querySelector('.notice_open_public').appendChild(AddDates); //Shows the button
  47. AddDates.setAttribute("id", "addalldates"); //Adds an id to the button
  48. AddDates.setAttribute("style", "cursor: pointer;margin-left: 5px;height: 10px;width: 10px;top: 10px;"); //Sets the button css style
  49. document.getElementById('addalldates').onclick = function() { //Adds an advent listener to the button
  50. document.getElementById("start_date_insert_today").click(); //Adds the start date
  51. document.getElementById("end_date_insert_today").click(); //Adds the finish date
  52. document.getElementsByClassName("inputButton main_submit")[0].click(); //Submit
  53. }; //Finishes the advent listener
  54. //**********************************************************************************************************************************************************************
  55. var InsertStart = document.createElement("a"); //Creates an a element
  56. InsertStart.innerHTML = "Insert + Submit"; //Adds the text to the element
  57.  
  58. function findTheInStartDateTd() { //Find the td element that thas the test "Start Date"
  59. const headers = [...document.querySelectorAll("td")]; //Select all the td elements
  60. return headers.find(td => td.textContent === "Start Date"); //Find the td element that has the text "Start Date"
  61. } //Finishes the findTheInStartDateTd function
  62. findTheInStartDateTd().nextElementSibling.setAttribute("style", "padding: 14px;"); //Sets the td element css style
  63. findTheInStartDateTd().parentElement.appendChild(InsertStart); //Shows the button
  64. InsertStart.setAttribute("id", "InsertStart"); //Adds an id to the button
  65. InsertStart.setAttribute("style", "cursor: pointer;margin-left: -200px;"); //Sets the button css style
  66. document.getElementById('InsertStart').onclick = function() { //Adds an advent listener to the button
  67. document.getElementById("start_date_insert_today").click(); //Adds the start date
  68. document.getElementsByClassName("inputButton main_submit")[0].click(); //Submit
  69. }; //Finishes the advent listener
  70. //**********************************************************************************************************************************************************************
  71. var InsertEnd = document.createElement("a"); //Creates an a element
  72. InsertEnd.innerHTML = "Insert + Submit"; //Adds the text to the element
  73.  
  74. function findTheInFinishDateTd() { //Find the td element that thas the test "Finish Date"
  75. const headers = [...document.querySelectorAll("td")]; //Select all the td elements
  76. return headers.find(td => td.textContent === "Finish Date"); //Find the td element that has the text "Finish Date"
  77. } //Finishes the findTheInFinishDateTd function
  78. findTheInFinishDateTd().nextElementSibling.setAttribute("style", "padding: 14px;"); //Sets the td element css style
  79. findTheInFinishDateTd().parentElement.appendChild(InsertEnd); //Shows the button
  80. InsertEnd.setAttribute("id", "InsertEnd"); //Adds an id to the button
  81. InsertEnd.setAttribute("style", "cursor: pointer;margin-left: -200px;"); //Sets the button css style
  82. document.getElementById('InsertEnd').onclick = function() { //Adds an advent listener to the button
  83. document.getElementById("end_date_insert_today").click(); //Adds the finish date
  84. document.getElementsByClassName("inputButton main_submit")[0].click(); //Submit
  85. }; //Finishes the advent listener
  86. //**********************************************************************************************************************************************************************
  87. var ResetAlmostAll = document.createElement("a"); //Creates an a element
  88. ResetAlmostAll.innerHTML = "Reset Almost Everything"; //Adds the text to the element
  89. document.querySelector("#advanced-button").parentElement.appendChild(ResetAlmostAll); //Shows the button
  90. ResetAlmostAll.setAttribute("id", "resetalmostall"); //Adds an id to the button
  91. ResetAlmostAll.setAttribute("style", "cursor: pointer;margin-left: 240px;"); //Sets the button css style
  92. document.getElementById('resetalmostall').onclick = function resetSelectElement() { //Adds an advent listener to the button
  93. $('select').prop('selectedIndex', 0); //Resets almost all form fields
  94. document.getElementById("unknown_end").click(); //Unmark the box "unknown_end"
  95. }; //Finishes the advent listener
  96. //**********************************************************************************************************************************************************************
  97. setTimeout(function() { //Starts the timeout condition
  98. if (document.querySelectorAll("#hide-advanced-button")[0].outerText !== "Hide Advanced ") //Detect if the Show Advanced button is already opened or not,if not then...
  99. { //Starts the if condition
  100. document.querySelector("#hide-advanced-button").click(); //Clicks on the Show Advanced button
  101. } //Finishes the if condition
  102. }, 0); //Finishes the timeout condition
  103. } //Finishes the if condition
  104. //**********************************************************************************************************************************************************************
  105. else //If the user is on a manga/anime page
  106. { //Starts the if condition
  107. var d = new Date(); //Creates a variable called d that will hold the computer date on the local time zone
  108. var day = d.getDate(); //Creates a variable to hold the actual day
  109. var month = d.getMonth() + 1; //Creates a variable to hold the actual month
  110. var year = d.getFullYear(); //Creates a variable to hold the actual year
  111. var entrytype2 = window.location.pathname.split('/')[1]; //Creates a variable to hold the actual entry type
  112. var token = document.head.querySelector("[name='csrf_token']").content; //Creates a variable to hold the actual csrf_token
  113. var entryid = location.pathname.match(/\d+/)[0]; //Creates a variable to hold the actual entry id
  114. var priority, is_asked_to_discuss, sns_post_type, start_month, start_day, start_year, finish_month, finish_day, finish_year, watched_eps, current_score, anime_tags, storage_type, storage_value, rewatched_times, rewatch_value, comments, manga_read_chapters, manga_retail, manga_read_times, manga_reread_value, manga_read_volumes, status; //Make all these variables global
  115.  
  116. if (entrytype2 === 'anime') //If the entry type is anime, get the total episodes number
  117. { //Starts the if condition
  118. var totaleps = document.querySelector("#curEps").textContent; //Get the actual total episodes value
  119. } //Finishes the if condition
  120. else //If the entry type is manga
  121. { //Starts the else condition
  122. var totalVols = document.querySelector("#totalVols").textContent; //Get the actual total manga volumes
  123. var totalChaps = document.querySelector("#totalChaps").textContent; //Get the actual total manga chapters
  124. } //Finishes the else condition
  125.  
  126. async function getVariables() //Creates a function to get the needed Variables
  127. { //Starts the function
  128. const response = await fetch('https://myanimelist.net/ownlist/' + entrytype2 + '/' + entryid + '/edit'); //Fetch
  129. const html = await response.text(); //Gets the fetch response
  130. const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
  131. priority = newDocument.querySelector("#add_" + entrytype2 + "_priority").value; //Creates a variable to hold the actual priority value
  132. is_asked_to_discuss = newDocument.querySelector("#add_" + entrytype2 + "_is_asked_to_discuss").value; //Creates a variable to hold the actual is_asked_to_discuss value
  133. sns_post_type = newDocument.querySelector("#add_" + entrytype2 + "_sns_post_type").value; //Creates a variable to hold the actual SNS value
  134. start_day = newDocument.querySelector("#add_" + entrytype2 + "_start_date_day").value; //Creates a variable to hold the actual start_day value
  135. start_month = newDocument.querySelector("#add_" + entrytype2 + "_start_date_month").value; //Creates a variable to hold the actual start_month value
  136. start_year = newDocument.querySelector("#add_" + entrytype2 + "_start_date_year").value; //Creates a variable to hold the actual start_year value
  137. finish_day = newDocument.querySelector("#add_" + entrytype2 + "_finish_date_day").value; //Creates a variable to hold the actual finish_day value
  138. finish_month = newDocument.querySelector("#add_" + entrytype2 + "_finish_date_month").value; //Creates a variable to hold the actual finish_month value
  139. finish_year = newDocument.querySelector("#add_" + entrytype2 + "_finish_date_year").value; //Creates a variable to hold the actual finish_year value
  140. current_score = newDocument.querySelector("#add_" + entrytype2 + "_score").value; //Creates a variable to hold the actual current_score value
  141. anime_tags = newDocument.querySelector("#add_" + entrytype2 + "_tags").value; //Creates a variable to hold the actual anime_tags value
  142. storage_type = newDocument.querySelector("#add_" + entrytype2 + "_storage_type").value; //Creates a variable to hold the actual storage_type value
  143. comments = newDocument.querySelector("#add_" + entrytype2 + "_comments").value; //Creates a variable to hold the actual comments value
  144. status = newDocument.querySelector("#add_" + entrytype2 + "_status").value; //Creates a variable to hold the actual status value
  145. if (entrytype2 === 'anime') //If the entry type is anime
  146. { //Starts the if condition
  147. watched_eps = newDocument.querySelector("#add_anime_num_watched_episodes").value; //Creates a variable to hold the actual watched_eps value
  148. storage_value = newDocument.querySelector("#add_anime_storage_value").value; //Creates a variable to hold the actual storage_value value
  149. rewatched_times = newDocument.querySelector("#add_anime_num_watched_times").value; //Creates a variable to hold the actual rewatched_times value
  150. rewatch_value = newDocument.querySelector("#add_anime_rewatch_value").value; //Creates a variable to hold the actual rewatch_value value
  151. } //Finishes the if condition
  152. else //If the entry type is manga
  153. { //Starts the else condition
  154. manga_read_chapters = newDocument.querySelector("#add_manga_num_read_chapters").value; //Creates a variable to hold the actual manga_read_chapters value
  155. manga_retail = newDocument.querySelector("#add_manga_num_retail_volumes").value; //Creates a variable to hold the actual manga_retail value
  156. manga_read_times = newDocument.querySelector("#add_manga_num_read_times").value; //Creates a variable to hold the actual manga_read_times value
  157. manga_reread_value = newDocument.querySelector("#add_manga_reread_value").value; //Creates a variable to hold the actual manga_read_times value
  158. manga_read_volumes = newDocument.querySelector("#add_manga_num_read_volumes").value; //Creates a variable to hold the actual manga_read_volumes value
  159. } //Finishes the else condition
  160.  
  161. //Starts the codes to Display the Started Date
  162. if ((start_month !== "") || (start_day !== "") || (start_year !== "")) // If month or date or year is set in the started dates then show the button
  163. { //Starts the if condition
  164. var ResetStartDate = document.createElement("div"); //Creates the button to reset the start date
  165. ResetStartDate.innerHTML = 'Started: Month:' + start_month + ' Day:' + start_day + ' Year:' + start_year; //Define the button text
  166. document.querySelector("#profileRows").append(ResetStartDate); //Append the button below the "add to favorites" button
  167. ResetStartDate.setAttribute("id", "ResetStartDate"); //Gives an id to the button
  168. if (document.querySelectorAll("#ResetStartDate").length > 1) //If the button already exits
  169. { //Starts the if condition
  170. document.querySelector("#ResetStartDate").remove(); //Remove the old button
  171. } //Finishes the if condition
  172. ResetStartDate.setAttribute("style", "border-top: #92b0f1 1px solid;border-color: #92b0f1;border-style: solid;border-width: 0 0 1px;color: #1d439b;cursor: pointer;padding: 2px 3px;"); //Set the css for the button when the page loads
  173. document.querySelector("#ResetStartDate").onmousemove = function() { //Set the css for the button when the mouse is hovering the button
  174. ResetStartDate.innerHTML = "Reset Started Date"; //Change the element text
  175. ResetStartDate.setAttribute("style", "cursor: pointer;background-color: #1d439b;border-color: #6386d5;border-style: solid;border-width: 0 0 1px;color: #fff;padding: 2px 3px;"); //Make the element look like it's clickable and change the element color
  176. }; //Finishes the css for the button when the mouse is hovering the button
  177. document.querySelector("#ResetStartDate").onmouseout = function() {
  178. ResetStartDate.innerHTML = 'Started: Month:' + start_month + ' Day:' + start_day + ' Year:' + start_year;
  179. ResetStartDate.setAttribute("style", "border-top: #92b0f1 1px solid;border-color: #92b0f1;border-style: solid;border-width: 0 0 1px;color: #1d439b;cursor: pointer;padding: 2px 3px;"); //Set the css for the button when the mouse is not hovering the button
  180. }; //Set the css for the button when the mouse is leaves the button
  181. document.querySelector("#ResetStartDate").addEventListener("click", ResetStartDateFunc, false); //When the button is cliked call this function
  182. } //Finishes the if condition
  183.  
  184. //Starts the codes to Display the Finished Date
  185. if ((finish_month !== "") || (finish_day !== "") || (finish_year !== "")) // If month or date or year is set in the finished dates then show the button
  186. { //Starts the if condition
  187. var ResetFinishDate = document.createElement("div"); //Creates the button to reset the finish date
  188. ResetFinishDate.innerHTML = 'Finished: Month:' + finish_month + ' Day:' + finish_day + ' Year:' + finish_year; //Define the button text; //Define the button text
  189. document.querySelector("#profileRows").append(ResetFinishDate); //Append the button below the "add to favorites" button
  190. ResetFinishDate.setAttribute("id", "ResetFinishDate"); //Gives an id to the button
  191. if (document.querySelectorAll("#ResetFinishDate").length > 1) //If the button already exits
  192. { //Starts the if condition
  193. document.querySelector("#ResetFinishDate").remove(); //Remove the old button
  194. } //Finishes the if condition
  195. ResetFinishDate.setAttribute("style", "border-top: #92b0f1 1px solid;border-color: #92b0f1;border-style: solid;border-width: 0 0 1px;color: #1d439b;cursor: pointer;padding: 2px 3px;"); //Set the css for the button when the page loads
  196. document.querySelector("#ResetFinishDate").onmousemove = function() { //Set the css for the button when the mouse is hovering the button
  197. ResetFinishDate.innerHTML = "Reset Finished Date"; //Change the element text
  198. ResetFinishDate.setAttribute("style", "cursor: pointer;background-color: #1d439b;border-color: #6386d5;border-style: solid;border-width: 0 0 1px;color: #fff;padding: 2px 3px;"); //Make the element look like it's clickable and change the element color
  199. }; //Finishes the css for the button when the mouse is hovering the button
  200. document.querySelector("#ResetFinishDate").onmouseout = function() {
  201. ResetFinishDate.innerHTML = 'Finished: Month:' + finish_month + ' Day:' + finish_day + ' Year:' + finish_year;
  202. ResetFinishDate.setAttribute("style", "border-top: #92b0f1 1px solid;border-color: #92b0f1;border-style: solid;border-width: 0 0 1px;color: #1d439b;cursor: pointer;padding: 2px 3px;"); //Set the css for the button when the mouse is leaves the button
  203. }; //Set the css for the button when the mouse is hovering the button
  204. document.querySelector("#ResetFinishDate").addEventListener("click", ResetFinishDateFunc, false); //When the button is cliked call this function
  205. } //Finishes the if condition
  206.  
  207. //Starts the codes to Display the Reset All Dates
  208. if ((finish_month !== "" || finish_day !== "" || finish_year !== "") && (start_month !== "" || start_day !== "" || start_year !== "")) // If month or date or year is set in the started and finished dates then show the button
  209. { //Starts the if condition
  210. var ResetAllDatesVar = document.createElement("div"); //Creates the button to reset all dates
  211. ResetAllDatesVar.innerHTML = "Reset Started+Finished Dates"; //Define the button text
  212. document.querySelector("#profileRows").append(ResetAllDatesVar); //Append the button below the "add to favorites" button
  213. ResetAllDatesVar.setAttribute("id", "ResetAllDatesVar"); //Gives an id to the button
  214. if (document.querySelectorAll("#ResetAllDatesVar").length > 1) //If the button already exits
  215. { //Starts the if condition
  216. document.querySelectorAll("#ResetAllDatesVar")[0].remove(); //Remove the old button.There's no real need to update this button again, but if isn't updated the onmousemove/out won't work
  217. } //Finishes the if condition
  218. ResetAllDatesVar.setAttribute("style", "border-top: #92b0f1 1px solid;border-color: #92b0f1;border-style: solid;border-width: 0 0 1px;color: #1d439b;cursor: pointer;padding: 2px 3px;"); //Set the css for the button when the page loads
  219. document.querySelector("#ResetAllDatesVar").onmousemove = function() { //Set the css for the button when the mouse is hovering the button
  220. ResetAllDatesVar.setAttribute("style", "cursor: pointer;background-color: #1d439b;border-color: #6386d5;border-style: solid;border-width: 0 0 1px;color: #fff;padding: 2px 3px;"); //Make the element look like it's clickable and change the element color
  221. }; //Finishes the css for the button when the mouse is hovering the button
  222. document.querySelector("#ResetAllDatesVar").onmouseout = function() { //Set the css for the button when the mouse isn't hovering the button
  223. ResetAllDatesVar.setAttribute("style", "border-top: #92b0f1 1px solid;border-color: #92b0f1;border-style: solid;border-width: 0 0 1px;color: #1d439b;cursor: pointer;padding: 2px 3px;"); //Set the css for the button when the mouse is leaves the button
  224. }; //Fnishrd the css for the button when the mouse isn't hovering the button
  225. document.querySelector("#ResetAllDatesVar").addEventListener("click", ResetAllDates, false); //When the button is cliked call this function
  226. } //Finishes the if condition
  227. } //Finishes the async getvariables function
  228. if (document.querySelector("#myinfo_status.btn-user-status-add-list.js-form-user-status.js-form-user-status-btn.myinfo_addtolist") === null) { //If the anime is on the user list
  229. var AddedToList = true;
  230. getVariables(); //Call and wait the function getVariables
  231. } //Finishes the if condition
  232.  
  233. GM_addStyle(".loading{position: fixed;width: 100%;height: 100%;background-color: #00000054;top: 0;z-index: 1000;background-image: url(https://pa1.narvii.com/6258/61f5cd5c652efec508ff3c6e10798d26ccef6366_hq.gif);background-repeat: no-repeat;background-position: center;}"); //Add the css. Image optionals and backup https://pastebin.com/raw/zrzN2PUe
  234. const loadingScreen = document.createElement("div"); //Creates and div element
  235. document.body.appendChild(loadingScreen); //Add the loading screen to the html body
  236.  
  237. async function ResetAllDates() //Creates a function to Reset All Dates
  238. { //Starts the async ResetAllDates function
  239. loadingScreen.classList.add("loading"); //Starts the Loading Screen
  240. document.querySelector("#ResetAllDatesVar").textContent = 'Done!'; //Changes the button text
  241. await getVariables(); //Call and wait the function getVariables
  242. document.querySelector("#ResetStartDate").textContent = 'Done!'; //Changes the button text
  243. document.querySelector("#ResetFinishDate").textContent = 'Done!'; //Changes the button text
  244. document.querySelector("#ResetAllDatesVar").remove(); //Removes the now needless button
  245. document.querySelector("#ResetStartDate").remove(); //Removes the now needless button
  246. document.querySelector("#ResetFinishDate").remove(); //Removes the now needless button
  247. const response = await fetch("https://myanimelist.net/ownlist/" + entrytype2 + "/" + entryid + "/edit", {
  248. "headers": {
  249. "content-type": "application/x-www-form-urlencoded"
  250. },
  251. "body": "add_manga%5Bnum_read_chapters%5D=" + manga_read_chapters + "&add_manga%5Bnum_retail_volumes%5D=" + manga_retail + "&add_manga%5Bnum_read_times%5D=" + manga_read_times + "&add_manga%5Breread_value%5D=" + manga_reread_value + "&add_manga%5Bnum_read_volumes%5D=" + manga_read_volumes + "&add_" + entrytype2 + "%5Bstatus%5D=" + status + "&add_anime%5Bnum_watched_episodes%5D=" + watched_eps + "&add_" + entrytype2 + "%5Bscore%5D=" + current_score + "&add_" + entrytype2 + "%5Btags%5D=" + anime_tags + "&add_" + entrytype2 + "%5Bpriority%5D=" + priority + "&add_" + entrytype2 + "%5Bstorage_type%5D=" + storage_type + "&add_anime%5Bstorage_value%5D=" + storage_value + "&add_anime%5Bnum_watched_times%5D=" + rewatched_times + "&add_anime%5Brewatch_value%5D=" + rewatch_value + "&add_" + entrytype2 + "%5Bcomments%5D=" + comments + "&add_" + entrytype2 + "%5Bis_asked_to_discuss%5D=" + is_asked_to_discuss + "&add_" + entrytype2 + "%5Bsns_post_type%5D=" + sns_post_type + "&csrf_token=" + token + "",
  252. "method": "POST"
  253. }); //Finishes the fetch
  254. loadingScreen.classList.remove("loading"); //Disable the Loading Screen
  255. } //Finishes the async ResetAllDates function
  256.  
  257. async function ResetStartDateFunc() //Creates a function to reset the start dates
  258. { //Starts the async ResetStartDateFunc function
  259. loadingScreen.classList.add("loading"); //Starts the Loading Screen
  260. document.querySelector("#ResetStartDate").textContent = 'Done!'; //Changes the button text
  261. if (document.querySelector("#ResetAllDatesVar") !== null) //Check if the button ResetAllDatesVar exists
  262. { //Starts the if condition
  263. document.querySelectorAll("#ResetAllDatesVar")[0].textContent = 'Done!'; //Changes the button text
  264. } //Finishes the if condition
  265. await getVariables(); //Call and wait the function getVariables
  266. document.querySelector("#ResetStartDate").remove(); //Removes the now needless button
  267. if (document.querySelector("#ResetAllDatesVar") !== null) //Check if the button ResetAllDatesVar exists
  268. { //Starts the if condition
  269. document.querySelector("#ResetAllDatesVar").remove(); //Removes the now needless button
  270. } //Finishes the if condition
  271. const response = await fetch("https://myanimelist.net/ownlist/" + entrytype2 + "/" + entryid + "/edit", {
  272. "headers": {
  273. "content-type": "application/x-www-form-urlencoded"
  274. },
  275. "body": "add_manga%5Bnum_read_chapters%5D=" + manga_read_chapters + "&add_manga%5Bnum_retail_volumes%5D=" + manga_retail + "&add_manga%5Bnum_read_times%5D=" + manga_read_times + "&add_manga%5Breread_value%5D=" + manga_reread_value + "&add_manga%5Bnum_read_volumes%5D=" + manga_read_volumes + "&add_" + entrytype2 + "%5Bstatus%5D=" + status + "&add_anime%5Bnum_watched_episodes%5D=" + watched_eps + "&add_" + entrytype2 + "%5Bscore%5D=" + current_score + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Bmonth%5D=" + finish_month + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Bday%5D=" + finish_day + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Byear%5D=" + finish_year + "&add_" + entrytype2 + "%5Btags%5D=" + anime_tags + "&add_" + entrytype2 + "%5Bpriority%5D=" + priority + "&add_" + entrytype2 + "%5Bstorage_type%5D=" + storage_type + "&add_anime%5Bstorage_value%5D=" + storage_value + "&add_anime%5Bnum_watched_times%5D=" + rewatched_times + "&add_anime%5Brewatch_value%5D=" + rewatch_value + "&add_" + entrytype2 + "%5Bcomments%5D=" + comments + "&add_" + entrytype2 + "%5Bis_asked_to_discuss%5D=" + is_asked_to_discuss + "&add_" + entrytype2 + "%5Bsns_post_type%5D=" + sns_post_type + "&csrf_token=" + token + "",
  276. "method": "POST"
  277. }); //Finishes the fetch
  278. await getVariables(); //Call and wait the function getVariables to Display the Reset All Dates
  279. loadingScreen.classList.remove("loading"); //Disable the Loading Screen
  280. } //Finishes the async ResetStartDateFunc function
  281.  
  282. async function ResetFinishDateFunc() //Creates a function to reset the finish dates
  283. { //Starts the async ResetFinishDateFunc function
  284. loadingScreen.classList.add("loading"); //Starts the Loading Screen
  285. document.querySelector("#ResetFinishDate").textContent = 'Done!'; //Changes the button text
  286. if (document.querySelector("#ResetAllDatesVar") !== null) //Check if the button ResetAllDatesVar exists
  287. { //Starts the if condition
  288. document.querySelectorAll("#ResetAllDatesVar")[0].textContent = 'Done!'; //Changes the button text
  289. } //Finishes the if condition
  290. await getVariables(); //Call and wait the function getVariables
  291. document.querySelector("#ResetFinishDate").remove(); //Removes the now needless button
  292. if (document.querySelector("#ResetAllDatesVar") !== null) //Check if the button ResetAllDatesVar exists
  293. { //Starts the if condition
  294. document.querySelector("#ResetAllDatesVar").remove(); //Removes the now needless button
  295. } //Finishes the if condition
  296. const response = await fetch("https://myanimelist.net/ownlist/" + entrytype2 + "/" + entryid + "/edit", {
  297. "headers": {
  298. "content-type": "application/x-www-form-urlencoded"
  299. },
  300. "body": "add_manga%5Bnum_read_chapters%5D=" + manga_read_chapters + "&add_manga%5Bnum_retail_volumes%5D=" + manga_retail + "&add_manga%5Bnum_read_times%5D=" + manga_read_times + "&add_manga%5Breread_value%5D=" + manga_reread_value + "&add_manga%5Bnum_read_volumes%5D=" + manga_read_volumes + "&add_" + entrytype2 + "%5Bstatus%5D=" + status + "&add_anime%5Bnum_watched_episodes%5D=" + watched_eps + "&add_" + entrytype2 + "%5Bscore%5D=" + current_score + "&add_" + entrytype2 + "%5Bstart_date%5D%5Bmonth%5D=" + start_month + "&add_" + entrytype2 + "%5Bstart_date%5D%5Bday%5D=" + start_day + "&add_" + entrytype2 + "%5Bstart_date%5D%5Byear%5D=" + start_year + "&add_" + entrytype2 + "%5Btags%5D=" + anime_tags + "&add_" + entrytype2 + "%5Bpriority%5D=" + priority + "&add_" + entrytype2 + "%5Bstorage_type%5D=" + storage_type + "&add_anime%5Bstorage_value%5D=" + storage_value + "&add_anime%5Bnum_watched_times%5D=" + rewatched_times + "&add_anime%5Brewatch_value%5D=" + rewatch_value + "&add_" + entrytype2 + "%5Bcomments%5D=" + comments + "&add_" + entrytype2 + "%5Bis_asked_to_discuss%5D=" + is_asked_to_discuss + "&add_" + entrytype2 + "%5Bsns_post_type%5D=" + sns_post_type + "&csrf_token=" + token + "",
  301. "method": "POST"
  302. }); //Finishes the fetch
  303. await getVariables(); //Call and wait the function getVariables to Display the Reset All Dates
  304. loadingScreen.classList.remove("loading"); //Disable the Loading Screen
  305. } //Finishes the async ResetFinishDateFunc function
  306.  
  307. async function AddStartDate() //Add The Start Date When Watching Is Selected
  308. { //Starts the async function
  309. loadingScreen.classList.add("loading"); //Starts the Loading Screen
  310. await getVariables(); //Call and wait the function getVariables
  311. if ((start_month === "") && (start_day === "") && (start_year === "")) // If month and date and year is NOT set in the started dates then Add The Start Date
  312. { //Starts the if condition
  313. const response = await fetch("https://myanimelist.net/ownlist/" + entrytype2 + "/" + entryid + "/edit", {
  314. "headers": {
  315. "content-type": "application/x-www-form-urlencoded"
  316. },
  317. "body": "add_manga%5Bnum_read_chapters%5D=" + manga_read_chapters + "&add_manga%5Bnum_retail_volumes%5D=" + manga_retail + "&add_manga%5Bnum_read_times%5D=" + manga_read_times + "&add_manga%5Breread_value%5D=" + manga_reread_value + "&add_manga%5Bnum_read_volumes%5D=" + manga_read_volumes + "&add_" + entrytype2 + "%5Bstatus%5D=1&add_anime%5Bnum_watched_episodes%5D=" + watched_eps + "&add_" + entrytype2 + "%5Bscore%5D=" + current_score + "&add_" + entrytype2 + "%5Bstart_date%5D%5Bmonth%5D=" + month + "&add_" + entrytype2 + "%5Bstart_date%5D%5Bday%5D=" + day + "&add_" + entrytype2 + "%5Bstart_date%5D%5Byear%5D=" + year + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Bmonth%5D=" + finish_month + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Bday%5D=" + finish_day + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Byear%5D=" + finish_year + "&add_" + entrytype2 + "%5Btags%5D=" + anime_tags + "&add_" + entrytype2 + "%5Bpriority%5D=" + priority + "&add_" + entrytype2 + "%5Bstorage_type%5D=" + storage_type + "&add_anime%5Bstorage_value%5D=" + storage_value + "&add_anime%5Bnum_watched_times%5D=" + rewatched_times + "&add_anime%5Brewatch_value%5D=" + rewatch_value + "&add_" + entrytype2 + "%5Bcomments%5D=" + comments + "&add_" + entrytype2 + "%5Bis_asked_to_discuss%5D=" + is_asked_to_discuss + "&add_" + entrytype2 + "%5Bsns_post_type%5D=" + sns_post_type + "&csrf_token=" + token + "",
  318. "method": "POST",
  319. }); //Set The Anime Start Dates
  320. await getVariables(); //Call and wait the function getVariables to Display the Finished Date and Display the Reset All Dates
  321. } //Finishes the if condition
  322. loadingScreen.classList.remove("loading"); //Disable the Loading Screen
  323. } //Finishes the async AddStartDate function
  324.  
  325. async function AddFinishDate() //Add The Finished Date When Completed Is Selected
  326. { //Starts the async AddFinishDate function
  327. loadingScreen.classList.add("loading"); //Starts the Loading Screen
  328. await getVariables(); //Call and wait the function getVariables
  329. if (finish_month === "" && finish_day === "" && finish_year === "") // If month and date and year is NOT set in the finished dates then Add The Finished Date
  330. { //Starts the if condition
  331.  
  332. if ((start_month === "") && (start_day === "") && (start_year === "")) //If month, date and year isn't set in the started dates, add the start date as well
  333. { //Starts the if condition
  334. start_day = day; //Instead of adding a blank or the actual start day value, add today's day
  335. start_month = month; //Instead of adding a blank or the actual start month value, add today's month
  336. start_year = year; //Instead of adding a blank or the actual start year value, add today's year
  337. } //Finishes the if condition
  338.  
  339. const response = await fetch("https://myanimelist.net/ownlist/" + entrytype2 + "/" + entryid + "/edit", {
  340. "headers": {
  341. "content-type": "application/x-www-form-urlencoded"
  342. },
  343. "body": "add_manga%5Bnum_read_chapters%5D=" + totalChaps + "&add_manga%5Bnum_retail_volumes%5D=" + manga_retail + "&add_manga%5Bnum_read_times%5D=" + manga_read_times + "&add_manga%5Breread_value%5D=" + manga_reread_value + "&add_manga%5Bnum_read_volumes%5D=" + totalVols + "&add_" + entrytype2 + "%5Bstatus%5D=2&add_anime%5Bnum_watched_episodes%5D=" + totaleps + "&add_" + entrytype2 + "%5Bscore%5D=" + current_score + "&add_" + entrytype2 + "%5Bstart_date%5D%5Bmonth%5D=" + start_month + "&add_" + entrytype2 + "%5Bstart_date%5D%5Bday%5D=" + start_day + "&add_" + entrytype2 + "%5Bstart_date%5D%5Byear%5D=" + start_year + "&add_" + entrytype2 + "%5Btags%5D=" + anime_tags + "&add_" + entrytype2 + "%5Bpriority%5D=" + priority + "&add_" + entrytype2 + "%5Bstorage_type%5D=" + storage_type + "&add_anime%5Bstorage_value%5D=" + storage_value + "&add_anime%5Bnum_watched_times%5D=" + rewatched_times + "&add_anime%5Brewatch_value%5D=" + rewatch_value + "&add_" + entrytype2 + "%5Bcomments%5D=" + comments + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Bmonth%5D=" + month + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Bday%5D=" + day + "&add_" + entrytype2 + "%5Bfinish_date%5D%5Byear%5D=" + year + "&add_" + entrytype2 + "%5Bis_asked_to_discuss%5D=" + is_asked_to_discuss + "&add_" + entrytype2 + "%5Bsns_post_type%5D=" + sns_post_type + "&csrf_token=" + token + "",
  344. "method": "POST"
  345. }); //Finishes the fetch
  346. await getVariables(); //Call and wait the function getVariables to Display the Finished Date and Display the Reset All Dates
  347. } //Finishes the if condition
  348. loadingScreen.classList.remove("loading"); //Disable the Loading Screen
  349. } //Finishes the async AddFinishDate function
  350.  
  351. function SelectedValue() //Creates a function to get the selected value
  352. { //Starts the SelectedValue function
  353. if (this.value === '2') //Completed Was Selected
  354. { //Starts the if condition
  355. AddFinishDate(); //Starts the function AddFinishDate
  356. } //Finishes the Completed else function
  357. else if (this.value === '1') //Watching Was Selected
  358. { //Starts the if condition
  359. AddStartDate(); //Starts the function set the date
  360. } //Finishes the Watching if function
  361. else if (this.value === '3') //On-Hold Was Selected
  362. { //Starts the else condition
  363. console.log('On-Hold Was Selected'); //Just shows a message on the dev console, this allows MAL to run their actual advent listener
  364. } //Finishes the On-Hold else function
  365. else if (this.value === '4') //Dropped Was Selected
  366. { //Starts the else condition
  367. console.log('Dropped Was Selected'); //Just shows a message on the dev console, this allows MAL to run their actual advent listener
  368. } //Finishes the Dropped else function
  369. else //Plan To Watch Was Selected
  370. { //Starts the else condition
  371. console.log('Plan To Watch Was Selected'); //Just shows a message on the dev console, this allows MAL to run their actual advent listener
  372. } //Finishes the Plan To else function
  373. } //Finishes the SelectedValue function
  374.  
  375. document.querySelectorAll("#myinfo_status")[1].addEventListener('change', SelectedValue, false); //Adds an advent listener to the status button on the right side of the anime image
  376. document.querySelectorAll("#myinfo_status")[0].addEventListener('change', SelectedValue, false); //Adds an advent listener to the status button below the anime image
  377.  
  378. if (entrytype2 === 'anime') //If the script is running on an anime entry
  379. { //Starts the if condition
  380. function PlusButtonAddFinishedDate() //Adding all episodes auto set entry as completed and auto set finished dates
  381. { //Starts the function PlusButtonAddFinishedDate
  382. if (document.querySelector("#myinfo_watchedeps").value === document.querySelector("#curEps").textContent) //If the number of add eps is the same as the total then
  383. { //Starts the if condition
  384. document.querySelectorAll("#myinfo_status")[1].value = '2'; //Set the anime as completed, in a way that the user can see
  385. document.querySelectorAll("#myinfo_status")[0].value = '2'; //Set the anime as completed, in a way that the user can see
  386. document.querySelectorAll("#myinfo_status")[1].dataset.class = 'completed'; //Change the selection box to blue
  387. AddFinishDate(); //Call the function AddFinishDate
  388. } //Finishes the if condition
  389. } //Finishes the function PlusButtonAddFinishedDate
  390.  
  391. function CallPlusButtonAddFinishedDate() //Function to call the function PlusButtonAddFinishedDate after some time
  392. {
  393. setTimeout(PlusButtonAddFinishedDate, 700); //Call the function PlusButtonAddFinishedDate, after 0.5 secs
  394. } //Finishes the function CallPlusButtonAddFinishedDate
  395.  
  396. document.querySelectorAll("i.fa.fa-plus-circle")[0].addEventListener('click', CallPlusButtonAddFinishedDate, false); //Adds an advent listener to the plus button below the anime image
  397. if (AddedToList) //If the entry is already on the user list
  398. { //Starts the if condition
  399. document.querySelectorAll("i.fa.fa-plus-circle")[1].addEventListener('click', CallPlusButtonAddFinishedDate, false); //Adds an advent listener to the plus button on the right side of the anime image
  400. } //Finishes the if condition
  401. } //Finishes the if condition
  402. } //Finishes the else condition
  403. })();