Raw Source
cloudberrybob / MAL Hide ongoing

// 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           MAL Hide ongoing
// @include        *://myanimelist.net/anime.php?*
// @include        *://myanimelist.net/manga.php?*
// @include        *://myanimelist.net/topanime.php?*
// @include        *://myanimelist.net/topmanga.php?*
// @include        *://myanimelist.net/anime/genre/*
// @include        *://myanimelist.net/manga/genre/*
// @include        *://myanimelist.net/anime/producer/*
// @include        *://myanimelist.net/anime/season*
// @include        *://myanimelist.net/manga/magazine/*
// @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
// @updateURL https://openuserjs.org/meta/cloudberrybob/Hide_ongoing.meta.js
// @downloadURL https://openuserjs.org/install/cloudberrybob/Hide_ongoing.user.js
// @license MIT
// @version        1.4.2
// @author         Bastvera <bastvera@gmail.com>, Cpt_mathix <fixed script>
// @namespace      https://greasyfork.org/users/16080
// ==/UserScript==


if (window.location.href.includes("season") || window.location.href.includes("genre")) {
    console.log("start");
var elements = document.evaluate(
		"//span[(contains(@class,'publishing'))]",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);
HideDivs(elements);
}
else {


var elements2 = document.evaluate(
		"//a[(contains(@class,'js-anime-watch-status') or contains(@class, 'button_edit'))]",
		document,
		null,
		XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
		null);
hideFuture(elements2);
}

function HideDivs(elements){

    console.log("start2");
    console.log(elements.snapshotLength);
        for (var i = 0; i < elements.snapshotLength; i++) {
            var element = elements.snapshotItem(i);
            element.parentNode.parentNode.parentNode.parentNode.style.display="none";
        }
}

function hideFuture(elements){
        for (var i = 0; i < elements.snapshotLength; i++) {
            var element = elements.snapshotItem(i);
            var details = element.parentNode.parentNode.getElementsByClassName("title")[0].getElementsByClassName("detail")[0].getElementsByClassName("information")[0].innerHTML;
            if (isOngoing(details) == true){
                element.parentNode.parentNode.style.display="none";
            }
        }
}

function isOngoing(details){
    const regex = /[A-Z]{1}[a-z]{2}[\s]{1}[0-9]{4}/g;
            const found = details.match(regex);
    if (found != null && found.length == 1){
        return true;
    }
    else
        return false;
}