Skip to content Skip to sidebar Skip to footer

Crossrider: Store Snapshot Of Bookmarks In Local Database And Compare To Current Bookmarks List

How do I store a snapshot of the bookmarks list and then compare that to the current bookmars list every n amount of time with a conditional statement that outputs any bookmarks th

Solution 1:

Conceptually, you can achieve your goal by storing the previous bookmarks list in the extension's local database using appAPI.db.async, comparing it to the current bookmark list obtained using appAPI.bookmarks.getTree, and sending it to your API server using appAPI.request.post.

You can use the following code in your background.js file as your starting point for handling the bookmarks lists and write your own comparison function (getChanges) as you require:

appAPI.ready(function() {
  // Poll every 30 secondssetInterval(function() {
    appAPI.db.async.get('prevBookmarks', function(value) {
      // Load or initialize previous bookmarks listvar prevBookmarks = (value) ? value : {};

      // Get current bookmarks
      appAPI.bookmarks.getTree(function(nodes) {
        // Save bookmark list for next comparison
        appAPI.db.async.set('prevBookmarks', nodes);

        // In your getChanges functions, traverse the bookmark trees collating// changes and then post then to your API server using appAPI.requestvar changes = getChanges(prevBookmarks, nodes);
        appAPI.request.post({
          url: http://yourAPIserver.com,postData: changes,
          contentType: 'application/json'
        });
      });
    });
  }, 30 * 1000);
});

Post a Comment for "Crossrider: Store Snapshot Of Bookmarks In Local Database And Compare To Current Bookmarks List"