修复通知错误

This commit is contained in:
woohoo 2022-02-20 21:18:31 +08:00
parent 0619bf15df
commit e7b8d4961e

View File

@ -1,8 +1,8 @@
// ==UserScript== // ==UserScript==
// @lastmodified 202202201643 // @lastmodified 202202202117
// @name 芜湖助手 // @name 芜湖助手
// @namespace WOOH // @namespace WOOH
// @version 0.3.14 // @version 0.3.15
// @description 托恩,起飞! // @description 托恩,起飞!
// @author Woohoo[2687093] Sabrina_Devil[2696209] // @author Woohoo[2687093] Sabrina_Devil[2696209]
// @match https://www.torn.com/* // @match https://www.torn.com/*
@ -23,13 +23,18 @@
if (window.WHTRANS) return; if (window.WHTRANS) return;
window.WHTRANS = true; window.WHTRANS = true;
// 版本 // 版本
const version = '0.3.14'; const version = '0.3.15';
// 修改历史 // 修改历史
const changelist = [ const changelist = [
{ {
todo: true, todo: true,
cont: `翻译baza npc商店、imarket、imarket搜索结果`, cont: `翻译baza npc商店、imarket、imarket搜索结果`,
}, },
{
ver: '0.3.15',
date: '20220220',
cont: `修复通知错误`,
},
{ {
ver: '0.3.14', ver: '0.3.14',
date: '20220220', date: '20220220',
@ -325,12 +330,17 @@
// isPDA // isPDA
const isPDA = PDA_APIKey.slice(-1) !== '#'; const isPDA = PDA_APIKey.slice(-1) !== '#';
// 请求通知权限 // 请求通知权限
Notification.requestPermission().then(status => { try {
// 这将使我们能在 Chrome/Safari 中使用 Notification.permission Notification.requestPermission().then(status => {
if (Notification.permission !== status) { // 这将使我们能在 Chrome/Safari 中使用 Notification.permission
Notification.permission = status; if (Notification.permission !== status) {
} Notification.permission = status;
}); }
})
} catch (e) {
window.Notification = undefined;
log(e)
}
const titleDict = { const titleDict = {
'Home': '主页', 'Home': '主页',
@ -9026,7 +9036,7 @@ text-decoration:none;
} }
const notify_obj = add_notify(); const notify_obj = add_notify();
// 浏览器通知 // 浏览器通知
if (Notification.permission === 'granted' && sysNotify) { if (Notification && Notification.permission === 'granted' && sysNotify) {
const date_local_string = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}]\r` const date_local_string = `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}]\r`
new Notification('芜湖助手', {body: date_local_string + notify_contain.msgInnerText, requireInteraction: true}); new Notification('芜湖助手', {body: date_local_string + notify_contain.msgInnerText, requireInteraction: true});
} }