Merge pull request #976 from JesuisTong/main

feat: add viewed style
pull/977/head
Sunface 2 years ago committed by GitHub
commit 5196105f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -173,9 +173,31 @@
<script type="text/javascript"> <script type="text/javascript">
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible'); document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible'); document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
// Get viewed page store
var viewed_key = 'mdbook-viewed';
var viewed_map = {};
try {
var viewed_storage = localStorage.getItem(viewed_key);
if (viewed_storage) {
viewed_map = JSON.parse(viewed_storage)
}
} catch (e) { }
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) { Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1); link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
// Apply viewed style
if (viewed_map[link.pathname]) {
link.classList.add('md-viewed')
}
}); });
// Mark viewed after 30s
setTimeout(function() {
viewed_map[location.pathname] = 1;
localStorage.setItem(viewed_key, JSON.stringify(viewed_map));
}, 30000)
</script> </script>
<div id="content" class="content"> <div id="content" class="content">

@ -113,3 +113,6 @@ code.editable, .ace_scroller {
margin-top: 8px; margin-top: 8px;
} }
.chapter li .md-viewed {
color: #777;
}

Loading…
Cancel
Save