Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Delete Button For MAL
- // @namespace betterbuttonstomal2
- // @version 22
- // @description Delete button added to MAL anime/manga page
- // @author hacker09
- // @include /^https:\/\/myanimelist\.net\/(anime|manga)(id=)?(\.php\?id=)?\/?\d+\/?(?!.*\/).*(\?q=.*&cat=anime|manga)?$/
- // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- (function() {
- 'use strict';
- var $ = window.jQuery; //Defines That The Symbol $ Is A jQuery
- var animeid = location.pathname.match(/\d+/) === null ? location.search.match(/\d+/)[0] : location.pathname.match(/\d+/)[0]; //Get the anime id
- var token = document.head.querySelector("[name='csrf_token']").content; //Get the user csrf token
- //*****************************************************************************************************************************************************
- var DeleteBTN = document.createElement("input"); //Create a input element
- document.querySelectorAll("#myinfo_status")[1].parentElement.appendChild(DeleteBTN); //Show the delete button
- $(DeleteBTN).attr({ //Set the attributes
- value: "Delete", //Add the value Delete to the button
- id: "DeleteBTN", //Add the id DeleteBTN to the button
- class: "inputButton ml8 delete_submit", //Add a class to the button
- type: "button", //Add the type to the button
- style: "margin-left: 30px!important;" //Set the css to the button
- }); //Finishing setting the attributes
- if (window.location.pathname.split('/')[1] === 'anime') { //If the user is on an anime page
- var entrytype = 'anime'; //Set the variable as anime
- document.querySelector("div.di-ib.form-user-episode.ml8").setAttribute("style", "width: 125px;"); //Set the css for the episodes element
- document.querySelectorAll("#myinfo_watchedeps")[1].setAttribute("style", "width: 25px;"); //Set the css for the episodes seen element
- //*****************************************************************************************************************************************************
- //*****************************************************************************************************************************************************
- } else { //Starts the else condition
- var entrytype = 'manga'; //Set the variable as manga
- } //Finishes the else condition
- 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
- await fetch("https://myanimelist.net/ownlist/" + entrytype + "/" + animeid + "/delete", {
- "headers": {
- "content-type": "application/x-www-form-urlencoded"
- },
- "body": "csrf_token=" + token + "",
- "method": "POST"
- }); //Finishes the fetch request
- location.reload(); //Reload the page after the user deleted the anime of his list
- })); //Finish the async function and the advent listener
- })();
Advertisement
Add Comment
Please, Sign In to add comment