header = [__CLASS__, 'changeheader'];
}
public static function deactivate() {}
public static function config(Typecho_Widget_Helper_Form $form)
{
$start = new Typecho_Widget_Helper_Form_Element_Text(
'startTime', NULL, '00:00', '开始时间', '格式如 08:00'
);
$end = new Typecho_Widget_Helper_Form_Element_Text(
'endTime', NULL, '23:59', '结束时间', '格式如 22:00'
);
$dates = new Typecho_Widget_Helper_Form_Element_Textarea(
'specialDates', NULL, '',
'灰白显示日期列表',
'支持多种格式:
- 一次性:2025-09-18
- 每年重复:04-04(每年4月4日)
- 每月重复:-18(每月18日)
多个值用英文逗号分隔,如:2025-09-18,04-04,-18'
);
$form->addInput($start);
$form->addInput($end);
$form->addInput($dates);
}
public static function personalConfig(Typecho_Widget_Helper_Form $form) {}
public static function changeheader()
{
$options = Typecho_Widget::widget('Widget_Options')->plugin('GrayModePlugin');
$start = $options->startTime;
$end = $options->endTime;
$dates = trim($options->specialDates);
$now = date('H:i');
// 判断是否在时间区间内
$inTimeRange = ($start <= $now && $now <= $end);
if (!$inTimeRange) return;
$today = date('Y-m-d');
$monthDay = date('m-d');
$dayOnly = date('d');
$dateList = array_filter(array_map('trim', explode(',', $dates)));
foreach ($dateList as $date) {
if (
$date === $today || // 一次性完整日期
$date === $monthDay || // 每年循环
$date === '-' . $dayOnly // 每月循环
) {
echo <<
html {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
}
EOT;
break;
}
}
}
}