Better Buttons to Change The Status Of Animes/Mangas And To Add Scores

Makes easier and faster to select any status/score by enlarging the removing the dropdown selection of those options. Delete any entry from your list, or score + add the whole anime Franchise to your anime list with a single click.

  1. // ==UserScript==
  2. // @name Better Buttons to Change The Status Of Animes/Mangas And To Add Scores
  3. // @namespace betterbuttonstomal2
  4. // @version 24
  5. // @description Makes easier and faster to select any status/score by enlarging the removing the dropdown selection of those options. Delete any entry from your list, or score + add the whole anime Franchise to your anime list with a single click.
  6. // @author hacker09
  7. // @include /^https:\/\/myanimelist\.net\/(anime|manga)(id=)?(\.php\?id=)?\/?\d+\/?(?!.*\/).*(\?q=.*&cat=anime|manga)?$/
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
  9. // @require https://greasyfork.org/scripts/446666-jquery-core-minified/code/jQuery%20Core%20minified.js
  10. // @grant GM.xmlHttpRequest
  11. // @connect chiaki.site
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17. var TotalLinks, FetchPage; //Creates a new global variable
  18. var token = document.head.querySelector("[name='csrf_token']").content; //Get the user csrf token
  19. const animeid = location.pathname.match(/\d+/) === null ? location.search.match(/\d+/)[0] : location.pathname.match(/\d+/)[0]; //Get the anime id
  20. document.querySelectorAll("#myinfo_status")[1].size = "5"; //Set the size for the Status button
  21. document.querySelectorAll("#myinfo_status")[1].setAttribute("style", "font-size: 13.2px; background-image: none; overflow: hidden;"); //Set the css for the status button
  22. document.querySelectorAll("#myinfo_score")[1].size = "11"; //Set the size for the Score button
  23. document.querySelectorAll("#myinfo_score > option:nth-child(1)")[1].innerText = 'Reset Score'; //Change the text "selection" to Reset Score
  24. document.querySelectorAll("#myinfo_score")[1].setAttribute("style", "background-image: none; overflow: hidden; padding : 5px; width: 100px;"); //Set the CSS for the score button
  25.  
  26. const DeleteBTN = document.createElement("input"); //Create a input element
  27. document.querySelectorAll("#myinfo_status")[1].parentElement.appendChild(DeleteBTN); //Show the delete button
  28. window.jQuery(DeleteBTN).attr({ //Set the attributes
  29. value: "Delete", //Add the value Delete to the button
  30. id: "DeleteBTN", //Add the id DeleteBTN to the button
  31. class: "inputButton ml8 delete_submit", //Add a class to the button
  32. type: "button", //Add the type to the button
  33. style: "margin-left: 15px!important;" //Set the CSS to the button
  34. }); //Finishing setting the attributes
  35. if (location.pathname.split('/')[1] === 'anime') { //If the user is on an anime page
  36. var entrytype = 'anime'; //Set the variable as anime
  37. document.querySelector("div.di-ib.form-user-episode.ml8").setAttribute("style", "width: 125px;"); //Set the CSS for the episodes element
  38. document.querySelectorAll("#myinfo_watchedeps")[1].setAttribute("style", "width: 25px;"); //Set the CSS for the episodes seen element
  39.  
  40. const ScoreButton = document.createElement("input"); //Create a input element
  41. document.querySelectorAll("#myinfo_status")[1].parentElement.appendChild(ScoreButton); //Show the Score button
  42. window.jQuery(ScoreButton).attr({ //Set the attributes
  43. value: "Score+Add Franchise", //Add the value Score to the button
  44. id: "ScoreBTN", //Add the id ScoreBTN to the button
  45. class: "inputButton ml8 delete_submit", //Add a class to the button
  46. type: "button", //Add the type to the button
  47. style: "margin-left: 15px!important;" //Set the CSS to the button
  48. }); //Finishing setting the attributes
  49. document.querySelector("div.di-ib.form-user-episode.ml8").setAttribute("style", "width: 125px;"); //Set the CSS for the episodes element
  50. document.querySelectorAll("#myinfo_watchedeps")[1].setAttribute("style", "width: 25px;"); //Set the CSS for the episodes seen element
  51. document.querySelector("#ScoreBTN").addEventListener("click", (async function() { //Add an event listener to the Score button that will score and set as "Watching" the whole franchise when clicked
  52. if (document.querySelector("#myinfo_score").value === '0') //If the actual score of the anime entry is 0
  53. { //Start the if condition
  54. alert('You must first give a score for this entry, then the script will give that same score and add the entire franchise with the current status of this entry.'); //Show a message
  55. return; //Stop the script from executing
  56. } //Finishes the if condition
  57.  
  58. GM.xmlHttpRequest({ //Starts the xmlHttpRequest
  59. method: "GET",
  60. url: `https://chiaki.site/?/tools/watch_order/id/${animeid}`,
  61. onload: function(response) { //Starts the onload event listener
  62. var ChiakiDocument = new DOMParser().parseFromString(response.responseText, 'text/html'); //Parses the fetch response
  63.  
  64. if (confirm("If you've already added this entire franchise to your anime list, press OK.")) { //Ask a question to the user
  65. FetchPage = `edit`; //If the user has already added the entire franchise to his anime list
  66. } else { //Starts the else condition
  67. FetchPage = `add`; //If the user doesn't have added the entire franchise to his anime list
  68. } //Starts the finishes
  69.  
  70. TotalLinks = ChiakiDocument.querySelectorAll("span.uk-text-muted.uk-text-small > a:nth-child(1)"); //Creates a variable to loop through the entry id elements after
  71.  
  72. for (var i = 0; i < TotalLinks.length; i++) { //Starts the for condition
  73. async function AddScore() //Creates a function to Score + set as "Watching" the Franchise
  74. { //Starts the function
  75. const response = await fetch(`https://myanimelist.net/ownlist/anime/${FetchPage}.json`, { //Fetches the page
  76. "headers": {
  77. "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
  78. },
  79. "body": `{"anime_id":${TotalLinks[i].href.match(/\d+/)[0]},"status":${document.querySelector(".po-r > #myinfo_status > option:checked").value},"score":${document.querySelector("#myinfo_score").value},"num_watched_episodes":0,"csrf_token":"${token}"}`,
  80. "method": "POST"
  81. }); //Finishes the fetch
  82. } //Finishes the async function
  83. if (TotalLinks[i].href.match(/\d+/)[0] !== animeid) //If the fetched chiaki.site anime ID isn't the same as the actual page anime ID
  84. { //Starts if condition
  85. AddScore(); //Starts the async AddScore function
  86. } //Finishes the if condition
  87. } //Finishes the for condition
  88.  
  89. alert(`Done!!!\nThe Whole Franchise was scored with ${document.querySelector("#myinfo_score").value} and added to your ${document.querySelector(".po-r > #myinfo_status > option:checked").innerText} anime list!`); //Shows a message
  90. } //Finishes the onload event listener
  91. }); //Finishes the xmlHttpRequest
  92. })); //Finishes the event listener
  93.  
  94. } else { //Starts the else condition
  95. entrytype = 'manga'; //Set the variable as manga
  96. } //Finishes the else condition
  97. document.querySelector("#DeleteBTN").addEventListener("click", (async function() { //Add an event listener to the delete button that will delete the entry of the user list when clicked
  98. await fetch(`https://myanimelist.net/ownlist/${entrytype}/${animeid}/delete`, {
  99. "headers": {
  100. "content-type": "application/x-www-form-urlencoded"
  101. },
  102. "body": `csrf_token=${token}`,
  103. "method": "POST"
  104. }); //Finishes the fetch request
  105. location.reload(); //Reload the page after the user deleted the anime from his list
  106. })); //Finish the async function and the event listener
  107. })();