Skip to content

Instantly share code, notes, and snippets.

@brandonhellman
Created July 5, 2020 22:42
Show Gist options
  • Save brandonhellman/101f28f75b70dfd728a739adee559802 to your computer and use it in GitHub Desktop.
Save brandonhellman/101f28f75b70dfd728a739adee559802 to your computer and use it in GitHub Desktop.
Export HIT Tracker in multiple files instead of one large file
const fileSave = (data, name) => {
const json = JSON.stringify(data);
const save = document.createElement('a');
save.href = window.URL.createObjectURL(new window.Blob([json], { type: 'application/json' }));
save.download = `${name}.json`;
document.body.appendChild(save);
save.click();
document.body.removeChild(save);
};
const hitTrackerExporter = async (maxHitsPerFile = 100000) => {
let db;
let count = 0;
let index = 0;
let indexFileSaved = 0;
const data = {
hits: [],
days: [],
};
const open = window.indexedDB.open('hitTrackerDB', 1);
open.onsuccess = (event) => {
db = event.target.result;
const transaction = db.transaction(['hit'], 'readonly');
const objectStore = transaction.objectStore('hit');
const objectStoreCount = objectStore.count();
objectStoreCount.onsuccess = (event) => {
count = event.target.result;
console.log(db, count);
const openCursor = objectStore.openCursor();
openCursor.onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
index++;
data.hits.push(cursor.value);
if (data.hits.length === maxHitsPerFile) {
fileSave({ ...data }, `HITs ${index - maxHitsPerFile + 1} to ${index} of ${count}`);
data.hits = [];
indexFileSaved = index;
}
cursor.continue();
} else {
fileSave({ ...data }, `HITs ${indexFileSaved + 1} to ${index} of ${count}`);
}
};
};
};
};
hitTrackerExporter();
@brandonhellman
Copy link
Author

How to use:

  1. Open HIT Tracker in MTSv2
  2. Open the console in HIT Tracker
  3. Paste the code above into the console and press the Enter key
  4. Wait while your database is exported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment