BetterAnimeWorld

Migliora AnimeWorld

11.12.2021 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         BetterAnimeWorld
// @namespace    https://pizidavi.altervista.org/
// @icon         https://static.animeworld.tv/assets/images/favicon/android-icon-192x192.png
// @description  Migliora AnimeWorld
// @author       pizidavi
// @version      1.6.2
// @copyright    2021, PIZIDAVI
// @license      MIT
// @require      https://cdn.jsdelivr.net/gh/soufianesakhi/node-creation-observer-js@edabdee1caaee6af701333a527a0afd95240aa3b/release/node-creation-observer-latest.min.js
// @match        https://www.animeworld.tv/*
// @run-at       document-body
// @grant        GM_addStyle
// @grant        GM_xmlhttpRequest
// @grant        window.onurlchange
// ==/UserScript==

(function() {
    'use strict';

    const PAGE_TITLE = document.title;

    NodeCreationObserver.onCreation('#sign > div.signed', function (element) {
        addStyle('#header .head #sign .signed, #header .head #sign .signin { width: unset !important; }');
        element.querySelector('div > ul > li:nth-child(3) > a').href += '?folder=1&sort=2';

        element.querySelector('div > ul > li:nth-child(4) > a').textContent = 'Notifiche';
        element.querySelector('div > ul > li:nth-child(4) > a').href = '/notifications';
    });

    NodeCreationObserver.onCreation('#notification', function (element) {
        setNotify();
        setInterval(function() {
            getNotify();
        }, 2*60*1000); // 2 minuti

        if (location.pathname.includes('/play/') && window.onurlchange !== undefined) {
            window.addEventListener('urlchange', (info) => {
                setNotify();
            });
        }
    });

    NodeCreationObserver.onCreation('div.menu-profile', function (element) {
        element.querySelector('a.pulsante-profilo-tabs:nth-child(2)').href += '?folder=1&sort=2';
        if(location.pathname.includes('/watchlist')) {
            document.querySelector('.cover-profilo-aw').style.display = 'none';
        }
    });

    if(location.pathname.includes('/play/')) {
        NodeCreationObserver.onCreation('#player .cover, div.server ul a, #controls > div.prevnext', function (element) {
            element.addEventListener('click', function() {
                window.scrollTo(0, 133);
                const r = document.querySelector('#controls .resize');
                if(r.textContent.includes('Espandi'))
                    r.click();

                setTimeout(function() {
                    document.querySelector('#controls .light').click();
                    document.cookie = 'expandedPlayer=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
                }, 700);
            });
        });
    }

    if(location.pathname.includes('/notifications')) {
        NodeCreationObserver.onCreation('#delete-all', function (element) {
            const parentDiv = element.parentElement;
            const button = element.cloneNode();
            button.id = 'delete-read-all';
            button.innerHTML = '<i class="fas fa-trash"></i> Cancella tutte le notifiche "lette"';
            button.onclick = function() {
                Swal.fire({
                    title: 'Vuoi davvero cancellare tutte le notifiche lette?',
                    icon: 'question',
                    showCancelButton: true,
                    confirmButtonColor: 'rgb(165, 220, 134)',
                    cancelButtonColor: 'rgb(221, 51, 51)',
                    confirmButtonText: 'Si',
                    cancelButtonText: 'No',
                }).then((result) => {
                    if (result.value) {
                        document.querySelectorAll('.profile-page .row .widget:nth-child(2) li.is-notification-read').forEach(function(e, i) {
                            e.querySelector('.actions i.delete-clickable-icon').click();
                        });
                    }
                });
            };
            parentDiv.appendChild(button);
            element.remove();
        });
    }

    NodeCreationObserver.onCreation('#account-delete', function (element) {
        element.parentElement.remove();
    });


    // ------- Function -------
    function getNotify() {
        request({
            url: '/request-serie',
            success: function(data) {
                const html = document.createElement('html'); html.innerHTML = data;
                document.querySelector('#notification > ul').innerHTML = html.querySelector('#notification > ul').innerHTML;
                setNotify();

                document.querySelectorAll('#notification > ul > li[data-id]').forEach(function(li, index) {
                    const span = li.querySelector('.header-notification-read');
                    span.addEventListener('click', function(e) {
                        e.preventDefault(); e.stopPropagation();
                        request({
                            url: '/api/notifications/open/'+li.getAttribute('data-id'),
                            success: function(data) {
                                li.remove();
                                setNotify();
                            }
                        });
                    });
                });
            }
        });
    }

    function setNotify() {
        const notify = document.querySelector('#notification-menu div.number-notify > span');
        notify.textContent = document.querySelectorAll('#notification > ul > li[data-id]').length;
        document.title = (parseInt(notify.textContent) ? notify.textContent+' - ' : '') + PAGE_TITLE;
    }

    function request(options) {
        const onreadystatechange = function() {
            if (this.readyState === 4 && (this.status == 200 || this.status == 201)) {
                options.success(this.responseText);
            } else if (this.readyState === 4) {
                console.warn('%cBetterAnimeWorld%c - Errore nella richiesta', 'color:red;font-size:14px;', '');
            }
        };
        if (typeof GM_xmlhttpRequest != 'undefined') {
            options.onload = onreadystatechange;
            GM_xmlhttpRequest(options);
        } else {
            const xhttp = new XMLHttpRequest();
            xhttp.open(options.method || 'GET', options.url);
            xhttp.onreadystatechange = onreadystatechange;
            xhttp.send();
        }
    }

    function addStyle(CSS) {
        if (typeof GM_addStyle != 'undefined') {
            GM_addStyle(CSS);
        } else {
            const style = document.createElement('style');
            style.innerText = CSS;
            document.head.appendChild(style);
        }
    }

})();