Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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();
@Kadauchi

This comment has been minimized.

Copy link
Owner Author

@Kadauchi Kadauchi commented Jul 5, 2020

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