天数正计时
// ==UserScript==
// @name 天数正计时
// @namespace https://bbs.tampermonkey.net.cn/
// @version 0.1
// @description 记录开始日期的累计天数,每隔一天计数增加1,可以在设置中填写回滚值对天数进行减少
// @author Exisi
// @crontab * 18-23 once * *
// @grant GM_notification
// @grant GM_getValue
// @grant GM_setValue
// @supportURL www.exi.ink
// ==/UserScript==
/* ==UserConfig==
设置:
Notice:
title: 标题
description: 请输入通知标题
Timeout:
title: 通知时间
description: 请输入每次通知保持的时长,默认 3 秒
Count:
title: 累计天数
description: 请输入计数,默认为0,每天增加1
Back:
title: 回滚值
description: 请输入回滚值,默认为0
==/UserConfig== */
function getDiffDay(pre, cur) {
let pre_date = new Date();
let cur_date = new Date();
pre_date.setFullYear(pre.year, pre.month - 1, pre.day);
cur_date.setFullYear(cur.year, cur.month - 1, cur.day);
let diff = (cur_date - pre_date) / 1000 / 3600 / 24;
return diff;
}
return new Promise((resolve, reject) => {
let notice = GM_getValue('设置.Notice', '') != '' ? GM_getValue('设置.Notice') : 0;
let start = GM_getValue('设置.Count', '') != '' ? GM_getValue('设置.Count') : 0;
let back = GM_getValue('设置.Back', '') != '' ? GM_getValue('设置.Back') : 0;
let date = new Date();
let current = {
year: date.getFullYear(),
month: date.getMonth() + 1,
day: date.getDate(),
}
let mark = GM_getValue('mark', '') != '' ? 1 : 0;
if (mark) {
let previous = GM_getValue('mark');
let diff_day = parseInt(getDiffDay(previous, current))
start -= back;
start += diff_day;
GM_setValue('设置.Count', start);
GM_setValue('设置.Back', '');
GM_setValue('mark', current);
} else {
GM_setValue('mark', current);
}
GM_notification({
title: notice,
text: '记录:'+start,
timeout: GM_getValue('设置.Timeout') != '' ? GM_getValue('设置.Timeout') : 3000,
});
resolve('ok');
});