Skip to content

Instantly share code, notes, and snippets.

@MadinaB
Created March 17, 2018 11:51
Show Gist options
  • Save MadinaB/f9baeee9b2d0b611772ed39ae0e5c521 to your computer and use it in GitHub Desktop.
Save MadinaB/f9baeee9b2d0b611772ed39ae0e5c521 to your computer and use it in GitHub Desktop.
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