Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lmj01 committed May 11, 2024
1 parent 93b4b92 commit f0b63c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 7 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ body {
em {
font-style: normal;
font-weight: bolder;
}
.mj-navigate-btn {
position: fixed;
top: 0;
right: 0;
margin-right: 10px;
margin-top: 10px;
}
16 changes: 10 additions & 6 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ hljs.registerLanguage('cpp', languageCpp);

const rootRelative = location.pathname;
const rootOrigin = location.origin;
const ud = {};
const ud = {
cacheUrls: [],
};
// 测试
document.getElementById('content').innerHTML = marked.parse('# Marked in the browser\n\nRendered by **marked**.');
const elBtnBack = document.createElement('button');
elBtnBack.classList.add('btn', 'btn-primary', 'position-absolute', 'top-0', 'right-0');
elBtnBack.classList.add('btn', 'btn-primary', 'mj-navigate-btn');
elBtnBack.textContent = 'Back';
elBtnBack.addEventListener('click', ()=>{
if (ud.cacheHref) {
console.log(ud.cacheUrls)
ud.cacheUrls.pop();
if (ud.cacheUrls.length > 0) {
const elTag = document.createElement('a');
elTag.href = ud.cacheHref;
elTag.href = ud.cacheUrls.pop();
tagLinkClickCaption(null, elTag)
}
})
Expand Down Expand Up @@ -71,15 +75,14 @@ function tagLinkClickCaption(event, aLink) {
event.preventDefault();
}
const strHref = aLink.href;
ud.cacheHref = strHref;
ud.cacheUrls.push(strHref);
const ext = strHref.substring(strHref.lastIndexOf('.') + 1);
const isSameOrigin = strHref.startsWith(rootOrigin) && ['md','js','cpp','lua'].includes(ext);
if (isSameOrigin) {
// 只解析本地的markdown文件
const tmp = `${rootRelative}${strHref.replace(rootOrigin,'').replace(rootRelative, '').replace('//', '/')}`;
fetch(tmp).then(res=>res.text()).then(text=>updateContent(text, {ext: ext}));
} else {
// window.open(aLink.href);
/**
* 不调整,还是留着当前页面内
*/
Expand All @@ -93,4 +96,5 @@ function tagLinkUpdateEvent(aLink) {
}

// 获取所有
ud.cacheUrls = [];
document.querySelectorAll('.side-menu a').forEach(a => tagLinkUpdateEvent(a));

0 comments on commit f0b63c3

Please sign in to comment.