Skip to content

Commit

Permalink
Update header.php
Browse files Browse the repository at this point in the history
  • Loading branch information
riceshowerX authored Nov 29, 2024
1 parent 7756f6e commit c21654b
Showing 1 changed file with 4 additions and 143 deletions.
147 changes: 4 additions & 143 deletions header.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!--header.php-->
<!DOCTYPE HTML>
<html lang="zh-CN">

Expand All @@ -22,38 +21,15 @@
<!-- 动态生成 CSS -->
<?php generateDynamicCSS(); ?>

<!-- 引入样式和脚本 -->
<!-- 引入外部 CSS 文件 -->
<link rel="stylesheet" href="<?= $this->options->themeUrl('/css/PureSuck_Style.css'); ?>">
<link rel="stylesheet" href="<?= $this->options->themeUrl('/css/a11y-dark.min.css'); ?>">
<link rel="stylesheet" href="<?= $this->options->themeUrl('/css/PureSuck_Module.css'); ?>">
<link rel="stylesheet" href="<?= $this->options->themeUrl('/css/MoxDesign.css'); ?>">
<link rel="stylesheet" href="<?= $this->options->themeUrl('/css/theme.css'); ?>"> <!-- 新增引用的外部 CSS 文件 -->

<!-- 标题线条样式 -->
<style>
.post-title::after {
content: '';
position: absolute;
display: block;
background: #2a2a2a;
bottom: 5px;
left: 0;
<?php if ($this->options->postTitleAfter == 'boldLine'): ?>
width: 58px;
height: 13px;
<?php elseif ($this->options->postTitleAfter == 'wavyLine'): ?>
width: 80px;
height: 12px;
bottom: -5px;
mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="10" viewBox="0 0 40 10" preserveAspectRatio="none"><path d="M0 5 Q 10 0, 20 5 T 40 5" stroke="black" stroke-width="2" fill="transparent"/></svg>') repeat-x;
mask-size: 40px 12px;
<?php elseif ($this->options->postTitleAfter == 'handDrawn'): ?>
width: 130px;
height: 6px;
border-radius: 6px;
transform: rotate(10deg);
<?php endif; ?>
}
</style>
<!-- 引入外部 JS 文件 -->
<script defer src="<?= $this->options->themeUrl('/js/theme.js'); ?>"></script>

<!-- AOS 样式和脚本 -->
<link rel="stylesheet" href="<?= $this->options->themeUrl('/css/aos.css'); ?>">
Expand All @@ -66,121 +42,6 @@
<script defer src="<?= $this->options->themeUrl('/js/OwO.min.js'); ?>"></script>
<script defer src="<?= $this->options->themeUrl('/js/MoxDesign.js'); ?>"></script>

<script>
// 更新图标 (全局函数,包含 null 检查)
function updateIcon(theme) {
const iconElement = document.getElementById('theme-icon');
if (iconElement) {
iconElement.className = {
light: 'icon-sun-inv',
dark: 'icon-moon-inv',
auto: 'icon-auto'
}[theme] || 'icon-auto';
}
}

// 主题初始化脚本 (立即执行函数)
(function() {
const savedTheme = localStorage.getItem('theme') || 'auto';
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
const initialTheme = savedTheme === 'auto' ? systemTheme : savedTheme;
document.documentElement.setAttribute('data-theme', initialTheme);

updateIcon(initialTheme);

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
if (localStorage.getItem('theme') === 'auto') {
const newTheme = e.matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
updateIcon(newTheme);
}
});

function setTheme(theme) {
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
const appliedTheme = theme === 'auto' ? systemTheme : theme;
document.documentElement.setAttribute('data-theme', appliedTheme);
localStorage.setItem('theme', theme);
updateIcon(theme);
}

window.toggleTheme = function() {
const currentTheme = localStorage.getItem('theme') || 'auto';
const nextTheme = currentTheme === 'light' ? 'dark' : (currentTheme === 'dark' ? 'auto' : 'light');
setTheme(nextTheme);

const messages = {
light: "已切换至浅色模式",
dark: "已切换至深色模式",
auto: "模式将跟随系统 ㆆᴗㆆ"
};

MoxToast({ message: messages[nextTheme] });
};
})();


// OwO 初始化函数 (全局函数)
function initializeCommentsOwO() {
const textarea = document.querySelector('.OwO-textarea');
const container = document.querySelector('.OwO-container');

if (textarea && container) {
new OwO({
logo: '表情',
container: container,
target: textarea,
api: '<?php $this->options->themeUrl("/json/OwO.json"); ?>',
position: 'down',
width: '100%',
maxHeight: '250px'
});
}
}
</script>



<!-- Pjax 支持 -->
<?php if ($this->options->enablepjax == '1'): ?>
<script defer src="<?= $this->options->themeUrl('/js/pjax.min.js'); ?>"></script>
<script>
// PJAX 初始化及事件处理
document.addEventListener('DOMContentLoaded', () => {
// 初始化 Pjax
// 移除 .right-sidebar 以解决 DOM 差异问题
new Pjax({
history: true,
cacheBust: false,
timeout: 6500,
elements: 'a[href^="<?php Helper::options()->siteUrl() ?>"]:not([target="_blank"], [no-pjax]), form[action]',
selectors: ["pjax", "script[data-pjax]", "title", ".main"]
});

// 处理 PJAX 错误
document.addEventListener('pjax:error', (e) => {
MoxToast({
message: "页面加载失败,请稍后重试",
type: 'danger'
});
console.error(e);
});

// 处理 PJAX 成功加载
document.addEventListener("pjax:success", () => {
AOS.refresh();
initializeCommentsOwO();
updateIcon(localStorage.getItem('theme') || 'auto');
});

// 在初始加载时初始化 OwO
initializeCommentsOwO();
});
</script>
<?php endif; ?>



</head>

<body>
Expand Down

0 comments on commit c21654b

Please sign in to comment.