NFT Panda Notifications

Notification script for NFT Panda

当前为 2021-12-01 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         NFT Panda Notifications
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Notification script for NFT Panda
// @author       Xortrox
// @match        https://game.nftpanda.space/*
// @icon         https://www.google.com/s2/favicons?domain=cryptureworld.com
// @grant        none
// @license MIT
// ==/UserScript==

(async function() {
    const icon = 'https://www.google.com/s2/favicons?domain=nftpanda.space';

    const notifyTimerInterval = 60000;

    await hasPermission();

    setInterval(() => {
        const notificationSpans = document.querySelectorAll('.one-slot span.button-name-in');

        /** We send notification only once if any panda's are inactive */
        if (notificationSpans && notificationSpans.length > 0) {
            for (let span of notificationSpans) {
                const text = span.innerText;

                if (text.toLowerCase().includes('send to adventure')) {
                    notify('You have at least one ready hero');
                }
                break;
            }
        }
    }, notifyTimerInterval);

    function notify(text) {
        hasPermission().then(function (result) {
            if (result === true) {
                let popup = new window.Notification('NFT PAnda', { 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);
            }
        });
    }
})();