From fd87cf95ee463a4a84766f95afb538c00ff0e06f Mon Sep 17 00:00:00 2001 From: Robin Malley Date: Sun, 4 Apr 2021 06:11:55 +0000 Subject: [PATCH] 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. --- assets/bookmark.js | 9 +++++++++ conf/smr.conf.in | 1 + src/lua/endpoints/read_get.lua | 3 +++ 3 files changed, 13 insertions(+) create mode 100644 assets/bookmark.js diff --git a/assets/bookmark.js b/assets/bookmark.js new file mode 100644 index 0000000..8362005 --- /dev/null +++ b/assets/bookmark.js @@ -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) +}) diff --git a/conf/smr.conf.in b/conf/smr.conf.in index 3f36dab..9de3ed0 100644 --- a/conf/smr.conf.in +++ b/conf/smr.conf.in @@ -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 diff --git a/src/lua/endpoints/read_get.lua b/src/lua/endpoints/read_get.lua index 17fb549..354f094 100644 --- a/src/lua/endpoints/read_get.lua +++ b/src/lua/endpoints/read_get.lua @@ -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 = { + '' + } } local err --Get our story id