index.html 34 KB

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