MyAnimeList(MAL) - Search Filter

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

目前為 2016-08-16 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// MAL Search Filter!
// version 1.2
// 2010-06-14
// Copyright (c) 2009, Bastvera <[email protected]>
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script. (Or Tampermonkey for chrome & Opera / Violentmonkey for Opera 12)
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "MAL Search Filter", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name           MyAnimeList(MAL) - Search Filter
// @namespace      http://thayanger.neostrada.pl
// @include        http://myanimelist.net/anime.php?*
// @include        http://myanimelist.net/manga.php?*
// @include        http://myanimelist.net/anime/genre/*
// @include        http://myanimelist.net/manga/genre/*
// @include        http://myanimelist.net/anime/producer/*
// @include        http://myanimelist.net/manga/magazine/*
// @exclude        http://myanimelist.net/anime.php?id=*
// @exclude        http://myanimelist.net/manga.php?id=*
// @description    This script hides search results that you already have on your list
// @version        1.3.0
// @author         Bastvera <[email protected]>, Cpt_mathix <fixed script>
// ==/UserScript==

//Anchor for checkbox
var	Anchor = document.evaluate(
    "//*[@id='content']/div[contains(@class,'normal_header')]",
    document,
    null,
    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
    null);

var AnchorLink = Anchor.snapshotItem(0);

if(AnchorLink !== null){

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

    var checkbox1 = document.createElement('input');
    checkbox1.type = 'checkbox';
    AnchorLink.appendChild(checkbox1);

    newElement = document.createElement('label');
    newElement.setAttribute('for','firstName');
    newElement.appendChild(document.createTextNode('Hide Search Results that you have on your list. (Show PTW:'));
    AnchorLink.appendChild(newElement);
    newElement.style.fontWeight="normal";
    newElement.style.fontSize="10px";
	
	var checkbox2 = document.createElement('input');
    checkbox2.type = 'checkbox';
    AnchorLink.appendChild(checkbox2);
	
	newElement = document.createElement('label');
    newElement.setAttribute('for','firstName');
    newElement.appendChild(document.createTextNode(')'));
    AnchorLink.appendChild(newElement);
    newElement.style.fontWeight="normal";
    newElement.style.fontSize="10px";

    //Anime list entries search
    var allElements = document.evaluate(
        "//a[contains(@class,'Lightbox_AddEdit button_edit')]",
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
	
	var ptwElements = document.evaluate(
        "//a[contains(@class,'Lightbox_AddEdit button_edit') and contains(@class,'plantowatch')]",
        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();
    }

    //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){
    for (var i = 0; i < elements.snapshotLength; i++){
        var EditLink = elements.snapshotItem(i);
		var PTW = showPTW ? !EditLink.classList.contains("plantowatch") : true;
        if (EditLink.parentNode.parentNode.parentNode.classList.contains("js-seasonal-anime") && PTW)
            EditLink.parentNode.parentNode.parentNode.style.display="none";
        else if (PTW) {
			EditLink.parentNode.parentNode.style.display="none";
		}
    }
}

function ShowDivs(showPTW, elements){
    for (var i = 0; i < elements.snapshotLength; i++){
        var EditLink = elements.snapshotItem(i);
		var PTW = showPTW ? !EditLink.classList.contains("plantowatch") : true;
        if (EditLink.parentNode.parentNode.parentNode.classList.contains("js-seasonal-anime") && PTW)
            EditLink.parentNode.parentNode.parentNode.removeAttribute('style');
        else if (PTW) {
			EditLink.parentNode.parentNode.removeAttribute('style');
		}
    }
}