index.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035
  1. <!doctype html>
  2. <html>
  3. <markdown-html version="1.12.0" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
  4. license="CC BY-SA 4.0 International"></markdown-html>
  5. <head>
  6. <meta charset="utf-8">
  7. <meta name="description" content="HTML read markdown">
  8. <meta name="keywords" content="markdown, html, renderer, low-dependency, one-click deployment">
  9. <meta name="author" content="PJ568">
  10. <meta name="viewport" content="width=256, initial-scale=1">
  11. <script defer src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/marked/4.0.2/marked.min.js"
  12. type="text/javascript"></script>
  13. <script src="https://lib.baomitu.com/pjax/0.2.8/pjax.min.js" type="text/javascript"></script>
  14. <script src="https://lib.baomitu.com/translate.js/3.7.2/translate.js" type="text/javascript"></script>
  15. <script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/Darkmode.js/1.5.7/darkmode-js.min.js"
  16. type="application/javascript"></script>
  17. <script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-y/mermaid/8.14.0/mermaid.min.js"
  18. type="application/javascript"></script>
  19. <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-y/highlight.js/11.4.0/highlight.min.js"
  20. type="application/javascript"></script>
  21. <script>
  22. // 使用 IIFE 包裹以避免全局变量污染
  23. (function () {
  24. const about = `
  25. # 关于
  26. ## MARKDOWN.HTML
  27. 旨在提供低依赖、一键部署的 Markdown 网页渲染方案。
  28. 详情请访问 [GitHub](https://github.com/PJ-568/MARKDOWN.HTML) 或 [Gitee](https://gitee.com/PJ-568/MARKDOWN.HTML) 仓库。
  29. `;
  30. // 加载动画相关
  31. var loadingState = {
  32. countLoading: 0
  33. };
  34. Object.defineProperty(loadingState, 'countLoading', {
  35. get: function () {
  36. return this._countLoading;
  37. },
  38. set: function (newValue) {
  39. if (newValue < 0) {
  40. newValue = 0;
  41. }
  42. const loadingBar = document.querySelector('.loading-bar');
  43. const progress = document.querySelector('.loading-bar .progress');
  44. if (this.countLoading === 0 && newValue > 0) {
  45. var loadingBarWidth = 20;
  46. var MAX_LOADING_WIDTH = 95;
  47. loadingBar.classList.add('loading');
  48. progress.style.width = loadingBarWidth + '%';
  49. clearInterval(timer);
  50. timer = setInterval(function () {
  51. loadingBarWidth += 3;
  52. if (loadingBarWidth > MAX_LOADING_WIDTH) {
  53. loadingBarWidth = MAX_LOADING_WIDTH;
  54. }
  55. progress.style.width = loadingBarWidth + '%';
  56. }, 500);
  57. } else if (this.countLoading > 0 && newValue === 0) {
  58. clearInterval(timer);
  59. progress.style.width = '100%';
  60. loadingBar.classList.remove('loading');
  61. setTimeout(function () {
  62. progress.style.width = 0;
  63. }, 400);
  64. }
  65. this._countLoading = newValue;
  66. }
  67. });
  68. loadingState.countLoading = 0;
  69. function startLoad() {
  70. loadingState.countLoading = loadingState.countLoading + 1;
  71. }
  72. function endLoad() {
  73. loadingState.countLoading = loadingState.countLoading - 1;
  74. }
  75. var timer = null;
  76. // 文档解析功能相关
  77. var notExistIndexPage = null; // 是否不存在索引页
  78. var pValue = null;
  79. async function getPValue() {
  80. if (pValue) {
  81. return pValue;
  82. } else {
  83. return await decodeMDPath(window.location.href);
  84. }
  85. }
  86. // PJAX 相关
  87. let PJAX;
  88. // 深色模式相关
  89. let darkmode;
  90. // 自定义 PJAX 相关
  91. const existPushState = (history && history.pushState);
  92. var level = 1; // 当前页面的层级
  93. var lastLevel = 0;
  94. // 初始化 PJAX
  95. function initPJAX() {
  96. try {
  97. const Pjax = window.Pjax || function () {
  98. console.warn('Pjax 不存在?');
  99. };
  100. PJAX = new Pjax({
  101. selectors: [
  102. 'head title',
  103. '.markdown-body',
  104. '.pjax-reload'
  105. ],
  106. switches: {
  107. ".markdown-body": Pjax.switches.sideBySide
  108. },
  109. switchesOptions: {
  110. ".markdown-body": {
  111. classNames: {
  112. remove: "Animated Animated-remove Animated--reverse Animate--fast Animate--noDelay",
  113. add: "Animated",
  114. backward: "Animate--slideInRight",
  115. forward: "Animate--slideInLeft"
  116. }
  117. }
  118. },
  119. cacheBust: false
  120. });
  121. } catch (e) {
  122. console.error('PJAX 初始化出错:' + e);
  123. }
  124. }
  125. // translate-js 翻译系统
  126. //// 初始化翻译系统
  127. function initTranslate() {
  128. try {
  129. translate.service.use('client.edge');
  130. translate.request.listener.start();
  131. translate.setAutoDiscriminateLocalLanguage();
  132. translate.language.setUrlParamControl();
  133. translate.ignore.class.push('notTranslate');
  134. translate.execute();
  135. } catch (e) {
  136. console.error('翻译系统出错:' + e);
  137. }
  138. }
  139. // Darkmode.js 深色模式
  140. function initDarkmode() {
  141. try {
  142. const Darkmode = window.Darkmode || function () {
  143. console.warn('Darkmode.js 不存在?');
  144. };
  145. darkmode = new Darkmode();
  146. } catch (e) {
  147. console.error('初始化 Darkmode.js 出错:' + e);
  148. }
  149. }
  150. //// 检查并提示翻译
  151. function infoTranslate() {
  152. try {
  153. const currentLang = translate.language.getCurrent();
  154. const originalLang = translate.language.getLocal();
  155. if (currentLang !== originalLang) {
  156. const translateInfo = document.querySelectorAll('.translate-info');
  157. if (translateInfo) {
  158. translateInfo.forEach(function (item) {
  159. item.remove();
  160. })
  161. }
  162. // 获取 .markdown-body 元素
  163. var bq = document.createElement('blockquote');
  164. bq.classList.add('translate-info');
  165. var infoBody = document.createElement('p');
  166. infoBody.innerText = '当前页面已翻译。您可以:';
  167. var msgBody = document.createElement('p');
  168. var switchButton = document.createElement('a');
  169. switchButton.classList.add('translate-switch');
  170. switchButton.href = 'javascript:;';
  171. switchButton.title = '切换到原语言';
  172. switchButton.innerText = '切换到文章原本的语言';
  173. bq.appendChild(infoBody);
  174. bq.appendChild(switchButton);
  175. const mainElement = document.querySelector('.markdown-body .content');
  176. mainElement.insertBefore(bq, mainElement.children[1]);
  177. }
  178. } catch (e) {
  179. console.error('检查并提示翻译出错:' + e);
  180. }
  181. }
  182. //// 刷新翻译
  183. function refreshTranslate() {
  184. try {
  185. translate.selectLanguageTag.refreshRender();
  186. } catch (e) {
  187. console.error('刷新翻译出错:' + e);
  188. }
  189. }
  190. // 获取文件所在目录
  191. function getDirectory(path) {
  192. path = new URL(path, 'http://example.com').pathname;
  193. const lastSlashIndex = path.lastIndexOf('/');
  194. return path.substring(0, lastSlashIndex + 1);
  195. }
  196. // 获取 markdown.html 当前所加载的 md 文件的所在路径
  197. function getPath() {
  198. return getDirectory(window.location.href);
  199. }
  200. // 将 ?p= 后面的值转换为绝对路径
  201. /*
  202. 输出的值是 /path/to/file.md
  203. 当其为 null 时,根据是否存在 index.md 文件来决定返回的值
  204. */
  205. async function decodeMDPath(path) {
  206. const url = new URL(path);
  207. const params = new URLSearchParams(url.search);
  208. path = formatMDPath(params.get('p'));
  209. return path;
  210. }
  211. // 格式化路径
  212. /*
  213. 如果 mdPath 为 null,则返回 null,如果 mdPath 是路径,则返回该路径下 /index.md
  214. return: 返回格式化后的文件路径,一定是绝对路径,或者 null
  215. */
  216. function formatMDPath(mdPath) {
  217. if (mdPath) {
  218. if (isRelativePath(mdPath)) {
  219. mdPath = getPath() + mdPath;
  220. }
  221. mdPath = new URL(mdPath, 'http://example.com').pathname;
  222. if (!mdPath.endsWith('.md')) {
  223. if (!mdPath.endsWith('/')) {
  224. mdPath += '/';
  225. }
  226. mdPath += 'index.md';
  227. }
  228. }
  229. return mdPath;
  230. }
  231. // 判断路径是否为相对路径
  232. function isRelativePath(path) {
  233. return !path.match(/^\//);
  234. }
  235. // 处理错误
  236. function updateContent(article, title = null, mdPath = null) {
  237. try {
  238. document.querySelector('.markdown-body').innerHTML = `<div class="old-content Animated Animated-remove Animated--reverse Animate--fast Animate--noDelay Animate--slideInLeft">${document.querySelector('.markdown-body .content').innerHTML}</div><div class="content Animated Animate--slideInRight">${article}</div>`;
  239. firstH1 = document.querySelector('.markdown-body .content h1');
  240. document.title = title ? title : (firstH1 ? firstH1.textContent : mdPath);
  241. } catch (error) {
  242. throw error;
  243. }
  244. }
  245. // 等待动画结束
  246. function waitForAnimationsEnd(parentElement, selector, animationNames) {
  247. return new Promise(resolve => {
  248. var completedCount = 0;
  249. const elements = parentElement.querySelectorAll(selector);
  250. const totalElements = elements.length;
  251. const handleAnimationEnd = function (event) {
  252. if (animationNames.includes(event.animationName) && Array.from(elements).includes(event.target)) {
  253. completedCount++;
  254. if (completedCount === totalElements) {
  255. parentElement.removeEventListener('animationend', handleAnimationEnd);
  256. resolve();
  257. }
  258. }
  259. };
  260. parentElement.addEventListener('animationend', handleAnimationEnd);
  261. });
  262. }
  263. // 处理错误
  264. function handleError(mdPath, errorMessage) {
  265. updateContent(`<h1>加载失败</h1><p>加载文档<code>${mdPath}</code>时出错:<code>${errorMessage}</code>。您可以尝试<a class="refresh-btn" href="">重新加载</a>或<a class="back-btn">返回</a>。</p>`, '加载失败');
  266. customPushState(window.location.origin + window.location.pathname + '?p=error.md');
  267. waitForAnimationsEnd(document.querySelector('.markdown-body'), '.content, .old-content', ['Animation-slideInRight', 'Animation-slideInLeft']).then(() => {
  268. customPushState(window.location.origin + window.location.pathname + (mdPath ? ('?p=' + mdPath) : ''));
  269. });
  270. endLoad();
  271. }
  272. // 更新页面的 markdown 内容
  273. /*
  274. mdPath: 要加载的 markdown 文件路径,最好是带主机名的绝对路径(要用于 fetch())
  275. response: fetch() 的返回值,用于防止二次访问
  276. */
  277. const showMarkdown = async (mdPath, response = null) => {
  278. if (mdPath === null) {
  279. var path = null;
  280. const currentPath = getPath();
  281. // 如果存在 index.md 文件,则返回 index.md,否则返回 README.md
  282. if (notExistIndexPage) {
  283. path = currentPath + 'README.md';
  284. } else if (notExistIndexPage === false) {
  285. path = currentPath + 'index.md';
  286. } else {
  287. response = await fetch(getPath() + 'index.md');
  288. if (response.ok && response.headers.get('content-type').startsWith('text/markdown')) {
  289. notExistIndexPage = false;
  290. path = currentPath + 'index.md';
  291. } else {
  292. response = null;
  293. notExistIndexPage = true;
  294. path = currentPath + 'README.md';
  295. }
  296. }
  297. } else if (mdPath.endsWith('about.md')) {
  298. // 特殊处理 about.md
  299. response = await fetch(mdPath);
  300. if (response.ok && response.headers.get('content-type').startsWith('text/markdown')) {
  301. var r_text = await response.text();
  302. const content = about + await r_text.replace(/^# .*/m, '');
  303. response = {
  304. ok: true,
  305. status: 200,
  306. statusText: '自生成。',
  307. text: async () => {
  308. return content;
  309. }
  310. };
  311. } else {
  312. response = {
  313. ok: true,
  314. status: 200,
  315. statusText: '自生成。',
  316. text: async () => {
  317. return about + '*无更多详细信息*';
  318. }
  319. };
  320. }
  321. }
  322. try {
  323. pValue = mdPath ? mdPath : path;
  324. updateContent(await getMarkdown((mdPath ? mdPath : path), response))
  325. document.querySelector('html').classList.add('loaded'); //// 防止缓存的页面被自定义 PJAX 中覆写的处理响应的函数捕获
  326. waitForAnimationsEnd(document.querySelector('.markdown-body'), '.content, .old-content', ['Animation-slideInRight', 'Animation-slideInLeft']).then(async () => {
  327. await showMarkdownEnded();
  328. customPushState(window.location.origin + window.location.pathname + (mdPath ? ('?p=' + mdPath) : ''));
  329. });
  330. } catch (error) {
  331. handleError((mdPath ? mdPath : path), error)
  332. }
  333. }
  334. // 读取并解析指定文件
  335. const getMarkdown = async (mdPath, response = null) => {
  336. // 生成目录
  337. function generateOutline(doc) {
  338. const headings = Array.from(doc.querySelectorAll('h1, h2, h3, h4, h5, h6'));
  339. if (headings.length === 0) return '<i>无目录</i>';
  340. var outline = '<ul>';
  341. var stack = [];
  342. headings.forEach(heading => {
  343. const level = parseInt(heading.tagName.charAt(1));
  344. const id = heading.textContent.toLowerCase()
  345. .replace(/ /g, '-') // 将空格替换为连字符
  346. .replace(/[^\w\u4e00-\u9fa5-]/g, ''); // 保留字母、数字、下划线、中文字符和连字符
  347. // 设置 id 属性以便链接跳转
  348. heading.setAttribute('id', id);
  349. while (stack.length > 0 && stack[stack.length - 1].level >= level) {
  350. stack.pop();
  351. outline += '</ul></li>';
  352. }
  353. if (stack.length === 0 || stack[stack.length - 1].level < level) {
  354. outline += '<li><ul>';
  355. } else {
  356. outline += '</li><li>';
  357. }
  358. outline += `<a href="#${id}">${heading.textContent}</a>`;
  359. stack.push({ level: level });
  360. });
  361. while (stack.length > 0) {
  362. outline += '</ul></li>';
  363. stack.pop();
  364. }
  365. outline += '</ul>';
  366. return outline;
  367. }
  368. if (!response) {
  369. response = await fetch(mdPath);
  370. if (!response.ok && response.headers.get('content-type').startsWith('text/markdown')) {
  371. throw new Error('请求失败:' + mdPath + ',' + response.headers.get('content-type') + ',' + response.status + ',' + response.statusText);
  372. }
  373. }
  374. var markdown_content = await response.text();
  375. // 如果 markdown_content 中发现 `[任意标题](路径文件名.md)`
  376. /*
  377. 如果 href 是相对路径,则在其前加上当前读取的文档的绝对路径;
  378. 如果不存在当前读取的文档(默认读取的 index.md 或 README.md),
  379. 则在其前加上 markdown.html 的绝对路径。
  380. */
  381. const links = markdown_content.match(/\[.*\]\(.*\.md\)/g);
  382. if (links) {
  383. links.forEach(link => {
  384. const linkText = link.match(/\[.*\]/)[0].slice(1, -1);
  385. var linkHref = link.match(/\(.*\)/)[0].slice(1, -1);
  386. if (isRelativePath(linkHref)) {
  387. if (pValue) {
  388. linkHref = getDirectory(mdPath) + linkHref;
  389. } else {
  390. linkHref = getPath() + linkHref;
  391. }
  392. linkHref = new URL(linkHref, 'http://example.com').pathname;
  393. }
  394. const newLink = `[${linkText}](${window.location.pathname}?p=${linkHref})`;
  395. markdown_content = markdown_content.replace(link, newLink);
  396. });
  397. }
  398. var content = marked.parse(markdown_content);
  399. if (content === '') {
  400. content = '<i>空文件</i>';
  401. }
  402. content = `<details class="outline"><summary>${decodeURIComponent(mdPath)}</summary></details><hr>${content}`;
  403. const parser = new DOMParser();
  404. const doc = parser.parseFromString(content, 'text/html');
  405. const outline = generateOutline(doc);
  406. doc.querySelector('.outline').innerHTML += outline;
  407. return doc.body.innerHTML;
  408. };
  409. // 初始化自定义 PJAX 响应
  410. function initCustomPJAXResponse() {
  411. // 覆写 PJAX 处理响应的函数,在内容插入页面之前实现 markdown 的渲染
  412. PJAX._handleResponse = PJAX.handleResponse;
  413. PJAX.handleResponse = async function (responseText, request, href, options) {
  414. if (request.responseText.startsWith('<!doctype html><html><markdown-html') || request.responseText.startsWith(`<!doctype html>
  415. <html>
  416. <markdown-html`)) {
  417. await showMarkdown(await decodeMDPath(href));
  418. } else {
  419. PJAX._handleResponse(responseText, request, href, options);
  420. }
  421. }
  422. }
  423. // 初始化自定义 PJAX 事件监听器
  424. function initCustomPJAXEventListener() {
  425. // 监听自定义链接的点击事件
  426. if (existPushState) {
  427. document.querySelector('.markdown-body').addEventListener('click', async function (event) {
  428. const link = event.target.closest('a[href$=".md"]');
  429. if (link) {
  430. try {
  431. event.preventDefault();
  432. startLoad();
  433. await showMarkdown(await decodeMDPath(link.href));
  434. } catch (e) {
  435. console.error('自定义 PJAX 出错:' + e);
  436. }
  437. }
  438. });
  439. }
  440. }
  441. // 自定义推送状态
  442. function customPushState(url = window.location.href) {
  443. if (existPushState) {
  444. if (level > lastLevel) {
  445. history.pushState({ url: url, title: document.title, uid: level }, null, url);
  446. lastLevel = level++;
  447. } else {
  448. lastLevel = level - 1;
  449. }
  450. }
  451. }
  452. // 初始化内容
  453. const initContent = async () => {
  454. try {
  455. await showMarkdown(await getPValue());
  456. } catch (error) {
  457. handleError(await getPValue(), '初始化内容时出错:' + error);
  458. }
  459. };
  460. // 初始化返回首页按钮
  461. function initHomeBtn() {
  462. const homeBtn = document.querySelector('.to-home');
  463. homeBtn.href = window.location.pathname;
  464. }
  465. // 初始化返回首页按钮
  466. function initAboutBtn() {
  467. const aboutBtn = document.querySelector('.about-btn');
  468. aboutBtn.href = `?p=${getDirectory(window.location.pathname)}about.md`;
  469. }
  470. // 初始化
  471. function initialize() {
  472. initDarkmode(); //// 初始化深色模式
  473. initHomeBtn(); //// 初始化返回首页按钮
  474. initAboutBtn(); //// 初始化关于按钮
  475. initContent(); //// 初始化内容
  476. initTranslate(); //// 初始化页面翻译
  477. initPJAX(); //// 初始化 PJAX
  478. initCustomPJAXResponse(); //// 初始化自定义 PJAX 响应
  479. initCustomPJAXEventListener(); //// 初始化自定义 PJAX 事件监听器
  480. }
  481. // 触发器
  482. //// 网页加载完毕后触发初始化
  483. window.addEventListener('DOMContentLoaded', () => initialize());
  484. //// 翻译执行完成后触发
  485. translate.listener.renderTaskFinish = function (_task) {
  486. endLoad();
  487. }
  488. //// PJAX 开始时执行的函数
  489. document.addEventListener('pjax:send', function () {
  490. startLoad();
  491. });
  492. //// 监听 PJAX 完成后,重新加载
  493. document.addEventListener('pjax:complete', async function () {
  494. await showMarkdown(await getPValue());
  495. initCustomPJAXEventListener(); //// 重新初始化自定义 PJAX 事件监听器
  496. });
  497. //// 监听 animationend 事件
  498. document.addEventListener('animationend', function handleAnimationEnd(event) {
  499. if (event.animationName === 'Animation-slideInRight') {
  500. const element = document.querySelector('.markdown-body .content');
  501. element.classList.remove('Animated');
  502. element.classList.remove('Animate--slideInRight');
  503. } else if (event.animationName === 'Animation-slideInLeft') {
  504. document.querySelector('.markdown-body .old-content').remove();
  505. }
  506. });
  507. //// 点击事件委托
  508. document.addEventListener('click', function (event) {
  509. const imgOrSvg = event.target.closest('.content img, .content svg');
  510. if (imgOrSvg) {
  511. const url = imgOrSvg.getAttribute('src') || imgOrSvg.getAttribute('xlink:href');
  512. if (url) {
  513. window.open(url, '_blank');
  514. event.preventDefault();
  515. return;
  516. } else {
  517. const newWindow = window.open('', '_blank');
  518. newWindow.document.write(imgOrSvg.outerHTML);
  519. newWindow.document.close();
  520. event.preventDefault();
  521. return;
  522. }
  523. }
  524. if (event.target.closest('.back-btn')) {
  525. window.history.back();
  526. } else if (event.target.closest('.refresh-btn')) {
  527. window.location.reload();
  528. } else if (event.target.closest('.dark-btn')) {
  529. darkmode.toggle();
  530. } else if (event.target.closest('.translate-switch')) {
  531. translate.changeLanguage(translate.language.getLocal());
  532. } else if (event.target.closest('a[href^="#"]')) {
  533. // 目录平滑移动
  534. const href = event.target.getAttribute('href');
  535. if (href !== '#') {
  536. event.preventDefault();
  537. const targetElement = document.querySelector(href);
  538. if (targetElement) {
  539. targetElement.scrollIntoView({
  540. behavior: 'smooth'
  541. });
  542. } else {
  543. console.error(`ID 为 ${targetId} 的元素不存在。`);
  544. }
  545. }
  546. }
  547. });
  548. //// 文档内容加载完毕时触发
  549. async function showMarkdownEnded() {
  550. refreshTranslate();
  551. infoTranslate(); //// 检查并提示翻译
  552. await mermaid.init({ noteMargin: 10 }, '.language-mermaid'); //// 初始化 mermaid
  553. translate.execute(); //// 手动触发翻译,但是理论上 translate-js 会监听页面变化
  554. hljs.highlightAll(); //// 触发代码块语法高亮
  555. endLoad();
  556. window.scrollTo({
  557. top: 0,
  558. behavior: 'smooth'
  559. });
  560. }
  561. //// 浏览器返回时触发
  562. window.onpopstate = function (event) {
  563. if (level > 1) {
  564. --level;
  565. }
  566. };
  567. })();
  568. </script>
  569. <title>加载中</title>
  570. <style>
  571. /* 全局 */
  572. :root,
  573. html,
  574. body,
  575. button,
  576. input,
  577. select,
  578. textarea,
  579. code,
  580. pre {
  581. font-family: 'Sarasa Term SC Nerd', 'Maple Mono CN', Ubuntu, Roboto, 'Open Sans', 'Microsoft YaHei', Arial, sans-serif;
  582. text-decoration: none;
  583. }
  584. :root,
  585. html,
  586. body {
  587. background-color: #e6e6e6;
  588. }
  589. ::selection {
  590. background-color: #DCEDC8;
  591. }
  592. body {
  593. margin: 0;
  594. }
  595. a {
  596. color: #66BB6A;
  597. cursor: pointer;
  598. text-decoration: none;
  599. }
  600. a:hover {
  601. color: #2E7D32;
  602. }
  603. /* 背景 */
  604. .background {
  605. position: fixed;
  606. left: 0;
  607. top: 0;
  608. height: 100%;
  609. width: 100%;
  610. z-index: -1;
  611. background-color: #e6e6e6;
  612. }
  613. /* 导航栏 */
  614. nav {
  615. position: fixed;
  616. top: 0;
  617. right: 0;
  618. width: min-content;
  619. background-color: #616161;
  620. display: flex;
  621. justify-content: space-between;
  622. align-items: center;
  623. z-index: 1;
  624. }
  625. nav a {
  626. color: #FAFAFA;
  627. padding: .3rem;
  628. transition:
  629. color .2s,
  630. background-color .2s;
  631. }
  632. nav a:hover {
  633. color: #FFF;
  634. background-color: #212121;
  635. }
  636. /* 动画 */
  637. .Animated {
  638. animation-fill-mode: both;
  639. animation-duration: 1s;
  640. }
  641. .Animated-remove {
  642. position: absolute;
  643. }
  644. .Animated--reverse {
  645. animation-direction: reverse
  646. }
  647. .Animate--fast {
  648. animation-duration: .5s
  649. }
  650. .Animate--noDelay {
  651. animation-delay: 0s !important;
  652. }
  653. .Animate--slideInRight {
  654. animation-name: Animation-slideInRight
  655. }
  656. @keyframes Animation-slideInRight {
  657. 0% {
  658. transform: translateX(200%);
  659. }
  660. 100% {
  661. transform: translateX(0);
  662. }
  663. }
  664. .Animate--slideInLeft {
  665. animation-name: Animation-slideInLeft
  666. }
  667. @keyframes Animation-slideInLeft {
  668. 0% {
  669. transform: translateX(-100%);
  670. }
  671. 100% {
  672. transform: translateX(0);
  673. }
  674. }
  675. /* 主要内容 */
  676. .markdown-body {
  677. position: relative;
  678. margin: 3rem auto;
  679. width: 100%;
  680. max-width: 950px;
  681. min-height: 300px;
  682. background-color: #FAFAFA;
  683. color: #212121;
  684. box-sizing: border-box;
  685. overflow-x: hidden;
  686. box-shadow: 0 2px 6px rgba(100, 100, 100, .3);
  687. }
  688. .markdown-body .content,
  689. .markdown-body .old-content {
  690. margin: 2rem;
  691. }
  692. .markdown-body img,
  693. .markdown-body video,
  694. .markdown-body iframe,
  695. .markdown-body object,
  696. .markdown-body embed,
  697. .markdown-body svg,
  698. .markdown-body canvas,
  699. .markdown-body audio {
  700. max-width: 100%;
  701. background-color: rgba(0, 0, 0, 0.05);
  702. }
  703. /* Markdown 样式 */
  704. .markdown-body a {
  705. transition:
  706. color .2s,
  707. background-color .2s;
  708. }
  709. .markdown-body a:hover {
  710. background-color: rgba(255, 255, 255, 0.1);
  711. }
  712. .markdown-body ul,
  713. .markdown-body ol {
  714. padding-left: 2rem;
  715. }
  716. .markdown-body pre {
  717. background-color: rgba(0, 0, 0, 0.05);
  718. padding: .4rem;
  719. border-radius: .1rem;
  720. overflow-y: scroll;
  721. }
  722. .markdown-body code {
  723. font-family: "cousine nerd font mono", monospace;
  724. background-color: rgba(0, 0, 0, 0.05);
  725. font-size: small;
  726. padding: .2rem;
  727. border-radius: .1rem;
  728. }
  729. .markdown-body pre code {
  730. background-color: unset;
  731. font-size: unset;
  732. padding: unset;
  733. border-radius: unset;
  734. }
  735. .markdown-body blockquote {
  736. background-color: rgba(0, 0, 0, 0.05);
  737. font-size: small;
  738. padding: .4rem;
  739. margin: .5rem 2rem;
  740. border-left: 5px solid rgba(0, 0, 0, 0.1);
  741. }
  742. .markdown-body details {
  743. border: 1px solid rgba(0, 0, 0, 0.1);
  744. border-radius: .1rem;
  745. }
  746. .markdown-body summary {
  747. font-size: small;
  748. cursor: pointer;
  749. background-color: rgba(0, 0, 0, 0.05);
  750. padding: .4rem;
  751. font-weight: bold;
  752. }
  753. .markdown-body details a {
  754. margin-left: -2rem;
  755. }
  756. .markdown-body table {
  757. border-spacing: 0;
  758. border-radius: .1rem;
  759. width: 100%;
  760. border-collapse: separate;
  761. border: .1rem solid rgba(0, 0, 0, 0.05);
  762. }
  763. .markdown-body table td,
  764. .markdown-body table th {
  765. border-right: .1rem solid rgba(0, 0, 0, 0.05);
  766. }
  767. .markdown-body table td,
  768. .markdown-body table th {
  769. border-top: .1rem solid rgba(0, 0, 0, 0.05);
  770. }
  771. .markdown-body table td:last-child,
  772. .markdown-body th:last-child {
  773. border-right-color: transparent;
  774. }
  775. .markdown-body table thead tr:first-child>* {
  776. border-top: .1rem solid transparent;
  777. }
  778. /* 加载进度条 */
  779. .loading-bar {
  780. position: fixed;
  781. top: 0;
  782. left: 0;
  783. z-index: 2;
  784. opacity: 0;
  785. transition: opacity .4s linear;
  786. .progress {
  787. position: fixed;
  788. top: 0;
  789. left: 0;
  790. width: 0;
  791. height: 4px;
  792. background-color: #2E7D32;
  793. box-shadow: 0 0 10px rgba(102, 187, 106, .7);
  794. }
  795. &.loading {
  796. opacity: 1;
  797. transition: none;
  798. .progress {
  799. transition: width .4s ease;
  800. }
  801. }
  802. }
  803. /* 翻译按钮相关 */
  804. .translateSelectLanguage {
  805. background-color: #616161;
  806. color: inherit;
  807. z-index: 3;
  808. width: 17%;
  809. height: 100%;
  810. opacity: 0;
  811. cursor: pointer;
  812. position: absolute;
  813. top: 0;
  814. left: 50%;
  815. }
  816. /* 深色模式相关 */
  817. .darkmode--activated .markdown-body img,
  818. .darkmode--activated .markdown-body svg {
  819. isolation: isolate;
  820. mix-blend-mode: difference
  821. }
  822. .darkmode-layer,
  823. .darkmode-toggle {
  824. z-index: 3
  825. }
  826. /* 小屏响应式优化 */
  827. @media only screen and (max-width: 950px) {
  828. html,
  829. body,
  830. .markdown-body {
  831. height: 100%;
  832. }
  833. .markdown-body {
  834. overflow-y: scroll;
  835. min-width: 256px;
  836. top: 0;
  837. margin: 0 0;
  838. }
  839. }
  840. </style>
  841. <link href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-y/highlight.js/11.4.0/styles/default.min.css"
  842. type="text/css" rel="stylesheet" />
  843. <link rel="stylesheet"
  844. href="https://chinese-fonts-cdn.deno.dev/packages/maple-mono-cn/dist/MapleMono-CN-Regular/result.css" />
  845. </head>
  846. <body>
  847. <!-- 导航栏 -->
  848. <nav>
  849. <a title="返回" class="back-btn">
  850. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  851. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  852. class="icon icon-tabler icons-tabler-outline icon-tabler-arrow-back">
  853. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  854. <path d="M9 11l-4 4l4 4m-4 -4h11a4 4 0 0 0 0 -8h-1" />
  855. </svg>
  856. </a>
  857. <a title="刷新" class="refresh-btn" href="">
  858. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  859. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  860. class="icon icon-tabler icons-tabler-outline icon-tabler-refresh">
  861. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  862. <path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" />
  863. <path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" />
  864. </svg>
  865. </a>
  866. <a title="主页" class="to-home">
  867. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  868. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  869. class="icon icon-tabler icons-tabler-outline icon-tabler-home">
  870. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  871. <path d="M5 12l-2 0l9 -9l9 9l-2 0" />
  872. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  873. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  874. </svg>
  875. </a>
  876. <a title="更改语言" id="translate">
  877. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  878. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  879. class="icon icon-tabler icons-tabler-outline icon-tabler-language">
  880. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  881. <path d="M4 5h7" />
  882. <path d="M9 3v2c0 4.418 -2.239 8 -5 8" />
  883. <path d="M5 9c0 2.144 2.952 3.908 6.7 4" />
  884. <path d="M12 20l4 -9l4 9" />
  885. <path d="M19.1 18h-6.2" />
  886. </svg>
  887. </a>
  888. <a title="切换显示模式" class="dark-btn" href="javascript:;">
  889. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  890. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  891. class="icon icon-tabler icons-tabler-outline icon-tabler-brightness">
  892. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  893. <path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
  894. <path d="M12 3l0 18" />
  895. <path d="M12 9l4.65 -4.65" />
  896. <path d="M12 14.3l7.37 -7.37" />
  897. <path d="M12 19.6l8.85 -8.85" />
  898. </svg>
  899. </a>
  900. <a title="关于" class="about-btn">
  901. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  902. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  903. class="icon icon-tabler icons-tabler-outline icon-tabler-info-circle">
  904. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  905. <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
  906. <path d="M12 9h.01" />
  907. <path d="M11 12h1v4h1" />
  908. </svg>
  909. </a>
  910. </nav>
  911. <!-- 内容主体 -->
  912. <div class="markdown-body">
  913. <div class="content">
  914. <h1>加载中……</h1>
  915. <p>请稍等。</p>
  916. </div>
  917. </div>
  918. <!-- 加载动画 -->
  919. <div class="loading-bar">
  920. <div class="progress"></div>
  921. </div>
  922. <div class="background"></div>
  923. <script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/instant.page/5.1.0/instantpage.min.js"
  924. type="text/javascript"></script>
  925. </body>
  926. </html>