Aincrad Notification

Notice that your action is done

目前為 2021-03-05 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Aincrad Notification
// @namespace    https://itiscaleb.com/
// @version      0.3
// @description  Notice that your action is done
// @author       ItisCaleb
// @match        https://ourfloatingcastle.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var timeComplete;
    var token = window.localStorage.getItem('token2')
    function calTime(){
        fetch("https://api.ourfloatingcastle.com/api/profile", {
            "headers": {
                "token": token
            },
            "referrer": "https://ourfloatingcastle.com/",
            "body": null,
            "method": "GET",
        })
        .then(res=>res.json())
        .then(data=>{
            timeComplete = data.actionUntil
        });
    }
    function init(){
        if (Notification.permission === 'default' || Notification.permission === 'undefined') {
            Notification.requestPermission();
        }
        if (Notification.permission === 'denied'){
            console.log("請開啟通知才能作用")
            return
        }
        calTime()
    }
    setTimeout(init,1000)
    setInterval(()=>{
        if(!timeComplete) return
        let timeleft = timeComplete-Date.now()
        if(timeleft<=0){
           new Notification('你的浮游城已經完成動作!')
           timeComplete=null
        }
    },1000)
})();