function fetchDB(cb) { let raw_db; let url; if (window.location.origin.match('paintings.asdf.us')) { url = '/db.json' } else { url = '/paintings/db.json' } fetch(url, { method: 'GET' }).then(res => { if (res.status !== 200) { return null } return res.json() }).then(json => { if (json) { raw_db = parse(json) } cb(raw_db) }).catch((err) => { console.warn(err) }) } function parse(db) { Object.keys(db).forEach(key => { db[key] = db[key] .filter((el) => ! el.disabled) .sort((a,b) => a.__index