// ==UserScript==
// @name Better Buttons To Edit Anime/Manga Information
// @namespace Better Buttons To Edit Anime Information
// @version 1.9
// @description The script removes the actual "Edit Anime/Manga Information" drop down menu, and replaces that with Better Buttons To edit the Anime/Manga information.
// @author hacker09
// @include /^https:\/\/myanimelist\.net\/((anime|manga)(id=)?(\.php\?id=)?)(\/)?([\d]+)?/
// @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
// @run-at document-end
// @grant none
// @downloadURL none
// ==/UserScript==
(async function() {
var MarginLeft = -7; //Creates a new variable
const id = location.pathname.match(/\d+/)[0]; //Get the entry id
var type, remove, sourceortype, airingdatesorpubdates, ratingorchapvol; //Create new variables
const CSSPart = 'height: 10px; width: 10px; background-size: cover; display: inline-block; transform: scale(1.8); vertical-align: top;'; //Stpre part of the CSS codes
location.pathname.split('/')[1] === 'anime' ? (type = 'aid', remove = 'anime', sourceortype = 'source', airingdatesorpubdates = 'airingdates', ratingorchapvol = 'rating') : (type = 'mid', remove = 'manga', sourceortype = 'type', airingdatesorpubdates = 'pubdates', ratingorchapvol = 'chapvol'); //Set up the constiables
document.getElementsByClassName('js-' + remove + '-edit-info-button')[0].remove(); //Remove the default Edit Anime/Manga Information Button
const BroadCastButton = ''; //Create a BTN const
const ProducersButton = ''; //Create a BTN const
const RatingButton = ''; //Create a BTN const
const RelationsButton = ''; //Create a BTN const
const SourceButton = ''; //Create a BTN const
const AiringDatesButton = ''; //Create a BTN const
const BackgroundButton = ''; //Create a BTN const
const AlternativeTitlesButton = ''; //Create a BTN const
const SynopsisButton = ''; //Create a BTN const
const PictureButton = ''; //Create a BTN const
var DurationButton = ''; //Create a BTN const
//Math.sign(document.querySelector('.header-right').getBoundingClientRect().top) === -1
[...[...document.querySelectorAll("h2")].find(h2 => h2.textContent === "Information").parentNode.querySelectorAll("h2")].find(info => info.outerHTML.includes("Information")).outerHTML = '
Information
'; //Add the Information h2 header inside a div
const Infoh2Elem = document.querySelector("#InformationDIV"); //Save the information div element
const BTNsArray = [BroadCastButton, ProducersButton, RatingButton, RelationsButton, SourceButton, AiringDatesButton, BackgroundButton, AlternativeTitlesButton, SynopsisButton, PictureButton, DurationButton]; //Creates an array of BTNs
BTNsArray.forEach(function(BTNs) { //ForEach button in the array
document.querySelector('.header-right').parentElement.insertAdjacentHTML("beforeend", BTNs); //Add the BTN on the page
Infoh2Elem.insertAdjacentHTML("afterbegin", BTNs); //Add the BTN on the page
}); //Finishes the ForEach function
if (type === 'mid') //If the user is on a manga entry
{ //Starts the if condition
MarginLeft = 5; //Centralize the icons
document.querySelectorAll("#SourceButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Type")); //Change txt on mouse hover
document.querySelectorAll("#PictureButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Picture")); //Change txt on mouse hover
document.querySelectorAll("#SynopsisButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Synopsis")); //Change txt on mouse hover
document.querySelectorAll("#RelationsButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Relations")); //Change txt on mouse hover
document.querySelectorAll("#BackgroundButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Background")); //Change txt on mouse hover
document.querySelectorAll("#AiringDatesButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Publishing Dates")); //Change txt on mouse hover
document.querySelectorAll("#RatingButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Chapters/Volumes")); //Change txt on mouse hover
document.querySelectorAll("#RatingButton").forEach(BTN => BTN.style.backgroundImage = "url(https://i.imgur.com/py5QNtd.png)"); //Change rating BTN IMG
document.querySelectorAll("#AlternativeTitlesButton").forEach(BTN => BTN.setAttribute("title", "Edit Manga Alternative Titles")); //Change txt on mouse hover
document.querySelectorAll("#BroadCastButton,#ProducersButton,#DurationButton").forEach(BTN => BTN.setAttribute("style", "display: none !important;")); //Hide BTNs
} //Finishes the if condition
document.querySelectorAll(".BetterBTN").forEach(function(BTNs, i) { //ForEach Information BTNs
if (i > 10) { //Only for the Information BTNs
BTNs.style.marginLeft = MarginLeft + 'px'; //Gradualy increase the left margin
BTNs.style.display = 'block'; //Change the display mode
MarginLeft += 22; //Increase the left margin
} //Finishes the if condition
}); //Finishes the ForEach loop
document.querySelectorAll("#PictureButton,#DurationButton").forEach(function(BTN) { //ForEach picture and duration BTNs
BTN.addEventListener('contextmenu', function() { //When the picture icon is right clicked
window.open(this.href); //Open the picture edit link on a new tab
}, false); //Finishes the contextmenu event listener
}); //Finishes the ForEach loop
})();