From 082389430ee0aa79951e7598baede89e8b157e84 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 4 Jan 2025 15:09:12 -0800 Subject: [PATCH] fixed CSP error with inline js --- app.py | 10 +++++++++- html/navbar.html | 13 +++---------- js/shortcode.js | 8 ++++++++ 3 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 js/shortcode.js diff --git a/app.py b/app.py index 0d036b1..9243c97 100644 --- a/app.py +++ b/app.py @@ -111,6 +111,7 @@ cached: dict = { "css_response": open("styles/human_readable.css", "r").read(), "css_collapsible": open("styles/collapsible.css", "r").read(), "js_collapsible": open("js/collapsible.js", "r").read(), + "js_shortcode": open("js/shortcode.js", "r").read(), } # Fill the chapter list with unique chapters for seeking back and forward by index. @@ -125,6 +126,13 @@ for book in range(1, 67): "SELECT c FROM fts_kjv where b = ? ORDER BY id DESC LIMIT 1;", (book,) ).fetchone()[0] +@app.get("/js/shortcode.js") +def serve_shortcode_js(): + return cached.get("js_shortcode") + +@app.get("/js/collapsible.js") +def serve_collapsible_js(): + return cached.get("js_collapsible") def generate_short_id(): remain = random.randrange(614_656, 17_210_367) # resolves to length of 5 @@ -467,7 +475,7 @@ def parse_query(query_override: str = None): ) result += "
" + definition + "
" logging.debug(f"parse_query.define = '{word}'") - result += "" + result += "" result += "
" # result += search() #logging.debug(f"parse_query.search = '{result}'") diff --git a/html/navbar.html b/html/navbar.html index 42d8482..b653ba5 100644 --- a/html/navbar.html +++ b/html/navbar.html @@ -22,14 +22,7 @@ {next_chapter_name} → - - \ No newline at end of file + diff --git a/js/shortcode.js b/js/shortcode.js new file mode 100644 index 0000000..1ed605a --- /dev/null +++ b/js/shortcode.js @@ -0,0 +1,8 @@ +function make_shortcode(){{ + var xmlHttp = new XMLHttpRequest(); + const theUrl = "/mksc/" + document.getElementById("searchBar").value; + xmlHttp.open( "GET", theUrl, false ); // false for synchronous request + xmlHttp.send( null ); + document.getElementById("context_href").innerHTML = xmlHttp.responseText; + document.getElementById('context_href').setAttribute("href", "/" + xmlHttp.responseText); +}}