Raw Source
cloudberrybob / MAL Hide future

// 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 future
// @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_future.meta.js
// @downloadURL https://openuserjs.org/install/cloudberrybob/Hide_future.user.js
// @version        1.4.1
// @license MIT
// @author         Bastvera <bastvera@gmail.com>, Cpt_mathix <fixed script>
// @namespace      https://greasyfork.org/users/16080
// ==/UserScript==



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

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 (isFuture(details) == true){
                element.parentNode.parentNode.style.display="none";
            }
        }
}

function isFuture(details){
    const regex = /[A-Z]{1}[a-z]{2}[\s]{1}[0-9]{4}/g;
            const found = details.match(regex);
    if (found == null){
        return true;
    }
            const month = found[0].substring(0,3);
            const year = Number(found[0].substring(4,8));
            var monthNumber = 0;
            switch(month) {
  case "Jan":
    monthNumber = 1;
    break;
  case "Feb":
    monthNumber = 2;
    break;
  case "Mar":
    monthNumber = 3;
    break;
  case "Apr":
    monthNumber = 4;
    break;
  case "May":
    monthNumber = 5;
    break;
  case "Jun":
    monthNumber = 6;
    break;
  case "Jul":
    monthNumber = 7;
    break;
  case "Aug":
    monthNumber = 8;
    break;
  case "Sep":
    monthNumber = 9;
    break;
  case "Oct":
    monthNumber = 10;
    break;
  case "Nov":
    monthNumber = 11;
    break;
  case "Dec":
    monthNumber = 12;
    break;
}
    const releaseDate = new Date(year, monthNumber, 0);
    const today = new Date();
    if (releaseDate > today)
        return true;
    else
        return false;
}