Last active
March 4, 2021 11:30
-
-
Save Ancientwood/6db068e5e3ff32415dc3b3d022602327 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let items = ['']; | |
let options = { | |
method: 'POST', | |
headers:{ | |
'Origin': 'https://mine.cubejoy.com', | |
'Referer': 'https://mine.cubejoy.com/JSJ/TaskList' | |
} | |
} | |
let interval = setInterval(function() { | |
fetch('https://mine.cubejoy.com/JSJSub/TaskList?pageIndex=1&pageSize=60',options) | |
.then(res => res.json()) | |
.then(json => { | |
console.log(new Date().toLocaleString()) | |
let notifications = json.result.list.map(feed => { | |
if (feed.status==2 && feed.residue!=0 && items.includes(feed.appName)){ | |
clearInterval(interval); | |
var notify_options = { | |
dir: "auto", // 文字方向 | |
body: "剩余数量:" + feed.residue, // 通知主体 | |
requireInteraction: true, // 不自动关闭通知 | |
icon: 'https:'+feed.vposter | |
}; | |
notifyMe(feed.appName, notify_options); | |
} | |
}) | |
}) | |
}, 120000); | |
function notifyMe(title, options) { | |
// 先检查浏览器是否支持 | |
if (!window.Notification) { | |
console.log('浏览器不支持通知'); | |
} else { | |
// 检查用户曾经是否同意接受通知 | |
if (Notification.permission === 'granted') { | |
var notification = new Notification(title, options); // 显示通知 | |
} else if (Notification.permission === 'default') { | |
// 用户还未选择,可以询问用户是否同意发送通知 | |
Notification.requestPermission().then(permission => { | |
if (permission === 'granted') { | |
console.log('用户同意授权'); | |
var notification = new Notification(title, options); // 显示通知 | |
} else if (permission === 'default') { | |
console.warn('用户关闭授权 未刷新页面之前 可以再次请求授权'); | |
} else { | |
// denied | |
console.log('用户拒绝授权 不能显示通知'); | |
} | |
}); | |
} else { | |
// denied 用户拒绝 | |
console.log('用户曾经拒绝显示通知'); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let items = ['','']; | |
let options = { | |
method: 'POST', | |
headers:{ | |
'Origin': 'https://mine.cubejoy.com', | |
'Referer': 'https://mine.cubejoy.com/JSJ/TaskList' | |
} | |
} | |
let interval = setInterval(function() { | |
fetch('https://mine.cubejoy.com/JSJSub/TaskList?pageIndex=1&pageSize=60',options) | |
.then(res => res.json()) | |
.then(json => { | |
console.log(new Date().toLocaleString()) | |
let notifications = json.result.list.map(feed => { | |
if (feed.status==2 && feed.residue!=0 && !items.includes(feed.appName)){ | |
clearInterval(interval); | |
var notify_options = { | |
dir: "auto", // 文字方向 | |
body: "剩余数量:" + feed.residue, // 通知主体 | |
requireInteraction: true, // 不自动关闭通知 | |
icon: 'https:'+feed.vposter | |
}; | |
notifyMe(feed.appName, notify_options); | |
} | |
}) | |
}) | |
}, 120000); | |
function notifyMe(title, options) { | |
// 先检查浏览器是否支持 | |
if (!window.Notification) { | |
console.log('浏览器不支持通知'); | |
} else { | |
// 检查用户曾经是否同意接受通知 | |
if (Notification.permission === 'granted') { | |
var notification = new Notification(title, options); // 显示通知 | |
} else if (Notification.permission === 'default') { | |
// 用户还未选择,可以询问用户是否同意发送通知 | |
Notification.requestPermission().then(permission => { | |
if (permission === 'granted') { | |
console.log('用户同意授权'); | |
var notification = new Notification(title, options); // 显示通知 | |
} else if (permission === 'default') { | |
console.warn('用户关闭授权 未刷新页面之前 可以再次请求授权'); | |
} else { | |
// denied | |
console.log('用户拒绝授权 不能显示通知'); | |
} | |
}); | |
} else { | |
// denied 用户拒绝 | |
console.log('用户曾经拒绝显示通知'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment