NFT Panda Notifications

Notification script for NFT Panda

目前為 2022-01-18 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         NFT Panda Notifications
// @namespace    http://tampermonkey.net/
// @version      0.4
// @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);
            }
        });
    }
})();