Greasy Fork is available in English.

AnimeList

Список аниме-сериалов

Устаревшая версия на 05.06.2019. Перейти к последней версии.

// ==UserScript==
// @name         AnimeList
// @version      1.3
// @author       Fenion
// @description  Список аниме-сериалов
// @match        https://online.anidub.com/*
// @require      https://unpkg.com/sweetalert/dist/sweetalert.min.js
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js
// @namespace    https://greasyfork.org/ru/scripts/383705-animelist
// ==/UserScript==
var debug = false;

var start = Date.now();
$(function(){
    var imgMeta = getMeta('og:image');
    var animes = localStorage.getItem('animes');
    var url = window.location.href;
    var restr = 100;

    $('body').append('<div id="al"></div>');
    $('#al').append('<a href="javascript: void(0)" class="mbtn"></a>');
    $('.mbtn').css({
        'width': '40px',
        'height': '40px',
        'opacity': '0.3',
        'position': 'fixed',
        'bottom': '50px',
        'left': '150px',
        'display': 'inline',
        'z-index': '500',
        'text-indent': '-9999px',
        'background': 'url("https://raw.githubusercontent.com/Fenion/AnimeList/master/icon.png") no-repeat'
    });
    $('body').append('<div id="anime-list"><div class="q"></div><div class="list"><div class="animes"><a id="close" href="javascript: void(0)">X</a><h1>Список просматриваемых аниме</h1><hr></div></div></div>');
    $('body').append('<style>a.addbtns {color: #fff; text-decoration: none; user-select: none; background: rgb(212,75,56); padding: .1em 1.5em; outline: none;}a.addbtns:hover { background: rgb(232,95,76); } a.addbtns:active { background: rgb(152,15,0); } .swal-overlay{background-color:rgba(43, 165, 137, 0.45)} .cnt {text-align: center;} .q {display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(43, 165, 137, 0.45); opacity: 0.6; z-index: 150;} .list {display: none; position: fixed; top: 0; right: 0; bottom: 0; left: 0; text-align: center; padding: 20px; z-index: 1000;} .animes { display: none; border-radius: 5px; width: 100%; overflow-y: auto; max-height: 80%; min-width: 200px; position: relative; background-color: #FAFAFA; z-index: 300; padding: 60px 0;} .anime{position: relative; width: 100%; margin: 0px; padding-box: 0px; z-index: 400} .img{position: relative; width: 100%; height: 200px; padding: 0px;} .kartinka{position: absolute; height: 200px; left: 10px;} .nme{position: absolute; top: 10%; left: 200px; width: 80%; } .del{position: absolute; top: 45%; right: 10%; width: 115px; height: 15px; color: #fff; text-decoration: none; user-select: none; background: rgb(212,75,56); padding: .7em 1.5em; outline: none;} ::-webkit-scrollbar {width: 12px;} ::-webkit-scrollbar-track {-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3); border-radius: 10px;} ::-webkit-scrollbar-thumb {border-radius: 10px; -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);} #close{position: fixed; top: 30px; right: 40px; z-index: 1000; color: #fff; text-decoration: none; user-select: none; background: rgb(255, 82, 82); padding: .1em .5em; outline: none;} .srs{position: absolute; width: 100%; bottom: 20%;} .red{position: absolute; right: 38px; bottom: 10%; color: #fff; text-decoration: none; user-select: none; background: rgb(255,165,0); padding: .01em .3em; outline: none;} .plus{position: absolute; bottom: 10%; color: #fff; text-decoration: none; user-select: none; background: rgb(0,155,0); padding: .1em .5em; outline: none;} .min{position: absolute; bottom: 10%; left: 5%; color: #fff; text-decoration: none; user-select: none; background: rgb(212,75,56); padding: .1em .6em; outline: none;} .seriesbtn{position: relative; width: 40px; left: 49%; bottom: 19px;}</style>');
    var wrap = $('#anime-list');
    var btn = $('.mbtn');
    var modal = $('.q, .list, .animes');

    function getMeta(metaName) {
        const metas = document.getElementsByTagName('meta');
        for (let i = 0; i < metas.length; i++) {
            if (metas[i].getAttribute('property') === metaName) {
                return metas[i].getAttribute('content');
            }
        }
        return '';
    }

    function no_anime() {
        swal({
            icon: 'error',
            text: 'В вашем списке ещё нет аниме!',
            button: "Ok!",
        });
    }

    function addAnime() {
        if (animes >= restr) {
            swal({
                icon: 'error',
                text: 'Список аниме заполнен!',
                button: 'Ok!',
            });
        } else {
            let title = getMeta('og:title'),
                r = title.match(/[^[\]]+(?=])/g).join(),
                t = r.split(' ');
            for (var f = 1; f <= restr; f++) {
                let src = localStorage.getItem('src' + f);
                if (src == null) {
                    localStorage.setItem('animes', ++animes);
                    localStorage.setItem('src' + f, url);
                    localStorage.setItem('series' + f, '0');
                    let s = localStorage.getItem('series' + f);
                    $('.animes').append('<div id="' + f + '" class="anime"><a href="' + url + '"><h3 class="srs">Просмотрено: ' + s + ' из ' + Number(t[0]) + '</h3><div class="img"><img src="' + imgMeta + '" class="kartinka" width="160"></img></div><div class="nme"><h2>' + title + '</h2></div></a><a href="javascript: void(0)" class="del" id="' + f + '">Удалить</a><div class="seriesbtn"><a href="javascript: void(0)" class="red" id="' + a + '">&#9998;</a><a href="javascript: void(0)" id="' + f + '" class="plus">+</a><a href="javascript: void(0)" id="' + f + '" class="min" style="display: none;">-</a></div><hr></div>');
                    swal({
                        icon: 'success',
                        text: 'Аниме добавлено в список!',
                        button: 'Ok!',
                    });
                    if(debug){
                        console.log('%c' + title + ' added to the list successfully!', 'background: green; color: white;');
                    }
                    break;
                }
            }
        }
    }

    function delAnime(num) {
        localStorage.removeItem('src' + num);
        localStorage.removeItem('series' + num);
        localStorage.setItem('animes', --animes);
        let id = ('#' + num);
        $('.anime' + id).remove();
        swal({
            icon: 'success',
            text: 'Аниме удалено из списка!',
            button: 'Ok!'
        });
        if(debug){
            console.log('%cAnime #' + num + ' deleted succesfully!', 'background: green; color: white;');
        }
    }
    $(document).on("click", ".del", function() {
        let id = $(this).attr("id");
        delAnime(id);
    });

    function ajaxReq(a, q) {
        $.ajax({
            url: q,
            async: true,
            success: function(data, textStatus, jqXHR) {
                var title = $(data).filter("meta[property='og:title']").attr("content"),
                    img = $(data).find("meta[property='og:image']").attr("content"),
                    series = title.match(/[^[\]]+(?=])/g).join(),
                    h = series.split(' '),
                    sP = '',
                    sM = '';
                let s = localStorage.getItem('series' + a);
                if(Number(s) >= Number(h[0])){
                    sP = 'style = "display:none;"';
                    sM = 'style = "display:auto;"';
                } else if(s == 0) {
                    sM = 'style = "display:none;"';
                    sP = 'style = "display:auto;"';
                } else if(s == 1) {
                    sM = 'style = "display:none;"';
                    sP = 'style = "display:auto;"';
                } else {
                    sP = 'style = "display:auto;"';
                    sM = 'style = "display:auto;"';
                }
                $('.animes').append('<div id="' + a + '" class="anime"><h3 class="srs">Просмотрено: ' + s + ' из ' + Number(h[0]) + '</h3><a href="' + q + '"><div class="img"><img src="' + img + '" class="kartinka" width="160"></img></div><div class="nme"><h2>' + title + '</h2></div></a><a href="javascript: void(0)" class="del" id="' + a + '">Удалить</a><div class="seriesbtn"><a href="javascript: void(0)" class="red" id="' + a + '">&#9998;</a><a href="javascript: void(0)" id="' + a + '" class="min" '+ sM +'>-</a><a href="javascript: void(0)" id="' + a + '" class="plus" '+ sP +'>+</a></div><hr></div>');
                if(debug){
                    console.log('%cCool! Ajax request sent successfully! ['+ jqXHR.status +']', 'background: green; color: white;');
                }
            },
            error: function(jqXHR) {
                if(debug){
                    console.log('%cOops! Something went wrong with Ajax! ['+ jqXHR.status +']', 'background: red; color: white;');
                }
            }
        });
    }
    if (!animes) {
    } else if (animes == 0) {
    } else if (animes > 0) {
        for (var a = 1; a <= restr; a++) {
            var q = localStorage.getItem('src' + a);
            if (q == null) {} else {
                ajaxReq(a, q);
            }
        }
    }
    if (!imgMeta) {} else {
        $('.poster_img').append('<a href="javascript: void(0)" class="addbtns">Добавить в список</a>');
    }
    if (!animes) {
        localStorage.setItem('animes', 0);
    }
    function redSeries(ser, aydi){
        var a = $('#' + aydi + '.anime').find(".srs"),
            b = $(a).html().split(' ');
        let p = $('#' + aydi + '.anime').find('.plus'),
            m = $('#' + aydi + '.anime').find('.min');
        if(!ser){
        } else if(ser > Number(b[3])) {
        } else if (ser < 0) {
        } else if(Number(ser)){
            let c = b[1] = [ser],
                d = b.join(' ');
            localStorage.setItem('series' + aydi, ser);
            $(a).text(d);
            if(debug){
                console.log(d);
                console.log(ser);
                console.log(Number(b[1]));
            }
            if(c >= b[3]){
                p.css({'display':'none'});
                m.css({'display':'auto'});
            } else if(c == 0) {
                m.css({'display':'none'});
                p.css({'display':'auto'});
            } else if(c == 1) {
                m.css({'display':'none'});
                p.css({'display':'auto'});
            } else {
                p.css({'display':'block'});
                m.css({'display':'block'});
            }
        } else {
            alert('Пожалуйста введите число!');
        }
    }
    $('.addbtns').click(addAnime);
    btn.click(function() {
        if (animes == 0) {
            no_anime();
        } else if (!animes) {
            no_anime();
        } else {
            modal.fadeIn();
        }
    });
    $('#close').click(function() {
        modal.fadeOut();
    });
    $(document).on('click','.red' ,function() {
        let id = $(this).attr('id');
        swal('Введите кол-во просмотренных серий', {
            content: "input",
        }).then((value) => {
            redSeries(value, id);
        });
    });
    $(document).on('click', '.plus', function(){
        let id = $(this).attr('id'),
            d = localStorage.getItem('series' + id),
            v = ++d;
        redSeries(v, id);
    });
    $(document).on('click', '.min', function(){
        let id = $(this).attr('id'),
            d = localStorage.getItem('series' + id),
            v = --d;
        redSeries(v, id);
    });
    var end = Date.now();
    var time = end - start;
    if(debug){
        console.log('%cScript started in ' + time + 'ms', 'background: green; color: white;');
    }
});