1
0

index.html 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. <!doctype html>
  2. <html>
  3. <markdown-html version="1.15.2" 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 文件,即可完成 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}](?p=${linkHref})`; // 链接格式与 window.location.search 一致
  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. } else {
  536. const newWindow = window.open('', '_blank');
  537. newWindow.document.write(imgOrSvg.outerHTML);
  538. newWindow.document.close();
  539. event.preventDefault();
  540. }
  541. return;
  542. }
  543. if (event.target.closest('.back-btn')) {
  544. window.history.back();
  545. } else if (event.target.closest('.refresh-btn')) {
  546. window.location.reload();
  547. } else if (event.target.closest('.dark-btn')) {
  548. darkmode.toggle();
  549. } else if (event.target.closest('.translate-switch')) {
  550. translate.changeLanguage(translate.language.getLocal());
  551. // 跳转。禁用原因是有些带有特殊字符的链接会出错或无法跳转
  552. // } else if (event.target.closest('.content 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. } else if (event.target.closest('.content a:not([href^="?"]):not([href^="#"]):not([href^="javascript:"])')) {
  567. const link = event.target.closest('a');
  568. if (link && link.href) {
  569. window.open(link.href, '_blank');
  570. event.preventDefault();
  571. return;
  572. }
  573. }
  574. });
  575. //// 文档内容加载完毕时触发
  576. async function showMarkdownEnded() {
  577. refreshTranslate();
  578. infoTranslate(); //// 检查并提示翻译
  579. await mermaid.init({ noteMargin: 10 }, '.language-mermaid'); //// 初始化 mermaid
  580. translate.execute(); //// 手动触发翻译,但是理论上 translate-js 会监听页面变化
  581. hljs.highlightAll(); //// 触发代码块语法高亮
  582. endLoad();
  583. window.scrollTo({
  584. top: 0,
  585. behavior: 'smooth'
  586. });
  587. }
  588. //// 浏览器返回时触发
  589. window.onpopstate = function (event) {
  590. if (level > 1) {
  591. --level;
  592. }
  593. };
  594. })();
  595. </script>
  596. <title>加载中</title>
  597. <style>
  598. /* 全局 */
  599. :root,
  600. html,
  601. body,
  602. button,
  603. input,
  604. select,
  605. textarea,
  606. code,
  607. pre {
  608. font-family: 'Sarasa Term SC Nerd', 'Maple Mono CN', Ubuntu, Roboto, 'Open Sans', 'Microsoft YaHei', Arial, sans-serif;
  609. text-decoration: none;
  610. }
  611. :root,
  612. html,
  613. body {
  614. background-color: #e6e6e6;
  615. }
  616. ::selection {
  617. background-color: #DCEDC8;
  618. }
  619. body {
  620. margin: 0;
  621. }
  622. a {
  623. color: #66BB6A;
  624. cursor: pointer;
  625. text-decoration: none;
  626. }
  627. a:hover {
  628. color: #2E7D32;
  629. }
  630. /* 背景 */
  631. .background {
  632. position: fixed;
  633. left: 0;
  634. top: 0;
  635. height: 100%;
  636. width: 100%;
  637. z-index: -1;
  638. background-color: #e6e6e6;
  639. }
  640. /* 导航栏 */
  641. nav {
  642. position: fixed;
  643. top: 0;
  644. right: 0;
  645. width: min-content;
  646. background-color: #616161;
  647. display: flex;
  648. justify-content: space-between;
  649. align-items: center;
  650. z-index: 1;
  651. }
  652. nav a {
  653. color: #FAFAFA;
  654. padding: .3rem;
  655. transition:
  656. color .2s,
  657. background-color .2s;
  658. }
  659. nav a:hover {
  660. color: #FFF;
  661. background-color: #212121;
  662. }
  663. /* 动画 */
  664. .Animated {
  665. animation-fill-mode: both;
  666. animation-duration: 1s;
  667. }
  668. .Animated-remove {
  669. position: absolute;
  670. }
  671. .Animated--reverse {
  672. animation-direction: reverse
  673. }
  674. .Animate--fast {
  675. animation-duration: .5s
  676. }
  677. .Animate--noDelay {
  678. animation-delay: 0s !important;
  679. }
  680. .Animate--slideInRight {
  681. animation-name: Animation-slideInRight
  682. }
  683. @keyframes Animation-slideInRight {
  684. 0% {
  685. transform: translateX(200%);
  686. }
  687. 100% {
  688. transform: translateX(0);
  689. }
  690. }
  691. .Animate--slideInLeft {
  692. animation-name: Animation-slideInLeft
  693. }
  694. @keyframes Animation-slideInLeft {
  695. 0% {
  696. transform: translateX(-100%);
  697. }
  698. 100% {
  699. transform: translateX(0);
  700. }
  701. }
  702. /* 主要内容 */
  703. .markdown-body {
  704. position: relative;
  705. margin: 3rem auto;
  706. width: 100%;
  707. max-width: 950px;
  708. min-height: 300px;
  709. background-color: #FAFAFA;
  710. color: #212121;
  711. box-sizing: border-box;
  712. overflow-x: hidden;
  713. box-shadow: 0 2px 6px rgba(100, 100, 100, .3);
  714. }
  715. .markdown-body .content,
  716. .markdown-body .old-content {
  717. margin: 2rem;
  718. }
  719. .markdown-body img,
  720. .markdown-body video,
  721. .markdown-body iframe,
  722. .markdown-body object,
  723. .markdown-body embed,
  724. .markdown-body svg,
  725. .markdown-body canvas,
  726. .markdown-body audio {
  727. max-width: 100%;
  728. background-color: rgba(0, 0, 0, 0.05);
  729. }
  730. /* Markdown 样式 */
  731. .markdown-body a {
  732. transition:
  733. color .2s,
  734. background-color .2s;
  735. }
  736. .markdown-body a:hover {
  737. background-color: rgba(255, 255, 255, 0.1);
  738. }
  739. .markdown-body ul,
  740. .markdown-body ol {
  741. padding-left: 2rem;
  742. }
  743. .markdown-body pre {
  744. background-color: rgba(0, 0, 0, 0.05);
  745. padding: .4rem;
  746. border-radius: .1rem;
  747. overflow-y: scroll;
  748. }
  749. .markdown-body code {
  750. font-family: "cousine nerd font mono", monospace;
  751. background-color: rgba(0, 0, 0, 0.05);
  752. font-size: small;
  753. padding: .2rem;
  754. border-radius: .1rem;
  755. }
  756. .markdown-body pre code {
  757. background-color: unset;
  758. font-size: unset;
  759. padding: unset;
  760. border-radius: unset;
  761. }
  762. .markdown-body blockquote {
  763. background-color: rgba(0, 0, 0, 0.05);
  764. font-size: small;
  765. padding: .4rem;
  766. margin: .5rem 2rem;
  767. border-left: 5px solid rgba(0, 0, 0, 0.1);
  768. }
  769. .markdown-body details {
  770. border: 1px solid rgba(0, 0, 0, 0.1);
  771. border-radius: .1rem;
  772. }
  773. .markdown-body summary {
  774. font-size: small;
  775. cursor: pointer;
  776. background-color: rgba(0, 0, 0, 0.05);
  777. padding: .4rem;
  778. font-weight: bold;
  779. }
  780. .markdown-body details a {
  781. margin-left: -2rem;
  782. }
  783. .markdown-body table {
  784. border-spacing: 0;
  785. border-radius: .1rem;
  786. width: 100%;
  787. border-collapse: separate;
  788. border: .1rem solid rgba(0, 0, 0, 0.05);
  789. }
  790. .markdown-body table td,
  791. .markdown-body table th {
  792. border-right: .1rem solid rgba(0, 0, 0, 0.05);
  793. }
  794. .markdown-body table td,
  795. .markdown-body table th {
  796. border-top: .1rem solid rgba(0, 0, 0, 0.05);
  797. }
  798. .markdown-body table td:last-child,
  799. .markdown-body th:last-child {
  800. border-right-color: transparent;
  801. }
  802. .markdown-body table thead tr:first-child>* {
  803. border-top: .1rem solid transparent;
  804. }
  805. /* 加载进度条 */
  806. .loading-bar {
  807. position: fixed;
  808. top: 0;
  809. left: 0;
  810. z-index: 2;
  811. opacity: 0;
  812. transition: opacity .4s linear;
  813. .progress {
  814. position: fixed;
  815. top: 0;
  816. left: 0;
  817. width: 0;
  818. height: 4px;
  819. background-color: #2E7D32;
  820. box-shadow: 0 0 10px rgba(102, 187, 106, .7);
  821. }
  822. &.loading {
  823. opacity: 1;
  824. transition: none;
  825. .progress {
  826. transition: width .4s ease;
  827. }
  828. }
  829. }
  830. /* 翻译按钮相关 */
  831. .translateSelectLanguage {
  832. background-color: #616161;
  833. color: inherit;
  834. z-index: 3;
  835. width: 17%;
  836. height: 100%;
  837. opacity: 0;
  838. cursor: pointer;
  839. position: absolute;
  840. top: 0;
  841. left: 50%;
  842. }
  843. /* 深色模式相关 */
  844. .darkmode--activated .markdown-body img,
  845. .darkmode--activated .markdown-body svg {
  846. isolation: isolate;
  847. mix-blend-mode: difference
  848. }
  849. .darkmode-layer,
  850. .darkmode-toggle {
  851. z-index: 3
  852. }
  853. /* 小屏响应式优化 */
  854. @media only screen and (max-width: 950px) {
  855. html,
  856. body,
  857. .markdown-body {
  858. height: 100%;
  859. }
  860. .markdown-body {
  861. overflow-y: scroll;
  862. min-width: 256px;
  863. top: 0;
  864. margin: 0 0;
  865. }
  866. }
  867. </style>
  868. <link href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-y/highlight.js/11.4.0/styles/default.min.css"
  869. type="text/css" rel="stylesheet" />
  870. <link rel="stylesheet"
  871. href="https://chinese-fonts-cdn.deno.dev/packages/maple-mono-cn/dist/MapleMono-CN-Regular/result.css" />
  872. </head>
  873. <body>
  874. <!-- 导航栏 -->
  875. <nav>
  876. <a title="返回" class="back-btn">
  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-arrow-back">
  880. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  881. <path d="M9 11l-4 4l4 4m-4 -4h11a4 4 0 0 0 0 -8h-1" />
  882. </svg>
  883. </a>
  884. <a title="刷新" class="refresh-btn" href="">
  885. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  886. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  887. class="icon icon-tabler icons-tabler-outline icon-tabler-refresh">
  888. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  889. <path d="M20 11a8.1 8.1 0 0 0 -15.5 -2m-.5 -4v4h4" />
  890. <path d="M4 13a8.1 8.1 0 0 0 15.5 2m.5 4v-4h-4" />
  891. </svg>
  892. </a>
  893. <a title="主页" class="to-home">
  894. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  895. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  896. class="icon icon-tabler icons-tabler-outline icon-tabler-home">
  897. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  898. <path d="M5 12l-2 0l9 -9l9 9l-2 0" />
  899. <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  900. <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
  901. </svg>
  902. </a>
  903. <a title="更改语言" id="translate">
  904. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  905. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  906. class="icon icon-tabler icons-tabler-outline icon-tabler-language">
  907. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  908. <path d="M4 5h7" />
  909. <path d="M9 3v2c0 4.418 -2.239 8 -5 8" />
  910. <path d="M5 9c0 2.144 2.952 3.908 6.7 4" />
  911. <path d="M12 20l4 -9l4 9" />
  912. <path d="M19.1 18h-6.2" />
  913. </svg>
  914. </a>
  915. <a title="切换显示模式" class="dark-btn" href="javascript:;">
  916. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  917. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  918. class="icon icon-tabler icons-tabler-outline icon-tabler-brightness">
  919. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  920. <path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" />
  921. <path d="M12 3l0 18" />
  922. <path d="M12 9l4.65 -4.65" />
  923. <path d="M12 14.3l7.37 -7.37" />
  924. <path d="M12 19.6l8.85 -8.85" />
  925. </svg>
  926. </a>
  927. <a title="关于" class="about-btn">
  928. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
  929. stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  930. class="icon icon-tabler icons-tabler-outline icon-tabler-info-circle">
  931. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  932. <path d="M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0" />
  933. <path d="M12 9h.01" />
  934. <path d="M11 12h1v4h1" />
  935. </svg>
  936. </a>
  937. </nav>
  938. <!-- 内容主体 -->
  939. <div class="markdown-body">
  940. <div class="content">
  941. <h1>加载中……</h1>
  942. <p>请稍等。</p>
  943. </div>
  944. </div>
  945. <!-- 加载动画 -->
  946. <div class="loading-bar">
  947. <div class="progress"></div>
  948. </div>
  949. <div class="background"></div>
  950. <script src="https://lf6-cdn-tos.bytecdntp.com/cdn/expire-1-y/instant.page/5.1.0/instantpage.min.js"
  951. type="text/javascript"></script>
  952. </body>
  953. </html>