AU Global Fix

Will fix many things that are wrong with AnimeUltima.io

Від 03.03.2016. Дивіться остання версія.

// ==UserScript==
// @name         AU Global Fix
// @namespace    AUVTF
// @version      1.0.1
// @description  Will fix many things that are wrong with AnimeUltima.io
// @author       Jopitan
// @match        http://www.animeultima.io/*
// @grant        none
// @require      http://code.jquery.com/jquery-latest.js
// ==/UserScript==

'use strict';
(function($) {
    $(document).ready(function() {
        var matches = window.location.pathname.match('/([a-zA-Z]+)');
        if(matches === null) {
            $('div.nr-top a').on('click', function() {
                var rel = $(this).attr('rel');
                $('div.nr-top a').removeClass('nr-toggle-view-active');
                $(this).addClass('nr-toggle-view-active');
                $('.switch').hide();
                $('.switch.' + rel).show();
            });
            $('<div id="calendar-view" style="display: none;" class="switch calendar"></div>')
                .insertAfter('#new-episodes');
            $('#new-episodes').addClass('switch default');
            $('#calendar-view').css({
                'width': '100%',
                'height': '580px'
            });
            $.get('/ajax.php?method=newrelease_calendarview&standalone=1')
                .done(function(html) {
                    var table = $.parseHTML(html)[7];
                    $('#calendar-view').html(table);
                });
            $('#new-episodes a').each(function(i, obj) {
                var href = $(obj).attr('href');
                $.get(href)
                    .done(function(data) {
                        var html = $(data);
                        var link = html.find('#pembed iframe').attr('src');
                        handleThumbnail(i, obj, link);
                    });
            });
        } else if(typeof matches[1] != 'undefined') {
            var path = matches[1];
            if(path === 'watch') {
                var favoriteObj = $('div.inline-top a:contains(Add to Favorites)');
                favoriteObj.addClass('ajaxCall').attr('data-func', 'handleFavorite');
            }
        }
        
        $('.ajaxCall').on('click', function() {
           var href = $(this).attr('href');
           var func = $(this).attr('data-func');
           $.get(href)
            .done(function(data) {
                eval('' + func + '("' + data + '");');
            });
           return false; 
        });
    });
    
    function handleThumbnail(index, parent, iframeUrl) {
        var par = $(parent);
        var href = par.attr('href');
        var cacheUrl = getCacheImgUrl(href);
        if(cacheUrl !== null) {
            par.find('img').attr('src', cacheUrl);
        } else {
            $.get('http://topdev.xyz/thumb.php?id=' + index + '&url=' + encodeURIComponent(btoa(iframeUrl)))
                .done(function(xhr) {
                    var img = xhr.data[0];
                    par.find('img').attr('src', img);
                    setCacheImgUrl(href, img);
                });
        }
    }
    
    function getCacheImgUrl(id) {
        var storage = JSON.parse(localStorage.getItem('imageCache'));
        if(storage === null)
            return null;
        if(id in storage)
            return storage[id];
        else
            return null;
    }
    
    function setCacheImgUrl(id, url) {
        var cacheStorage = JSON.parse(localStorage.getItem('imageCache'));
        if(cacheStorage === null)
            cacheStorage = {};
        cacheStorage[id] = url;
        localStorage.setItem('imageCache', JSON.stringify(cacheStorage));
    }
            
    function handleFavorite(data) {
        alert(data);
    }
})(jQuery);