Guest User

Untitled

a guest
Aug 8th, 2022
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Delete Button For MAL
  3. // @namespace betterbuttonstomal2
  4. // @version 22
  5. // @description Delete button added to MAL anime/manga page
  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. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var $ = window.jQuery; //Defines That The Symbol $ Is A jQuery
  16. var animeid = location.pathname.match(/\d+/) === null ? location.search.match(/\d+/)[0] : location.pathname.match(/\d+/)[0]; //Get the anime id
  17. var token = document.head.querySelector("[name='csrf_token']").content; //Get the user csrf token
  18.  
  19. //*****************************************************************************************************************************************************
  20. var DeleteBTN = document.createElement("input"); //Create a input element
  21. document.querySelectorAll("#myinfo_status")[1].parentElement.appendChild(DeleteBTN); //Show the delete button
  22. $(DeleteBTN).attr({ //Set the attributes
  23. value: "Delete", //Add the value Delete to the button
  24. id: "DeleteBTN", //Add the id DeleteBTN to the button
  25. class: "inputButton ml8 delete_submit", //Add a class to the button
  26. type: "button", //Add the type to the button
  27. style: "margin-left: 30px!important;" //Set the css to the button
  28. }); //Finishing setting the attributes
  29. if (window.location.pathname.split('/')[1] === 'anime') { //If the user is on an anime page
  30. var entrytype = 'anime'; //Set the variable as anime
  31. document.querySelector("div.di-ib.form-user-episode.ml8").setAttribute("style", "width: 125px;"); //Set the css for the episodes element
  32. document.querySelectorAll("#myinfo_watchedeps")[1].setAttribute("style", "width: 25px;"); //Set the css for the episodes seen element
  33.  
  34. //*****************************************************************************************************************************************************
  35. //*****************************************************************************************************************************************************
  36. } else { //Starts the else condition
  37. var entrytype = 'manga'; //Set the variable as manga
  38. } //Finishes the else condition
  39. document.querySelector("#DeleteBTN").addEventListener("click", (async function() { //Add an advent listener to the delete button that will delete the anime of the user list when clicked
  40. await fetch("https://myanimelist.net/ownlist/" + entrytype + "/" + animeid + "/delete", {
  41. "headers": {
  42. "content-type": "application/x-www-form-urlencoded"
  43. },
  44. "body": "csrf_token=" + token + "",
  45. "method": "POST"
  46. }); //Finishes the fetch request
  47. location.reload(); //Reload the page after the user deleted the anime of his list
  48. })); //Finish the async function and the advent listener
  49. })();
Advertisement
Add Comment
Please, Sign In to add comment