Skip to content

Commit

Permalink
Task #27 Bookmarking system. Adding constants for key names.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesgs authored and ardathksheyna committed Jul 23, 2017
1 parent ec270a3 commit c80fb4e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions assets/js/bookmark.js
Expand Up @@ -21,13 +21,33 @@

var BookMark = {
storage : null,

BOOKMARK_HISTORY : 'mangapress-bookmark-history',
BOOKMARK : 'mangapress-bookmark',
init: function() {
this.storage = localStorage;
},

bookmark : function() {

var href = window.location.href,
pageTitle = window.document.title,
data = {},
d = new Date();

var existingBookmarkData = this.storage.getItem(this.BOOKMARK);

if (existingBookmarkData) {
var bookmarkHistory = JSON.parse(this.storage.getItem(this.BOOKMARK_HISTORY));
bookmarkHistory.push(existingBookmarkData);
this.storage.setItem(this.BOOKMARK_HISTORY, JSON.stringify(bookmarkHistory));
}

data = {
url : href,
title : pageTitle,
date : Date.now()
};

this.storage.setItem(this.BOOKMARK, JSON.stringify(data));
},

history : function() {
Expand Down

0 comments on commit c80fb4e

Please sign in to comment.