fix Plugin name fix Class name fix version number Signed-off-by: Dylan Wu <i@dylanwu.space>
89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
||
/**
|
||
* 页面黑白显示插件(支持时间段、指定日期、每月/每年循环)
|
||
*
|
||
* @package GrayMode
|
||
* @author DylanWu & linhaicaoyuan
|
||
* @version 0.0.3
|
||
* @link https://blog.lhcy.org/about.html$0
|
||
*/
|
||
class GrayMode_Plugin implements Typecho_Plugin_Interface
|
||
{
|
||
public static function activate()
|
||
{
|
||
Typecho_Plugin::factory('Widget_Archive')->header = __CLASS__ . '::render';
|
||
}
|
||
|
||
public static function deactivate() {}
|
||
|
||
public static function config(Typecho_Widget_Helper_Form $form)
|
||
{
|
||
try {
|
||
$options = Typecho_Widget::widget('Widget_Options')->plugin('GrayMode');
|
||
// 可选:读取配置值
|
||
} catch (Exception $e) {
|
||
// 不处理配置读取错误
|
||
}
|
||
$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, '',
|
||
'灰白显示日期列表',
|
||
'支持多种格式:<br>
|
||
- 一次性:2025-09-18<br>
|
||
- 每年重复:04-04(每年4月4日)<br>
|
||
- 每月重复:-18(每月18日)<br>
|
||
多个值用英文逗号分隔,如: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 render($archive)
|
||
{
|
||
$options = Typecho_Widget::widget('Widget_Options')->plugin('GrayMode');
|
||
|
||
$start = $options->startTime ?? '00:00';
|
||
$end = $options->endTime ?? '23:59';
|
||
$dates = isset($options->specialDates) ? 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 <<<EOT
|
||
<style>
|
||
html {
|
||
filter: grayscale(100%);
|
||
-webkit-filter: grayscale(100%);
|
||
}
|
||
</style>
|
||
EOT;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
} |