Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 3x 3x 3x 16x 8x 4x 4x 4x 4x 3x 3x 4x 5x 1x 1x 4x 4x 4x 4x 4x 10x 5x 3x 3x 3x 1x 2x 4x 1x 3x 1x 1x 2x 1x 4x 9x 9x 10x 5x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 9x 5x 3x 2x 1x | // What the player keeps in this browser, read for the local data viewer: its `localStorage` keys, its IndexedDB
// databases and the browser's storage estimate. Reading never writes: databases are opened at their current version and
// only the ones the browser lists are opened, so the viewer creates nothing.
/** What each `localStorage` key of the player holds. */
const LOCAL_STORAGE_KEYS: Readonly<Record<string, string>> = {
'be-music.option-settings': 'Every Options dialog setting',
'be-music.settings-reset-pending': 'A settings reset still to send to the server',
'be-music.chart-best-records': 'Best records of each chart, per judge ruleset',
'be-music.hi-speed': 'The hi-speed the next play starts at',
'be-music.play-tempo': 'Tempo settings',
'be-music.replay-view': 'Replay view settings',
'be-music.render-resolution': 'Render resolution',
'be-music.compressor-tuning': 'Audio compressor tuning',
'be-music.volumes': 'Volumes',
'be-music.built-in-skin': 'The built-in skin',
'be-music.skin-settings': 'Skin settings',
'be-music.skin-effects': 'Skin effects',
'be-music.play-layout': 'Play layout',
'be-music.renderer': 'Renderer',
'be-music.recording-format': 'Recording format',
'be-music.course-table-urls': 'Difficulty tables whose courses are imported on load',
'be-music.play-in-silent-mode': 'Play sound with the device in silent mode',
'be-music.silent-mode-hint-seen': 'The silent-mode hint was shown',
'be-music.worker-count': 'Background worker count',
'be-music.start-account-state': 'The account state the start card last showed, to shape its loading placeholder',
};
/** What each IndexedDB database and store of the player holds. */
const DATABASES: Readonly<Record<string, { description: string; stores: Readonly<Record<string, string>> }>> = {
'be-music': { description: 'Courses you made', stores: { courses: 'Saved courses' } },
'be-music-replays': {
description: 'Replay history and slots',
stores: {
replaySlots: 'Replay history and slot selections',
replaySlotData: 'Replay files, gzip-compressed',
meta: 'Storage revision',
},
},
'be-music-charts': {
description: 'Parsed charts, so a folder dropped again loads faster',
stores: {
parsedCharts: 'Each chart’s parse result, by the SHA-256 of its file',
meta: 'The build that parsed them',
},
},
'be-music-folders': {
description: 'Folders you opened or dropped, to open them again on the next visit',
stores: { folders: 'The remembered folders' },
},
'be-music-folder-snapshots': {
description: 'What each remembered folder held when it was last loaded, so its charts are listed at once',
stores: {
folders: 'The folders that have a snapshot',
snapshots: 'Each folder’s file listing, and the size, modification time and parse key of its chart files',
},
},
};
/** One `localStorage` entry. */
export interface LocalStorageEntry {
readonly key: string;
readonly value: string;
/** UTF-8 bytes of the key and value. */
readonly bytes: number;
/** What it holds, for the player's own keys. */
readonly description?: string;
}
/** One stored IndexedDB record, as read. */
export interface StoredRecord {
readonly key: string;
readonly value: unknown;
}
/** One object store of a database. */
export interface StoredObjectStore {
readonly name: string;
readonly description?: string;
readonly count: number;
/** The first records, up to the read limit. */
readonly records: readonly StoredRecord[];
}
/** One IndexedDB database. */
export interface StoredDatabase {
readonly name: string;
readonly version: number;
readonly description?: string;
readonly stores: readonly StoredObjectStore[];
}
/** A stored value as the viewer shows it. */
export interface StoredValueView {
readonly kind: 'json' | 'text' | 'blob' | 'binary';
/** Its size in bytes; for JSON, the UTF-8 size of its JSON text, which approximates what the browser keeps. */
readonly bytes: number;
/** What to print: pretty JSON, the text, or a line describing binary data. */
readonly text: string;
}
const encoder = new TextEncoder();
/** UTF-8 bytes of `text`. */
export function utf8Bytes(text: string): number {
return encoder.encode(text).length;
}
/** A byte count for people: `512 B`, `1.5 KB`, `12.0 MB` (powers of 1024). */
export function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
const units = ['KB', 'MB', 'GB', 'TB'];
let value = bytes / 1024;
let unit = 0;
while (value >= 1024 && unit < units.length - 1) {
value /= 1024;
unit += 1;
}
return `${value.toFixed(1)} ${units[unit]}`;
}
/** What a `localStorage` key holds, for the player's own keys. */
export function describeLocalStorageKey(key: string): string | undefined {
return LOCAL_STORAGE_KEYS[key];
}
/** Every `localStorage` entry: the player's own (`be-music.`) first, each group by key. */
export function listLocalStorage(storage: Pick<Storage, 'length' | 'key' | 'getItem'>): LocalStorageEntry[] {
const entries: LocalStorageEntry[] = [];
for (let index = 0; index < storage.length; index++) {
const key = storage.key(index);
Iif (key === null) continue;
const value = storage.getItem(key) ?? '';
const description = describeLocalStorageKey(key);
entries.push({ key, value, bytes: utf8Bytes(key) + utf8Bytes(value), ...(description ? { description } : {}) });
}
const own = (key: string) => (key.startsWith('be-music.') ? 0 : 1);
return entries.sort((a, b) => own(a.key) - own(b.key) || a.key.localeCompare(b.key));
}
/** A `localStorage` value as the viewer shows it: pretty JSON when it parses, else the text. */
export function viewLocalStorageValue(value: string): StoredValueView {
try {
const parsed: unknown = JSON.parse(value);
if (typeof parsed === 'object' && parsed !== null)
return { kind: 'json', bytes: utf8Bytes(value), text: JSON.stringify(parsed, null, 2) };
} catch {
// Not JSON: shown as text.
}
return { kind: 'text', bytes: utf8Bytes(value), text: value };
}
/** An IndexedDB value as the viewer shows it. Blobs and binary data are described, not read. */
export function viewStoredValue(value: unknown): StoredValueView {
if (typeof Blob !== 'undefined' && value instanceof Blob) {
return {
kind: 'blob',
bytes: value.size,
text: `Blob, ${formatBytes(value.size)}${value.type ? `, ${value.type}` : ''}`,
};
}
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
const bytes = value.byteLength;
return { kind: 'binary', bytes, text: `Binary data, ${formatBytes(bytes)}` };
}
if (typeof value === 'string') return { kind: 'text', bytes: utf8Bytes(value), text: value };
const json = JSON.stringify(value, null, 2) ?? String(value);
return { kind: 'json', bytes: utf8Bytes(JSON.stringify(value) ?? ''), text: json };
}
/** What a database, or one of its stores, holds, for the player's own. */
export function describeDatabase(name: string, store?: string): string | undefined {
const database = DATABASES[name];
return store === undefined ? database?.description : database?.stores[store];
}
/** The player's databases first, then the rest, each group by name. */
export function sortDatabases<T extends { name: string }>(databases: readonly T[]): T[] {
const own = (name: string) => (name in DATABASES ? 0 : 1);
return [...databases].sort((a, b) => own(a.name) - own(b.name) || a.name.localeCompare(b.name));
}
function request<T>(target: IDBRequest<T>): Promise<T> {
return new Promise((resolve, reject) => {
target.onsuccess = () => resolve(target.result);
target.onerror = () => reject(target.error ?? new Error('indexedDB request failed'));
});
}
/** Opens an existing database at its current version; an upgrade request (a database that is gone) is aborted. */
function openExisting(factory: IDBFactory, name: string): Promise<IDBDatabase | undefined> {
return new Promise((resolve, reject) => {
const open = factory.open(name);
open.onupgradeneeded = () => open.transaction?.abort();
open.onsuccess = () => resolve(open.result);
open.onerror = () => (open.error?.name === 'AbortError' ? resolve(undefined) : reject(open.error));
});
}
/** Reads every database the browser lists for this origin, with up to `limit` records of each store. */
export async function readIndexedDB(factory: IDBFactory, limit = 200): Promise<StoredDatabase[]> {
const listed = typeof factory.databases === 'function' ? await factory.databases() : [];
const result: StoredDatabase[] = [];
for (const info of sortDatabases(listed.flatMap((info) => (info.name ? [{ ...info, name: info.name }] : [])))) {
const db = await openExisting(factory, info.name);
Iif (db === undefined) continue;
try {
const stores: StoredObjectStore[] = [];
for (const name of Array.from(db.objectStoreNames)) {
const store = db.transaction(name, 'readonly').objectStore(name);
const [count, keys, values] = await Promise.all([
request(store.count()),
request(store.getAllKeys(null, limit)),
request(store.getAll(null, limit)),
]);
const description = describeDatabase(info.name, name);
stores.push({
name,
count,
records: keys.map((key, index) => ({ key: formatKey(key), value: values[index] })),
...(description ? { description } : {}),
});
}
const description = describeDatabase(info.name);
result.push({ name: info.name, version: db.version, stores, ...(description ? { description } : {}) });
} finally {
db.close();
}
}
return result;
}
/** An IndexedDB key as text. */
export function formatKey(key: IDBValidKey): string {
if (typeof key === 'string') return key;
if (typeof key === 'number') return String(key);
if (key instanceof Date) return key.toISOString();
if (Array.isArray(key)) return `[${key.map(formatKey).join(', ')}]`;
return `Binary key, ${formatBytes(key.byteLength)}`;
}
/** The browser's storage estimate for this origin, and whether it is kept from eviction. */
export async function readStorageEstimate(): Promise<{ usage?: number; quota?: number; persisted?: boolean }> {
const storage = typeof navigator !== 'undefined' ? navigator.storage : undefined;
if (storage === undefined) return {};
const [estimate, persisted] = await Promise.all([
storage.estimate?.().catch(() => undefined),
storage.persisted?.().catch(() => undefined),
]);
return {
...(estimate?.usage !== undefined ? { usage: estimate.usage } : {}),
...(estimate?.quota !== undefined ? { quota: estimate.quota } : {}),
...(persisted !== undefined ? { persisted } : {}),
};
}
|