BetterAnimeWorld

Migliora AnimeWorld

目前為 2020-11-19 提交的版本,檢視 最新版本

// ==UserScript==
// @name         BetterAnimeWorld
// @namespace    https://pizidavi.altervista.org/
// @version      1.5.4
// @description  Migliora AnimeWorld
// @author       pizidavi
// @require      https://cdn.jsdelivr.net/gh/soufianesakhi/node-creation-observer-js@edabdee1caaee6af701333a527a0afd95240aa3b/release/node-creation-observer-latest.min.js
// @include      https://www.animeworld.*
// @run-at       document-body
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const PAGE_TITLE = document.title;

    NodeCreationObserver.onCreation('.widget.watchlist', function (element) {
        S('.cover-profilo-aw').style.display = 'none';
        S('#no-comments').style.display = 'none';
        //S('.menu-profile').style.display = 'none';
        S('.menu-profile > a:nth-child(2)').href = '/watchlist?sort=a-z';

        window.onload = function() {
            setTimeout(function() {
                element.querySelector('[data-name="watching"]').click();
            }, 50);
        };
    });

    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 = '/watchlist?sort=a-z';
        element.querySelector('div > ul > li:nth-child(4) > a').textContent = 'Notifiche';
        element.querySelector('div > ul > li:nth-child(4) > a').href = '/notifications';

        setNotify();
        setInterval(function() {
            getNotify();
        }, 2*60*1000); // 2 minuti
    });

    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);
                var r = S('#controls .resize');
                if(r.textContent.includes("Espandi")) r.click();

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

        document.addEventListener('keydown', function(e) {
            var bg = document.querySelector('#light-mode-background')
            if (bg && e.key == 'Escape') {
                console.log('click')
                bg.click(); }
        });
    }

    if(location.pathname.includes('/notifications')) {
        NodeCreationObserver.onCreation('#delete-all', function (element) {
            var parentDiv = element.parentElement;
            var 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) {
                            var action = e.querySelector('.actions i.delete-clickable-icon');
                            action.click();
                        });
                    }
                });
            };
            parentDiv.appendChild(button);
            element.remove();
        });
    }

    // ------- Function -------
    function getNotify() {
        request('GET', '/request-serie', function(data) {
            var html = document.createElement('html'); html.innerHTML = data;
            S('#notification > ul').innerHTML = html.querySelector('#notification > ul').innerHTML;
            setNotify();

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

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

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

    function addStyle(CSS) {
        var style = document.createElement('style');
        style.innerText = CSS;
        document.head.appendChild(style);
    }
    function S(selector) {
        var element = document.querySelector(selector);
        return element != null ? element : document.createElement('div'); }

})();

QingJ © 2025

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