83
Plugin.php
Normal file
83
Plugin.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* 页面黑白显示插件(支持时间段、指定日期、每月/每年循环)
|
||||
*
|
||||
* @package GrayModePlugin
|
||||
* @author Your
|
||||
* @version 1.1.0
|
||||
* @link https://your.site
|
||||
*/
|
||||
class GrayModePlugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
public static function activate()
|
||||
{
|
||||
Typecho_Plugin::factory('Widget_Archive')->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, '',
|
||||
'灰白显示日期列表',
|
||||
'支持多种格式:<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 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 <<<EOT
|
||||
<style>
|
||||
html {
|
||||
filter: grayscale(100%);
|
||||
-webkit-filter: grayscale(100%);
|
||||
}
|
||||
</style>
|
||||
EOT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user