UserScript Notification Framework

Exposes an instance of the Notifications class of this script to window.UserScript.Notifications

اعتبارا من 19-01-2022. شاهد أحدث إصدار.

لا ينبغي أن لا يتم تثبيت هذا السكريت مباشرة. هو مكتبة لسكبتات لتشمل مع التوجيه الفوقية // @require https://update.greasyfork.org/scripts/438798/1010201/UserScript%20Notification%20Framework.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @namespace    Xortrox/UserScripts/Notifications
// @name         UserScript Notification Framework
// @version      0.2
// @description  Exposes an instance of the Notifications class of this script to window.UserScript.Notifications
// @author       Xortrox, Puls3
// @match        *
// @esversion: 6
// @license MIT
// ==/UserScript==

class Notifications {

    /** Should always be awaited before you use notifications. */
    askPermission() {
        return this.hasPermission();
    }

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

    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);
            }
        });
    }
}

if (!window.UserScript) {
    window.UserScript = {};
}
window.UserScript.Notifications = new Notifications();