AoG Notifications

Notification script for Arena of Glory

目前为 2022-01-18 提交的版本。查看 最新版本

// ==UserScript==
// @name         AoG Notifications
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Notification script for Arena of Glory
// @author       Xortrox
// @match        https://play.arenaofglory.io/*
// @icon         https://play.arenaofglory.io/favicon.ico
// @grant        none
// @license MIT
// ==/UserScript==

(async function() {
    const icon = 'https://play.arenaofglory.io/favicon.ico';
    const gameTitle = 'Arena of Glory';

    /** How frequently to scan for changes on the website (in milliseconds) */
    const notifyTimerInterval = 60000;

    await hasPermission();

    setInterval(() => {
        const notificationElements = document.querySelectorAll('.adventure-done-component .go-button-wrapper .button label');

        /** We send notification only once if any adventures are claimable */
        if (notificationElements && notificationElements.length > 0) {
            for (let element of notificationElements) {
                const text = element.innerText;

                const textLower = text.toLowerCase();
                if (textLower.includes('claim') && !textLower.includes('claimed')) {
                    notify('You have at least one adventure to claim');
                }
                break;
            }
        }
    }, notifyTimerInterval);

    function notify(text) {
        hasPermission().then(function (result) {
            if (result === true) {
                let popup = new window.Notification(gameTitle, { body: text, icon: icon });
                popup.onclick = function () {
                    window.focus();
                }
            }
        });
    }

    function hasPermission() {
        return new Promise(function (resolve) {
            if ('Notification' in window) {
                if (window.Notification.permission === 'granted') {
                    resolve(true);
                } else {
                    window.Notification.requestPermission().then(function (permission) {
                        if (permission === 'granted') {
                            resolve(true);
                        } else {
                            resolve(false);
                        }
                    });
                }
            } else {
                resolve(true);
            }
        });
    }
})();

QingJ © 2025

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