diff options
author | dan <[email protected]> | 2023-05-16 10:11:55 -0400 |
---|---|---|
committer | dan <[email protected]> | 2023-05-16 10:11:55 -0400 |
commit | b416c82ecc9ac8a94d059338c488507229d0996c (patch) | |
tree | 618bdc9d8b84b5ae3cf933d55db780f526aa351e | |
parent | aecc6ee8009fa70d012510a9babd50e5f364dece (diff) | |
download | simple-comments-widget-b416c82ecc9ac8a94d059338c488507229d0996c.tar.gz simple-comments-widget-b416c82ecc9ac8a94d059338c488507229d0996c.tar.bz2 simple-comments-widget-b416c82ecc9ac8a94d059338c488507229d0996c.zip |
fix: config moved to config.js
-rw-r--r-- | client.html | 1 | ||||
-rw-r--r-- | client.js | 14 | ||||
-rw-r--r-- | config.js | 4 |
3 files changed, 10 insertions, 9 deletions
diff --git a/client.html b/client.html index ada7604..68c6c90 100644 --- a/client.html +++ b/client.html @@ -27,6 +27,7 @@ </form> <div id="commentsthread"></div> + <script type="text/javascript" src="config.js"></script> <script type="text/javascript" src="client.js"></script> </body> </html> @@ -1,10 +1,6 @@ -/* Config */ -const pageId = 'add-page-id-here'; -const commentsUrl = `${baseUrl}?page_url=${pageId}`; - /* Running State */ let comments = []; - + /* LocalStorage Access */ function getDeletionKeys() { @@ -38,7 +34,7 @@ function commentsRender() { // GET comments function fetchComments() { - fetch(commentsUrl) + fetch(`${config.base_url}?page_url=${config.page_id}`) .then(r => r.ok && r.json()) .then(xs => { comments = xs; @@ -58,7 +54,7 @@ function generateRandomKey() { // POST new comment function createComment(comment) { comment.deletion_key = generateRandomKey(); - fetch(baseUrl, { + fetch(config.base_url, { method: 'POST', body: JSON.stringify(comment), headers: {'content-type': 'application/json'} @@ -76,7 +72,7 @@ function createComment(comment) { function handleCommentFormSubmit() { if (commentcontent.value !== "") { createComment({ - page_url: pageId, + page_url: config.page_id, content: `${commentcontent.value}\n - ${username.value}`, bot: bot.value }); @@ -87,7 +83,7 @@ function handleCommentFormSubmit() { // DELETE comment function handleDelete(commentId, deletionKey) { fetch( - `${baseUrl}?comment=${commentId}&deletion_key=${deletionKey}`, + `${config.base_url}?comment=${commentId}&deletion_key=${deletionKey}`, {method: 'DELETE'} ).then(r => { if (r.ok) { diff --git a/config.js b/config.js new file mode 100644 index 0000000..28e29eb --- /dev/null +++ b/config.js @@ -0,0 +1,4 @@ +const config = { + "base_url": "http://localhost:7060/comments", + "page_id": "add-page-id-here" +} |