Skip to content

Commit

Permalink
updating script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Rivas-Jorge committed Feb 19, 2023
1 parent 667f482 commit c5fbc25
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "books",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "test"
},
"author": "",
"license": "ISC"
}
25 changes: 25 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});

0 comments on commit c5fbc25

Please sign in to comment.