MyAnimeList(MAL) - Search Filter

This script hides search results that you already have on your list

// MAL Search Filter!
// version 1.2
// 2010-06-14
// Copyright (c) 2009, Bastvera <bastvera@gmail.com>
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html

// ==UserScript==
// @name           MyAnimeList(MAL) - Search Filter
// @match          *://myanimelist.net/anime.php*
// @match          *://myanimelist.net/manga.php*
// @match          *://myanimelist.net/topanime.php*
// @match          *://myanimelist.net/topmanga.php*
// @match          *://myanimelist.net/anime/genre/*
// @match          *://myanimelist.net/manga/genre/*
// @match          *://myanimelist.net/manga/magazine/*
// @exclude        *://myanimelist.net/anime/producer/*
// @exclude        *://myanimelist.net/anime.php
// @exclude        *://myanimelist.net/manga.php
// @exclude        *://myanimelist.net/anime.php?id=*
// @exclude        *://myanimelist.net/manga.php?id=*
// @description    This script hides search results that you already have on your list
// @version        1.4.6
// @author         Bastvera <bastvera@gmail.com>, Cpt_mathix <fixed script>
// @license        GPL-2.0-or-later; http://www.gnu.org/licenses/gpl-2.0.txt
// @namespace      https://greasyfork.org/users/16080
// ==/UserScript==

//Anchor for checkbox
let anchor = document.querySelector("#content > div.normal_header") || document.querySelector("#content h2");

if(anchor !== null){
	injectCSS();

	//Element Placing
	var newElement;
	newElement = document.createElement('BR');
	anchor.appendChild(newElement);

	var checkbox1 = document.createElement('input');
	checkbox1.type = 'checkbox';
	checkbox1.className = 'filterbox';
	anchor.appendChild(checkbox1);

	newElement = document.createElement('label');
	newElement.setAttribute('for','firstName');
	var url = document.location.href;
	if (/myanimelist.net\/manga/.test(url)) {
		newElement.appendChild(document.createTextNode('Hide Search Results that you have on your list. (Show PTR:'));
	} else {
		newElement.appendChild(document.createTextNode('Hide Search Results that you have on your list. (Show PTW:'));
	}
	anchor.appendChild(newElement);
	newElement.style.fontWeight="normal";
	newElement.style.fontSize="10px";

	var checkbox2 = document.createElement('input');
	checkbox2.type = 'checkbox';
	checkbox2.className = 'filterbox';
	anchor.appendChild(checkbox2);

	newElement = document.createElement('label');
	newElement.setAttribute('for','firstName');
	newElement.appendChild(document.createTextNode(')'));
	anchor.appendChild(newElement);
	newElement.style.fontWeight="normal";
	newElement.style.fontSize="10px";

	//Anime list entries search
	var allElements = document.evaluate(
		"//a[(contains(@class,'js-anime-watch-status') or contains(@class, 'button_edit')) and not(contains(@class,'notinmylist'))]",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);

	var ptwElements = document.evaluate(
		"//a[contains(@class,'plantowatch') or contains(@class,'plantoread')]",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);

	//Get or Set status of checkbox
	var activate = true;
	var checkboxmem1 = (localStorage.getItem('checkboxmem1_search') === "true"); //Get checkbox status
	if(checkboxmem1 === null){
		checkboxmem1 = false;
		localStorage.setItem('checkboxmem1_search', checkboxmem1);
		checkbox1.checked = checkboxmem1;
		activate = false;
	}
	var checkboxmem2 = (localStorage.getItem('checkboxmem2_search') === "true"); //Get checkbox status PTW
	if(checkboxmem2 === null){
		checkboxmem2 = false;
		localStorage.setItem('checkboxmem2_search', checkboxmem2);
		checkbox2.checked = checkboxmem2;
		activate = false;
	}

	if (activate) {
		checkbox1.checked = checkboxmem1;
		checkbox2.checked = checkboxmem2;
		if(checkbox1.checked === true) {
			HideDivs(checkboxmem2, allElements);
		}
	}

	//Listener 1
	checkbox1.addEventListener('change',function () {

		if(checkbox1.checked === true){
			checkbox2.disabled = false;
			HideDivs(checkbox2.checked, allElements);
		}

		if(checkbox1.checked === false){
			checkbox2.disabled = true;
			ShowDivs(checkbox2.checked, allElements);
		}

		localStorage.setItem('checkboxmem1_search', checkbox1.checked);

	},false);

	//Listener 2
	checkbox2.addEventListener('change',function () {

		if(checkbox2.checked === true && checkbox1.checked === true){
			ShowDivs(false, ptwElements);
		}

		if(checkbox2.checked === false && checkbox1.checked === true){
			HideDivs(false, ptwElements);
		}

		localStorage.setItem('checkboxmem2_search', checkbox2.checked);

	},false);
}

function HideDivs(showPTW, elements){
    var gridLayout = !!document.querySelector(".js-block-list > .seasonal-anime-list");
    var tableLayout = !!document.querySelector(".js-block-list > table") || !!document.querySelector("table.top-ranking-table");
    var tableAnimeSearchLayout = !!document.querySelector(".js-block-list.js-categories-seasonal > table") && document.querySelector("h1").innerText.indexOf("Anime") > -1;

	for (var i = 0; i < elements.snapshotLength; i++) {
		var EditLink = elements.snapshotItem(i);
		var showIfPTW = showPTW ? !EditLink.classList.contains("plantowatch") && !EditLink.classList.contains("plantoread") : true;

		if ((gridLayout || tableAnimeSearchLayout) && showIfPTW) {
			EditLink.parentNode.parentNode.parentNode.style.display="none";
        } else if (tableLayout && showIfPTW) {
			EditLink.parentNode.parentNode.style.display="none";
		}
	}

    var article = document.querySelector("#content article");
    if (article) {
        article.style.display="none";
    }

    var ad = document.querySelector(".js-middle_ad.seasonal-middle");
    if (ad) {
        ad.style.display="none";
    }
}

function ShowDivs(showPTW, elements){
    var gridLayout = !!document.querySelector(".js-block-list > .seasonal-anime-list");
    var tableLayout = !!document.querySelector(".js-block-list > table") || !!document.querySelector("table.top-ranking-table");
    var tableAnimeSearchLayout = !!document.querySelector(".js-block-list.js-categories-seasonal > table") && document.querySelector("h1").innerText.indexOf("Anime") > -1;

	for (var i = 0; i < elements.snapshotLength; i++){
		var EditLink = elements.snapshotItem(i);
		var showIfPTW = showPTW ? !EditLink.classList.contains("plantowatch") && !EditLink.classList.contains("plantoread") : true;

		if ((gridLayout || tableAnimeSearchLayout) && showIfPTW) {
			EditLink.parentNode.parentNode.parentNode.removeAttribute('style');
        } else if (tableLayout && showIfPTW) {
			EditLink.parentNode.parentNode.removeAttribute('style');
		}
	}

    var article = document.querySelector("#content article");
    if (article) {
        article.removeAttribute('style');
    }
}

function injectCSS() {
	var css = `
input.filterbox {
  width: 13px;
  height: 13px;
  padding: 0;
  margin: 6px 2px 0 2px;
  vertical-align: bottom;
}
`;

	var style = document.createElement("style");
	style.type = "text/css";
	if (style.styleSheet){
		style.styleSheet.cssText = css;
	} else {
		style.appendChild(document.createTextNode(css));
	}

	document.documentElement.appendChild(style);
}