read.blade.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. <!DOCTYPE html>
  2. <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>{{ $book['title'] }}</title>
  7. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/css/tabler.min.css" />
  8. <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
  9. <script src="https://cdn.jsdelivr.net/npm/@tabler/core@1.3.2/dist/js/tabler.min.js"></script>
  10. <style>
  11. body {
  12. font-family: 'Inter', sans-serif;
  13. transition: background-color 0.3s, color 0.3s;
  14. }
  15. .main-container {
  16. display: flex;
  17. gap: 20px;
  18. padding: 20px;
  19. max-width: 1400px;
  20. margin: 0 auto;
  21. }
  22. .toc-sidebar {
  23. width: 250px;
  24. flex-shrink: 0;
  25. display: none;
  26. position: sticky;
  27. top: 0;
  28. height: 100vh;
  29. overflow-y: auto;
  30. overflow-x: hidden;
  31. scrollbar-width: thin;
  32. }
  33. .toc-sidebar .card-body {
  34. height: 100%;
  35. overflow-y: auto;
  36. overflow-x: hidden;
  37. }
  38. .content-area {
  39. flex-grow: 1;
  40. max-width: 100%;
  41. }
  42. .right-sidebar {
  43. width: 300px;
  44. flex-shrink: 0;
  45. display: none;
  46. }
  47. .related-books {
  48. margin-top: 30px;
  49. }
  50. .card-img-container {
  51. height: 150px;
  52. overflow: hidden;
  53. }
  54. .card-img-container img {
  55. width: 100%;
  56. height: 100%;
  57. object-fit: cover;
  58. }
  59. @media (max-width: 767px) {
  60. .content-area {
  61. width: 100%;
  62. }
  63. .main-container {
  64. padding: 0;
  65. }
  66. .card {
  67. border: none;
  68. }
  69. }
  70. @media (min-width: 768px) {
  71. .toc-sidebar {
  72. display: block;
  73. }
  74. .content-area {
  75. max-width: calc(100% - 270px);
  76. }
  77. }
  78. @media (min-width: 992px) {
  79. .right-sidebar {
  80. display: block;
  81. }
  82. .content-area {
  83. max-width: calc(100% - 570px);
  84. }
  85. }
  86. .dark-mode {
  87. background-color: #1a1a1a;
  88. color: #ffffff;
  89. }
  90. .dark-mode .card {
  91. background-color: #2a2a2a;
  92. border-color: #3a3a3a;
  93. color: #ffffff;
  94. }
  95. .dark-mode .navbar {
  96. background-color: #2a2a2a;
  97. }
  98. .dark-mode .offcanvas {
  99. background-color: #2a2a2a;
  100. color: #ffffff;
  101. }
  102. .dark-mode .offcanvas .nav-link {
  103. color: #ffffff;
  104. }
  105. .dark-mode .toc-sidebar,
  106. .dark-mode .right-sidebar {
  107. background-color: #2a2a2a;
  108. }
  109. .toc-sidebar ul,
  110. .offcanvas-body ul {
  111. list-style: none;
  112. padding: 0;
  113. }
  114. .toc-sidebar ul li,
  115. .offcanvas-body ul li {
  116. padding: 5px 0;
  117. }
  118. .toc-sidebar ul li a,
  119. .offcanvas-body ul li a {
  120. color: #206bc4;
  121. text-decoration: none;
  122. }
  123. .toc-sidebar ul li a:hover {
  124. text-decoration: none;
  125. }
  126. .offcanvas-body ul li a:hover {
  127. text-decoration: underline;
  128. }
  129. .dark-mode .toc-sidebar ul li a,
  130. .dark-mode .offcanvas-body ul li a {
  131. color: #4dabf7;
  132. }
  133. .toc-level-1 {
  134. padding-left: 0 !important;
  135. }
  136. .toc-level-2 {
  137. padding-left: 16px !important;
  138. }
  139. .toc-level-3 {
  140. padding-left: 24px !important;
  141. }
  142. .toc-level-4 {
  143. padding-left: 36px !important;
  144. }
  145. .toc-disabled {
  146. color: #6c757d;
  147. cursor: not-allowed;
  148. pointer-events: none;
  149. }
  150. .dark-mode .toc-disabled {
  151. color: #adb5bd;
  152. }
  153. .toc_item {
  154. white-space: nowrap;
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. }
  158. .toc_item:hover {
  159. color: #206bc4 !important;
  160. background: rgba(32, 107, 196, 0.15);
  161. border-radius: 2px;
  162. cursor: 'pointer';
  163. }
  164. .toc_item a,
  165. .toc_item span {
  166. display: block;
  167. width: 100%;
  168. white-space: nowrap;
  169. overflow: hidden;
  170. text-overflow: ellipsis;
  171. }
  172. .toc-active {
  173. color: #206bc4 !important;
  174. font-weight: 600;
  175. background: rgba(32, 107, 196, 0.08);
  176. border-left: 3px solid #206bc4;
  177. border-radius: 2px;
  178. cursor: default;
  179. pointer-events: none;
  180. }
  181. .dark-mode .toc-active {
  182. color: #4dabf7 !important;
  183. background: rgba(77, 171, 247, 0.1);
  184. border-left-color: #4dabf7;
  185. }
  186. .origin {
  187. color: darkred;
  188. }
  189. </style>
  190. </head>
  191. <body class="{{ session('theme', 'light') }}-mode">
  192. <!-- Navbar -->
  193. <header class="navbar navbar-expand-md navbar-light d-print-none">
  194. <div class="container-xl">
  195. <button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#tocDrawer" aria-controls="tocDrawer">
  196. <span class="navbar-toggler-icon"></span>
  197. </button>
  198. {{-- 面包屑:文集标题 > 文章标题 --}}
  199. <div class="navbar-brand d-flex flex-column lh-1">
  200. @if(!empty($book['anthology']))
  201. <small class="text-muted" style="font-size:.75rem;">
  202. <a href="{{ route('library.anthology.show', $book['anthology']['id']) }}" class="text-muted text-decoration-none">
  203. {{ $book['anthology']['title'] }}
  204. </a>
  205. </small>
  206. @endif
  207. </div>
  208. <div class="navbar-nav flex-row order-md-last align-items-center">
  209. {{-- Desktop 编辑器按钮 --}}
  210. @if(!empty($editor_link))
  211. <div class="nav-item d-none d-md-block me-2">
  212. <a href="{{ $editor_link }}"
  213. target="_blank"
  214. class="nav-link">
  215. <i class="fas fa-pen-to-square me-1"></i>
  216. 编辑器
  217. </a>
  218. </div>
  219. {{-- Mobile 编辑器按钮 --}}
  220. <div class="nav-item d-md-none me-2">
  221. <a href="{{ $editor_link }}"
  222. target="_blank"
  223. class="nav-link">
  224. <i class="fas fa-pen-to-square"></i>
  225. </a>
  226. </div>
  227. @endif
  228. {{-- Desktop 设置按钮 --}}
  229. <div class="nav-item d-none d-md-block me-2">
  230. <a href="#"
  231. class="nav-link"
  232. data-bs-toggle="modal"
  233. data-bs-target="#settingsModal">
  234. <i class="fas fa-cog me-1"></i>
  235. 设置
  236. </a>
  237. </div>
  238. {{-- Mobile 设置按钮 --}}
  239. <div class="nav-item d-md-none me-2">
  240. <a href="#"
  241. class="nav-link"
  242. data-bs-toggle="modal"
  243. data-bs-target="#settingsModal">
  244. <i class="fas fa-cog"></i>
  245. </a>
  246. </div>
  247. {{-- Desktop Dropdown --}}
  248. @if(!empty($channels))
  249. <div class="nav-item dropdown d-none d-md-block me-2">
  250. <a href="#" class="nav-link" data-bs-toggle="dropdown">
  251. <i class="fas fa-layer-group me-1"></i>
  252. 版本
  253. </a>
  254. <div class="dropdown-menu dropdown-menu-end">
  255. @foreach($channels as $channel)
  256. <a class="dropdown-item"
  257. href="{{ request()->fullUrlWithQuery(['channel' => $channel['id']]) }}">
  258. {{ $channel['name'] }}
  259. <small class="text-muted">
  260. ({{ __('language.' . $channel['lang']) }})
  261. </small>
  262. </a>
  263. @endforeach
  264. </div>
  265. </div>
  266. {{-- Mobile Drawer Trigger --}}
  267. <div class="nav-item d-md-none me-2">
  268. <a href="#" class="nav-link"
  269. data-bs-toggle="offcanvas"
  270. data-bs-target="#channelDrawer">
  271. <i class="fas fa-layer-group"></i>
  272. </a>
  273. </div>
  274. @endif
  275. <div class="nav-item">
  276. <a href="#" class="nav-link" id="themeToggle">
  277. <i class="fas fa-moon"></i>
  278. </a>
  279. </div>
  280. @auth
  281. <div class="nav-item dropdown">
  282. <a href="#" class="nav-link d-flex lh-1 text-reset p-0" data-bs-toggle="dropdown">
  283. <span class="avatar avatar-sm" style="background-image: url({{ auth()->user()->avatar ?? '' }})"></span>
  284. </a>
  285. <div class="dropdown-menu dropdown-menu-end">
  286. <a class="dropdown-item" href="#">Profile</a>
  287. <a class="dropdown-item" href="{{ route('logout') }}">Logout</a>
  288. </div>
  289. </div>
  290. @endauth
  291. </div>
  292. </div>
  293. </header>
  294. <!-- TOC Drawer (Mobile) -->
  295. @if(!empty($channels))
  296. <div class="offcanvas offcanvas-end"
  297. tabindex="-1"
  298. id="channelDrawer">
  299. <div class="offcanvas-header">
  300. <h5 class="offcanvas-title">选择版本</h5>
  301. <button type="button"
  302. class="btn-close"
  303. data-bs-dismiss="offcanvas">
  304. </button>
  305. </div>
  306. <div class="offcanvas-body">
  307. <div class="list-group list-group-flush">
  308. @foreach($channels as $channel)
  309. <a
  310. href="{{ request()->fullUrlWithQuery(['channel' => $channel['id']]) }}"
  311. class="list-group-item list-group-item-action">
  312. <div class="fw-bold">
  313. {{ $channel['name'] }}
  314. </div>
  315. <small class="text-muted">
  316. {{ __('language.' . $channel['lang']) }}
  317. </small>
  318. </a>
  319. @endforeach
  320. </div>
  321. </div>
  322. </div>
  323. @endif
  324. <div class="offcanvas offcanvas-start" tabindex="-1" id="tocDrawer" aria-labelledby="tocDrawerLabel">
  325. <div class="offcanvas-header">
  326. <h5 class="offcanvas-title" id="tocDrawerLabel">目录</h5>
  327. <button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
  328. </div>
  329. <div class="offcanvas-body">
  330. @if(isset($book['toc']) && count($book['toc']) > 0)
  331. <ul>
  332. @foreach ($book['toc'] as $item)
  333. <li class="toc_item toc-level-{{ $item['level'] }} {{ $item['active'] ?? false ? 'toc-active' : ($item['disabled'] ? 'toc-disabled' : '') }}">
  334. @if($item['active'] ?? false)
  335. <span title="{{ $item['title'] }}">
  336. {{ $item['title'] }}
  337. </span>
  338. @elseif(!$item['disabled'])
  339. @if(isset($anthologyId))
  340. {{-- ✅ 修改1:使用文集阅读路由,传 anthology + article 两个参数 --}}
  341. <a href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $item['id'],'channel' => request('channel')]) }}" title="{{ $item['title'] }}">
  342. @else
  343. <a href="{{ route('library.tipitaka.read', ['id' => $item['id'] ,'channel' => request('channel')]) }}" title="{{ $item['title'] }}">
  344. @endif
  345. {{ $item['title'] }}
  346. </a>
  347. @else
  348. <span title="{{ $item['title'] }}">
  349. {{ $item['title'] }}
  350. </span>
  351. @endif
  352. </li>
  353. @endforeach
  354. </ul>
  355. @else
  356. <div class="alert alert-warning">此书没有目录</div>
  357. @endif
  358. </div>
  359. </div>
  360. <!-- Main Content Area -->
  361. <div class="main-container">
  362. <!-- TOC Sidebar (Tablet+) -->
  363. <div class="toc-sidebar card">
  364. <div class="card-body">
  365. <h5>目录</h5>
  366. @if(isset($book['toc']) && count($book['toc']) > 0)
  367. <ul>
  368. @foreach ($book['toc'] as $item)
  369. <li class="toc_item toc-level-{{ $item['level'] }} {{ $item['active'] ?? false ? 'toc-active' : ($item['disabled'] ? 'toc-disabled' : '') }}">
  370. @if($item['active'] ?? false)
  371. <span>{{ $item['title'] }}</span>
  372. @elseif(!$item['disabled'])
  373. {{-- --}}
  374. @if(isset($anthologyId))
  375. <a href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $item['id'],'channel' => request('channel')]) }}">
  376. @else
  377. <a href="{{ route('library.tipitaka.read', ['id' => $item['id'],'channel' => request('channel')]) }}">
  378. @endif
  379. {{ $item['title'] }}
  380. </a>
  381. @else
  382. <span>{{ $item['title'] }}</span>
  383. @endif
  384. </li>
  385. @endforeach
  386. </ul>
  387. @else
  388. <div class="alert alert-warning">此书没有目录</div>
  389. @endif
  390. </div>
  391. </div>
  392. <!-- Main Content -->
  393. <div class="content-area card">
  394. <div class="card-body">
  395. <div>
  396. <h2>{{ $book['title'] }}</h2>
  397. <p>
  398. <strong>Author:</strong>
  399. <span>
  400. {{ $book['author'] }}
  401. @if(isset($book['publisher']))
  402. @
  403. <a href="{{ route('blog.index', ['user' => $book['publisher']->username]) }}">
  404. {{ $book['publisher']->nickname }}
  405. </a>
  406. @endif
  407. </span>
  408. </p>
  409. <div class="content">
  410. @if(isset($book['content']) && count($book['content']) > 0)
  411. @foreach ($book['content'] as $paragraph)
  412. <div id="para-{{ $paragraph['id'] }}">
  413. @foreach ($paragraph['text'] as $rows)
  414. <div style="display:flex;">
  415. @foreach ($rows as $col)
  416. <div style="flex:1;">
  417. @if($paragraph['level'] < 8)
  418. {{-- ✅ 修改3:{!! !!} 不转义,渲染 HTML 内容 --}}
  419. <h{{ $paragraph['level'] }}>{!! $col !!}</h{{ $paragraph['level'] }}>
  420. @else
  421. <p>{!! $col !!}</p>
  422. @endif
  423. </div>
  424. @endforeach
  425. </div>
  426. @endforeach
  427. </div>
  428. @endforeach
  429. @else
  430. <div>没有内容</div>
  431. @endif
  432. </div>
  433. </div>
  434. <!-- Nav buttons -->
  435. <div class="mt-6 pt-6">
  436. <ul class="pagination">
  437. @if(!empty($book['pagination']['prev']))
  438. <li class="page-item page-prev">
  439. {{-- ✅ 修改2:翻页也用文集路由 --}}
  440. @if(isset($anthologyId))
  441. <a class="page-link"
  442. href="{{ route('library.anthology.read', [
  443. 'anthology' => $anthologyId,
  444. 'article' => $book['pagination']['prev']['id'],
  445. 'channel' => request('channel')
  446. ]) }}">
  447. @else
  448. <a class="page-link" href="{{ route('library.tipitaka.read', [
  449. 'id' => $book['pagination']['prev']['id'],
  450. 'channel' => request('channel')
  451. ]) }}">
  452. @endif
  453. <div class="row align-items-center">
  454. <div class="col-auto">
  455. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-1">
  456. <path d="M15 6l-6 6l6 6"></path>
  457. </svg>
  458. </div>
  459. <div class="col">
  460. <div class="page-item-subtitle">上一篇</div>
  461. <div class="page-item-title">{{ $book['pagination']['prev']['title'] }}</div>
  462. </div>
  463. </div>
  464. </a>
  465. </li>
  466. @endif
  467. @if(!empty($book['pagination']['next']))
  468. <li class="page-item page-next">
  469. @if(isset($anthologyId))
  470. <a class="page-link" href="{{ route('library.anthology.read', ['anthology' => $anthologyId, 'article' => $book['pagination']['next']['id'],'channel' => request('channel')]) }}">
  471. @else
  472. <a class="page-link" href="{{ route('library.tipitaka.read', ['id' => $book['pagination']['next']['id'],'channel' => request('channel')]) }}">
  473. @endif
  474. <div class="row align-items-center">
  475. <div class="col">
  476. <div class="page-item-subtitle">下一篇</div>
  477. <div class="page-item-title">{{ $book['pagination']['next']['title'] }}</div>
  478. </div>
  479. <div class="col-auto">
  480. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-1">
  481. <path d="M9 6l6 6l-6 6"></path>
  482. </svg>
  483. </div>
  484. </div>
  485. </a>
  486. </li>
  487. @endif
  488. </ul>
  489. </div>
  490. <!-- Related Books -->
  491. @if(!empty($relatedBooks))
  492. <div class="related-books">
  493. <h3>Related Books</h3>
  494. <div class="row row-cards">
  495. @foreach ($relatedBooks as $relatedBook)
  496. <div class="col-md-4">
  497. <div class="card">
  498. <div class="card-img-container">
  499. <img src="{{ $relatedBook['image'] }}" alt="{{ $relatedBook['title'] }}">
  500. </div>
  501. <div class="card-body">
  502. <h5 class="card-title">{{ $relatedBook['title'] }}</h5>
  503. <p class="card-text">{{ $relatedBook['description'] }}</p>
  504. <a href="{{ $relatedBook['link'] }}" class="btn btn-primary">Read Now</a>
  505. </div>
  506. </div>
  507. </div>
  508. @endforeach
  509. </div>
  510. </div>
  511. @endif
  512. </div>
  513. </div>
  514. <!-- Right Sidebar (Desktop) -->
  515. <div class="right-sidebar card">
  516. <div class="card-body">
  517. @if(!empty($book['downloads']))
  518. <h5>下载</h5>
  519. <ul class="list-unstyled">
  520. @foreach ($book['downloads'] as $download)
  521. <li>
  522. <a href="{{ $download['url'] }}" class="btn btn-outline-primary mb-2 w-100">
  523. <i class="fas fa-download me-2"></i>{{ $download['format'] }}
  524. </a>
  525. </li>
  526. @endforeach
  527. </ul>
  528. @endif
  529. @if(!empty($book['categories']))
  530. <h5>分类</h5>
  531. @foreach ($book['categories'] as $category)
  532. <span class="badge bg-blue text-blue-fg">{{ $category['name'] }}</span>
  533. @endforeach
  534. @endif
  535. @if(!empty($book['tags']))
  536. <h5>标签</h5>
  537. @foreach ($book['tags'] as $tag)
  538. <span class="badge me-1">{{ $tag['name'] }}</span>
  539. @endforeach
  540. @endif
  541. </div>
  542. </div>
  543. </div>
  544. <!-- Settings Modal -->
  545. <div class="modal modal-blur fade" id="settingsModal" tabindex="-1">
  546. <div class="modal-dialog">
  547. <form id="settingsForm" class="modal-content">
  548. <div class="modal-header">
  549. <h5 class="modal-title">阅读设置</h5>
  550. <button type="button"
  551. class="btn-close"
  552. data-bs-dismiss="modal"></button>
  553. </div>
  554. <div class="modal-body">
  555. {{-- 显示原文 --}}
  556. <div class="mb-4">
  557. <label class="form-label">显示原文</label>
  558. <label class="form-check form-switch">
  559. <input class="form-check-input"
  560. type="checkbox"
  561. id="showOrigin">
  562. <span class="form-check-label">
  563. 开启/关闭原文显示
  564. </span>
  565. </label>
  566. </div>
  567. {{-- 界面语言 --}}
  568. <div class="mb-4">
  569. <label class="form-label">界面语言</label>
  570. <select class="form-select" id="uiLanguage">
  571. <option value="auto">自动</option>
  572. <option value="zh">简体中文</option>
  573. <option value="en">英文</option>
  574. </select>
  575. </div>
  576. {{-- 巴利文脚本 --}}
  577. <div class="mb-4">
  578. <label class="form-label">巴利文脚本</label>
  579. <select class="form-select" id="paliScript">
  580. <option value="auto">自动</option>
  581. <option value="roman">罗马</option>
  582. <option value="myanmar">缅文</option>
  583. <option value="thai">泰文</option>
  584. </select>
  585. </div>
  586. </div>
  587. <div class="modal-footer">
  588. <button type="button"
  589. class="btn btn-link"
  590. data-bs-dismiss="modal">
  591. 取消
  592. </button>
  593. <button type="submit"
  594. class="btn btn-primary">
  595. 确定
  596. </button>
  597. </div>
  598. </form>
  599. </div>
  600. </div>
  601. <script>
  602. function toggleOriginDisplay(show) {
  603. document.querySelectorAll('.origin').forEach(el => {
  604. el.style.display = show ? 'unset' : 'none';
  605. });
  606. }
  607. function setCookie(name, value, days = 365) {
  608. let expires = "";
  609. const date = new Date();
  610. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  611. expires = "; expires=" + date.toUTCString();
  612. document.cookie =
  613. name + "=" + encodeURIComponent(value) +
  614. expires +
  615. "; path=/";
  616. }
  617. function getCookie(name) {
  618. const value = `; ${document.cookie}`;
  619. const parts = value.split(`; ${name}=`);
  620. if (parts.length === 2)
  621. return decodeURIComponent(parts.pop().split(';').shift());
  622. return null;
  623. }
  624. // 初始化加载 cookie
  625. document.addEventListener('DOMContentLoaded', function() {
  626. const showOrigin =
  627. getCookie('show_origin') === 'true';
  628. document.getElementById('showOrigin').checked =
  629. showOrigin;
  630. document.getElementById('uiLanguage').value =
  631. getCookie('ui_language') || 'auto';
  632. document.getElementById('paliScript').value =
  633. getCookie('pali_script') || 'auto';
  634. // 应用原文显示设置
  635. toggleOriginDisplay(showOrigin);
  636. });
  637. // 提交保存
  638. document.getElementById('settingsForm')
  639. .addEventListener('submit', function(e) {
  640. e.preventDefault();
  641. setCookie(
  642. 'show_origin',
  643. document.getElementById('showOrigin').checked
  644. );
  645. setCookie(
  646. 'ui_language',
  647. document.getElementById('uiLanguage').value
  648. );
  649. setCookie(
  650. 'pali_script',
  651. document.getElementById('paliScript').value
  652. );
  653. toggleOriginDisplay(showOrigin);
  654. location.reload();
  655. });
  656. </script>
  657. <script>
  658. const themeToggle = document.getElementById('themeToggle');
  659. themeToggle.addEventListener('click', (e) => {
  660. e.preventDefault();
  661. const isDark = document.body.classList.contains('dark-mode');
  662. document.body.classList.toggle('dark-mode', !isDark);
  663. document.body.classList.toggle('light-mode', isDark);
  664. fetch('{{ route("theme.toggle") }}', {
  665. method: 'POST',
  666. headers: {
  667. 'X-CSRF-TOKEN': '{{ csrf_token() }}',
  668. 'Content-Type': 'application/json'
  669. },
  670. body: JSON.stringify({
  671. theme: isDark ? 'light' : 'dark'
  672. })
  673. });
  674. themeToggle.innerHTML = isDark ? '<i class="fas fa-moon"></i>' : '<i class="fas fa-sun"></i>';
  675. });
  676. </script>
  677. </body>
  678. </html>