(function() { window.main = function() { /* the value '2' as DB version makes me laugh, but is the only way I can make it work... */ var request; request = indexedDB.open('openlog', 2); request.onupgradeneeded = function() { /* called whenever the DB changes version. triggers when the DB is created */ var db, store; db = request.result; store = db.createObjectStore('timestamps', { keyPath: 'id', autoIncrement: true }); return console.log('Database created or upgraded.'); }; return request.onsuccess = function() { /* called when the connection with the DB is opened successfully */ var cursorRequest, db, keyRange, now, store, tx; db = request.result; console.log('Database connection opened.'); /* open a transaction */ tx = db.transaction('timestamps', 'readwrite'); store = tx.objectStore('timestamps'); /* store a new record with the current timestamp */ now = new Date(); store.put({ t: now }); /* get everything in the store */ keyRange = IDBKeyRange.lowerBound(0); cursorRequest = store.openCursor(keyRange); cursorRequest.onsuccess = function(e) { /* called when the cursor request succeeds */ var result, t; result = e.target.result; if (!(result != null)) return; /* display the log record, skipping the last */ t = result.value.t; if (+t === +now) return; $('#log').prepend($("