From c5fbc25f61bb2fc6b485d7bf17ed91ffdeec8b90 Mon Sep 17 00:00:00 2001 From: J0rgeR1vas Date: Sun, 19 Feb 2023 14:52:15 -0600 Subject: [PATCH] updating script.js --- package-lock.json | 13 +++++++++++++ package.json | 11 +++++++++++ script.js | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 package-lock.json create mode 100644 package.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f00582f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "books", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "books", + "version": "1.0.0", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..74e8813 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "books", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "test" + }, + "author": "", + "license": "ISC" +} diff --git a/script.js b/script.js index c11361e..b5d2df2 100644 --- a/script.js +++ b/script.js @@ -36,3 +36,28 @@ function searchBook() { window.location.href = "lifeofpi.html"; } } + //bookmark + var bookmarkButtons = document.getElementsByClassName('bookmark-button'); + for (var i = 0; i < bookmarkButtons.length; i++) { + bookmarkButtons[i].addEventListener('click', function() { + var bookmarkKey = 'myBookmark'; + var bookmarkData = { + url: window.location.href, + title: document.title + }; + localStorage.setItem(bookmarkKey, JSON.stringify(bookmarkData)); + window.location.href = bookmarkData.url; + }); + } + //gets book mark info from local storage + window.addEventListener('load', function() { + var bookmarkKey = 'myBookmark'; + var bookmarkData = JSON.parse(localStorage.getItem(bookmarkKey)); + if (bookmarkData) { + console.log('Bookmarked page URL:', bookmarkData.url); + console.log('Bookmarked page title:', bookmarkData.title); + window.location.href = bookmarkData.url; + } else { + console.log('No bookmark data found'); + } + }); \ No newline at end of file