Haxorsnake / Remove Completed Anime for MyAnimeList

// ==UserScript==
// @name         Remove Completed Anime for MyAnimeList
// @namespace    http://tampermonkey.net/
// @version      1
// @description  Remove completed, on-hold, watching and dropped anime from the myanimelist genre listing to make it so you only see not seen anime.
// @author       Haxorsnake
// @license      MIT
// @match        https://myanimelist.net/anime/genre/*
// @match        https://myanimelist.net/topanime.php*
// ==/UserScript==

(function() {
    'use strict';
    //Check if logged in first for later use when placing button and text.
    let isLoggedin = document.querySelector("#malLogin");
    let topAnime = document.querySelector(".ml16");

    //Create function to locate completed, on-hold, watching and dropped anime. Remove spacer, then go to each entry and remove them from the page.
    function removeAnime(){
        let animeLoc = document.querySelectorAll(".completed, .on-hold, .watching, .dropped")

        //Spacer is removed so that the animes fall into eachother rather than to stay seperated after removing anime.

        if (topAnime){
            console.log("we in here")
            for (let i = 0; i < animeLoc.length; i++){
            animeLoc[i].parentElement.parentElement.remove();
        }
        }else {
            document.querySelector("article").remove()
            console.log("hah")
            for (let i = 0; i < animeLoc.length; i++){
            animeLoc[i].parentElement.parentElement.parentElement.remove();
            }
        }
       }
    //btnLocation is the area where the button will go. Then make the button element and style for later use.
    let btnLocation = document.querySelector(".js-search-filter-block")
    let RemoveAnimeBTN = document.createElement("BUTTON");

    RemoveAnimeBTN.innerHTML = "Remove Anime";
    RemoveAnimeBTN.style.border = "none";
    RemoveAnimeBTN.style.color = "white";
    RemoveAnimeBTN.style.fontFamily = "Verdana";
    RemoveAnimeBTN.style.fontSize = "13px";
    RemoveAnimeBTN.style.backgroundColor = "#1d439b";
    RemoveAnimeBTN.style.fontWeight = "700";

    //Add click event for the button so it can be clicked.
    RemoveAnimeBTN.addEventListener('click', function() {
        removeAnime();
    }, false);

    //Only happens if you are not logged into an account.
    if (isLoggedin) {
        //Create the element to display login text
        let LogINtext = document.createElement("span");

        LogINtext.innerHTML = " Please Login";
        LogINtext.style.color = "red";

        //Change the Remove Anime button to another color and disable it
        RemoveAnimeBTN.style.backgroundColor = "#cccccc"
        RemoveAnimeBTN.style.color = "#666666";
        RemoveAnimeBTN.disabled = true;

        //Place Remove Anime button before login text for correct placement
        btnLocation.appendChild(RemoveAnimeBTN);
        btnLocation.appendChild(LogINtext);
    }else if (topAnime) {
        console.log("top anime")
        btnLocation = topAnime
        btnLocation.append(RemoveAnimeBTN);
    }else {
        //If Logged in place the button as normal
        btnLocation.appendChild(RemoveAnimeBTN);
    }
})();