1
0

index.html 33 KB

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