您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Greasy Fork is available in English.
This script is intended to work with @require only. Exposes an instance of the Notifications class of this script to window.UserScript.Notifications
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greatest.deepsurf.us/scripts/438798/1010205/UserScript%20Notification%20Framework.js
您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
- // ==UserScript==
- // @namespace Xortrox/UserScripts/Notifications
- // @name UserScript Notification Framework
- // @version 0.3
- // @description This script is intended to work with @require only. 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(title, text, icon) {
- this.hasPermission().then(function (result) {
- if (result === true) {
- let popup = new window.Notification(title, { 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();