-
-
Save MadinaB/f9baeee9b2d0b611772ed39ae0e5c521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
background.js : | |
if (!localStorage.isInitialized) { | |
localStorage.isInitialized = true; | |
localStorage.setItem('LatestDate', ''); | |
localStorage.setItem('currentWebsites', '{}'); | |
localStorage.setItem('backup',''); | |
} | |
console.log('hi'); | |
setInterval(function() { | |
var hostname = window.location.hostname; | |
if(localStorage.getItem(hostname) === null){ | |
localStorage.setItem(hostname,'0'); | |
var websites = JSON.parse(localStorage.getItem('currentWebsites')); | |
websites.push(hostname); | |
localStorage.setItem('currentWebsites', JSON.stringify(websites)); | |
} | |
else{ | |
var seconds = parseInt(localStorage.getItem(hostname)); | |
localStorage.setItem(hostname,(seconds+1)); | |
} | |
// console.log(localStorage.getItem(hostname)); | |
var w = localStorage.getItem( 'currentWebsites' ); | |
console.table(JSON.parse(w)); | |
}, 1000); | |
// console.log('currentWebsites'); | |
//console.log(localStorage.getItem('currentWebsites')); | |
This throws this error: | |
Unexpected token c in JSON at position 0 | |
at JSON.parse (<anonymous>) | |
because of: | |
var w = localStorage.getItem( 'currentWebsites' ); | |
console.table(JSON.parse(w)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment