BetterAnimeWorld

Migliora AnimeWorld

目前为 2020-08-31 提交的版本。查看 最新版本

// ==UserScript==
// @name         BetterAnimeWorld
// @namespace    https://pizidavi.altervista.org/
// @version      1.5.1
// @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://*.animeworld.*
// @grant        GM_addStyle
// @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) {
        GM_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';

        setNotify();
        setInterval(function() {
            getNotify();
        }, 3*60*1000); // 3 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);
            });
        });
    }

    // ------- 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) {
                value.addEventListener('click', function() {
                    var li = this;
                    var id = li.getAttribute('data-id');
                    request('GET', '/api/notifications/open/'+id, function(data) {
                        li.remove();
                        setNotify();
                    });
                });
            });
        });
    }

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

    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 S(selector) {
        var element = document.querySelector(selector);
        return element != null ? element : document.createElement('div'); }

})();

QingJ © 2025

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