我们在关闭机器再重启的时候,经常抢不到GPU,尽管可以订阅GPU通知,但微信的这种消息好像不通知,反正我的手机是不通知
所以写了个js脚本,实时检测GPU是否上线,若上线,弹出系统通知:
代码
function showMess(){
setTimeout(function () {
window.focus();
window.blur();
console.log('1:'+Notification.permission, window.Notification);
//如果支持window.Notification 并且 许可不是拒绝状态
if(window.Notification && Notification.permission !== "denied") {
//Notification.requestPermission这是一个静态方法,作用就是让浏览器出现是否允许通知的提示
Notification.requestPermission(function(status) {
console.log('2: '+status);
//如果状态是同意
if (status === "granted") {
var m = new Notification('收到信息', {
body: 'GPU上线了' //消息体内容
// icon:"images/img1.jpg" //消息图片
});
m.onclick = function () {//点击当前消息提示框后,跳转到当前页面
window.focus();
}
} else{
console.log('当前浏览器不支持弹出消息')
}
});
}
},1000)
};
function myFunction() {
document.querySelector("#app > div:nth-child(4) > div.data-list-common > div.page-content > div.content-header > div:nth-child(1) > button.el-button.el-button--default.el-button--small.refresh-btn").click()
var divElement = document.querySelector('.gpuTips');
console.log(123)
if(divElement.children.length > 0){
showMess();
}
};
var intervalId = setInterval(myFunction, 5000);
使用方法,在容器实例页面,将代码复制到控制台,回车即可。注意给网页系统通知权限