xx职业培训在线通知验证
2021-04-07 本文已影响0人
Chting
// ==UserScript==
// @name xx职业培训在线通知验证
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 自动通知该验证了
// @author chting
// @match https://px.class.com.cn/*
// @license GPL-3.0-or-later
// @run-at document-end
// ==/UserScript==
(function() {
var url;
var photo_url = 'https://px.class.com.cn/player/index/photo';
url = window.location.href; /* 获取完整URL */
if (url.indexOf(photo_url) != -1) {
console.log(111);
notice();
}
//发送通知
function notice() {
var roundtime = 1000;
for(var i = 1; i<3; i++){
setTimeout(function (){
console.log(222);
showMsgNotification();
}, roundtime);
roundtime+=5000;
}
}
function showMsgNotification() {
var title = '该验证咯!';
var msg = '请尽快完整验证!';
var Notification = window.Notification || window.mozNotification || window.webkitNotification;
console.log(Notification)
if (Notification) { /*支持桌面通知*/
if (Notification.permission == "granted") {
/*已经允许通知*/
var instance = new Notification(title, {
body: msg,
icon: "https://www.haolizi.net/skin/images/150x50_logo.png",
}); instance.onclick = function() {
$('body').css({'background': 'red'});
console.log('onclick');
instance.close();
};
instance.onerror = function() {
console.log('onerror');
};
instance.onshow = function() {
console.log('onshow');
};
instance.onclose = function() {
console.log('onclose');
};
} else {
/*第一次询问或已经禁止通知(如果用户之前已经禁止显示通知,那么浏览器不会再次询问Notification.requestPermission()方法无效) */
Notification.requestPermission(function(status) {
if (status === "granted") {
//用户允许
var instance = new Notification(title, {
body: msg,
icon: "https://www.haolizi.net/skin/images/150x50_logo.png"
}); instance.onclick = function() {
};
instance.onerror = function() {
};
instance.onshow = function() {
};
instance.onclose = function() {
};
} else {
alert('用户禁止');
return false
}
});
}
} else {
alert('不支持(IE等)');
}
}
})();