MyAnimeList(MAL) - Anime/Manga Entries Compare

This script compares anime and manga entries from your userlists with entries from anime detail page and bold similar ones

当前为 2016-03-19 提交的版本,查看 最新版本

// ==UserScript==
// @name           MyAnimeList(MAL) - Anime/Manga Entries Compare
// @include        /^http://myanimelist\.net/(anime|manga)/*
// @include        /^http://myanimelist\.net/(anime|manga)\.php?id=*
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/reviews
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/userrecs
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/stats
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/characters
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/pics
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/moreinfo
// @exclude        /^http://myanimelist\.net/(anime|manga)/*/*/forum
// @description    This script compares anime and manga entries from your userlists with entries from anime detail page and bold similar ones
// @version        1.0.3
// @author         Cpt_mathix (this script is inspired on the script of Bastvera)
// @grant          GM_getValue
// @grant          GM_setValue
// @namespace https://gf.qytechs.cn/users/16080
// ==/UserScript==

init();

function init() {
    // get user
    var user = document.getElementsByClassName('header-profile-link')[0].textContent;
    
    // get header (shameless copy of bastvera's script)
    var AnchorLink;
    var allTextareas = document.getElementsByTagName('H2');
    for(var element in allTextareas){
        if(allTextareas[element].textContent=="EditRelated Anime")
            AnchorLink = allTextareas[element];
    }
    var feedbackElement;
    if (AnchorLink != null) {
        feedbackElement = document.createElement('BR');
        AnchorLink.appendChild(feedbackElement);
        feedbackElement = document.createElement('label');
        feedbackElement.setAttribute('for','firstName');
        feedbackElement.appendChild(document.createTextNode('Entries Compare in Process. Please wait...'));
        AnchorLink.appendChild(feedbackElement);
        feedbackElement.style.fontWeight="normal";
        feedbackElement.style.fontSize="10px";
    }
    
    activateScript(user, feedbackElement);
}

function activateScript(user, feedbackElement) {
    // check if we have/need to refresh our userlist
    var animelist;
    var mangalist;
    if(isUserListsUpToDate(user)) {
        feedbackElement.textcontent = "Processing cached userlists...";
        animelist = getUserList("anime");
        mangalist = getUserList("manga");
    } else {
        feedbackElement.textcontent = "Downloading userlists...";
        animelist = loadUserList(user, "anime");
        mangalist = loadUserList(user, "manga");
    }

    // get Anime/Manga Entries on current page
    var allElements;
    allElements = document.evaluate(
        '//a[@href]',
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
    
    for (var i = 0; i < allElements.snapshotLength; i++){
        var linkEl= allElements.snapshotItem(i);
        var href = linkEl.href;
        
        feedbackElement.textContent = "Comparing entries..."
        // compare Anime Entries with your list
        if (/http:\/\/myanimelist\.net\/anime\/\d+\/\D*/.test(href)) {
            var animeid = href.match(/\d+/g)[0];
            var self = animeid.search(document.location.href.match(/\d+/g)[0]);
            if (self == -1 && haveListHit(animelist, animeid, "anime")) {
                linkEl.style.fontWeight="bold";
            }
        }
        
        // compare Manga Entries with your list
        if (/http:\/\/myanimelist\.net\/manga\/\d+\/\D*/.test(href)) {
            var mangaid = href.match(/\d+/g)[0];
            var self = mangaid.search(document.location.href.match(/\d+/g)[0]);
            if (self == -1 && haveListHit(mangalist, mangaid, "manga")) {
                linkEl.style.fontWeight= "bold";
            }
        }
        feedbackElement.style.display = "none";
    }
}

function isUserListsUpToDate(user) {
    var rssAnime = loadRSS(user, "rw");
    var rssManga = loadRSS(user, "rm");
    var lastUpdateA = rssAnime.getElementsByTagName('pubDate')[0].textContent;
    var lastUpdateM = rssManga.getElementsByTagName('pubDate')[0].textContent;
    var cachedDateA = getCacheDate("A");
    var cachedDateM = getCacheDate("M");
    if (lastUpdateA == cachedDateA && lastUpdateM == cachedDateM)
        return true;
    else {
        GM_setValue('AEC_CacheDateA', lastUpdateA);
        GM_setValue('AEC_CacheDateM', lastUpdateM);
        return false;
    }
}

function getUserList(type) {
    var object = JSON.parse(GM_getValue('AEC_MAL' + type + 'list')); // AEC = Anime Entries Compare
    if (object)
        return object;
    else
        console.log("failed to get lists");
}

function getCacheDate(type) {
    return GM_getValue('AEC_CacheDate' + type); 
}

function loadUserList(user, type) {
    // get userlist
    var xhr = new XMLHttpRequest();
    var url = 'http://myanimelist.net/malappinfo.php?u=' + user + '&status=all&type=' + type + '';
    xhr.open("GET", url, false);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.send();
    var xmlDocument = xhr.responseXML;
    
    // create a list that I can cache
    var rawList = xmlDocument.getElementsByTagName('series_' + type + 'db_id');
    var list = [];
    for (var i = 0; i < rawList.length; i++)
        list.push(rawList[i].textContent);
    GM_setValue('AEC_MAL' + type + 'list', JSON.stringify(list));
    return list;
}

function loadRSS(user) {
    var xhr = new XMLHttpRequest();
    var url = 'http://myanimelist.net/rss.php?type=rw&u=' + user;
    xhr.open("GET", url, false);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.send();
    var xmlDocument = xhr.responseXML;
    return xmlDocument;
}

function haveListHit(list, animeid, type) {
    for(var k = 0; k < list.length; k++) {
        if (list[k] == animeid) {
            return true;
        }
    }
    return false;
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址