html5-notification-api

Used htlm5 notification in GC

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         html5-notification-api
// @namespace    http://tampermonkey.net/
// @version      0.2
// @author       Nei
// @match        https://catwar.su/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @license      MIT
// @description  Used htlm5 notification in GC
// ==/UserScript==


(function() {
    'use strict';

    let intervalId;
    function notifyMe() {
        if(document.querySelector("#sek")){
            let arr =  document.querySelector("#sek").textContent.split(" ");
            let time;
            if(arr.length === 4){
                time = arr[0]*60*1000 + arr[2]*1000 - 500;
            }
            if(arr.length === 2){
                time = arr[0]*1000 - 500;
            }
            // intervalId = setTimeout(notice, time);
            document.querySelector("#cancel").addEventListener("click", clearInterval);
        }
    }
    $('#block_deys').bind("DOMSubtreeModified",function(){
        document.querySelectorAll(".dey").forEach((item) =>
                                                  item.addEventListener("click", intervalNotify)
                                                 )
    })
    $('#block_mess').bind("DOMSubtreeModified",function(){
        let time;
        if(document.querySelector("#sek")){
            let arr = document.querySelector("#sek").textContent.split(" ");
            if(arr.length === 4){
                time = arr[0]*60*1000 + arr[2]*1000 - 500;
            }
            if(arr.length === 2){
                time = arr[0]*1000 - 500;
            }
            console.log(time);
            if(time < 1500){
                notice();
            }
        }

    })



    function intervalNotify(){
        setTimeout(notifyMe, 500);

    }

    function clearInterval(){
        clearTimeout(intervalId);
    }

    function notice(){
        if (!("Notification" in window)) {
            alert("This browser does not support desktop notification");
        } else if (Notification.permission === "granted") {
            const notification = new Notification("Действие закончилось");

        } else if (Notification.permission !== "denied") {
            Notification.requestPermission().then((permission) => {
                if (permission === "granted") {
                    const notification = new Notification("Действие закончилось");
                    // …
                }
            });
        }
    }
})();