Add bookmark script.

Add a script that saves the position on read pages to localstorage, and
restores the page position when the page is reloaded.
This commit is contained in:
Robin Malley 2021-04-04 06:11:55 +00:00
parent fdf0b67f3a
commit fd87cf95ee
3 changed files with 13 additions and 0 deletions

9
assets/bookmark.js Normal file
View File

@ -0,0 +1,9 @@
window.onbeforeunload = function(e) {
localStorage.setItem(window.location.pathname,window.scrollY)
}
document.addEventListener("DOMContentLoaded", function(e) {
var scrollpos = localStorage.getItem(window.location.pathname)
if(scrollpos)
window.scrollTo(0,scrollpos)
})

View File

@ -45,6 +45,7 @@ domain * {
route /_css/milligram.min.css.map asset_serve_milligram_min_css_map
route /_faq asset_serve_faq_html
route /_js/suggest_tags.js asset_serve_suggest_tags_js
route /_js/bookmark.js asset_serve_bookmark_js
route /favicon.ico asset_serve_favicon_ico
route /_paste post_story
route /_edit edit_story

View File

@ -97,6 +97,9 @@ local function read_get(req)
host = http_request_get_host(req),
path = http_request_get_path(req),
method = http_method_text(req),
extra_load = {
'<script src="/_js/bookmark.js"></script>'
}
}
local err
--Get our story id