// ==UserScript== // @name 天数倒计时 // @namespace https://bbs.tampermonkey.net.cn/ // @version 0.1 // @description 每天提醒你距离目标日期的天数 // @author Exisi // @crontab * 7-23 once * * // @grant GM_notification // @grant GM_getValue // ==/UserScript== /* ==UserConfig== 设置: Notice: title: 标题 description: 请输入通知标题 Year: title: 年 description: 请输入年份,默认当前年份 Month: title: 月 description: 请输入年份,默认当前月份 Day: title: 日 description: 请输入天数,默认无 ==/UserConfig== */ function getTotalDay(year, month) { let date = new Date(year, month, 0); return date.getDate(); } function getDiffDay(date, aim_date){ let diff = (aim_date - date) / 1000 / 3600 / 24; return diff; } return new Promise((resolve, reject) => { let date = new Date(); let aim_date = new Date(); let current = { year : date.getFullYear(), month : date.getMonth() + 1, day : date.getDay(), } let target = { notice : GM_getValue('设置.Notice', '天数倒计时'), year : GM_getValue('设置.Year', current.year), month : GM_getValue('设置.Month', current.month), day : GM_getValue('设置.Day', false), } let over = { year : target.year >= current.year, month : ( 0 < target.year <= 12 ) && ( target.year >= current.year ), day : ( 0 < target.day <= getTotalDay(target.year, target.month) ) && ( target.day >= current.day ), } if (over.year && over.month && over.day) { aim_date.setFullYear(target.year, target.month - 1 , target.day); let diff = getDiffDay(date, aim_date); GM_notification({ title : target.notice, text : '剩余天数:'+ diff, timeout : 3000, }); resolve(); } else { resolve('倒计时完成,自动停止'); } });