From 77d1c59cd0db5ad08247e2639802fdd3c552a28b Mon Sep 17 00:00:00 2001 From: Dylan Wu Date: Mon, 4 Aug 2025 04:34:57 -0400 Subject: [PATCH] Add Plugin.php Signed-off-by: Dylan Wu --- Plugin.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Plugin.php diff --git a/Plugin.php b/Plugin.php new file mode 100644 index 0000000..d828a44 --- /dev/null +++ b/Plugin.php @@ -0,0 +1,83 @@ +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; + } + } + } +} \ No newline at end of file