chrome.storage.sync -> Storing Dictionary

145 views
Skip to first unread message

Kayla Green

unread,
Aug 12, 2015, 5:33:14 PM8/12/15
to Chromium-extensions
Hey there!

I'm trying to figure out the best way to store a dictionary that has multiple entries and is updated anytime a user visits a given list of websites. 

Let's say it looks something like this:

var website {}
website
["google.com"] = 121315;
website
["bing.com"] = 071915;


I'm looking to store this information using chrome.storage.sync, but the number of entries I'm looking to have is around ~300 websites, so it seems kind of excessive to store these as individual key:value pairs, like so: chrome.storage.sync({url : timestamp}, function () { return; } )'
Is there a way for me to use chrome storage sync like the following?

var list = ["google.com", "bing.com"]
if (list.indexOf(tab.url) > -1) {
  time
= Date.now();
  chrome
.storage.sync.set({websites[tab.url] : time}. function() { console.log( tab.url + " has been updated to time: " + time ); });
}


I can't seem to make this work, so I'm not sure if it's possible. 

Kayla Green

unread,
Aug 12, 2015, 5:42:30 PM8/12/15
to Chromium-extensions
Actually, that code does the same thing, which isn't what I want. 

I guess what I'm getting as it I want to store a dictionary as one single entry in chrome.storage.sync, and be able to update each entry without having to do something like:
chrome.storage.sync.get( "websites", function(obj) {
  obj
[tab.url] = new_time;
  chrome
.storage.sync.set( {website : obj}, function () {
      console
.log ( "Updated " + tab.url + " to " + new_time );
   
});
});
Reply all
Reply to author
Forward
0 new messages