Skip to content

Instantly share code, notes, and snippets.

@jan-osch
Created July 23, 2018 13:53
Show Gist options
  • Save jan-osch/f172b978af1abe5b20dd7d5d510bc7ed to your computer and use it in GitHub Desktop.
Save jan-osch/f172b978af1abe5b20dd7d5d510bc7ed to your computer and use it in GitHub Desktop.
Sync pending settings bookmarklet
javascript:(() => { const identifierRegex = /(\/beacons|v3\/devices)\/(\w{16,32})(\/settings)?/; const match = identifierRegex.exec(window.location); if (!match) { return; } const isProd = /cloud\.estimote\.com/.exec(window.location); if (isProd && !window.confirm('This is production, are you sure?')) { return; } const identifier = match[2]; fetch(`/v3/devices/${identifier}`, { credentials: 'same-origin' }) .then(response => response.json()) .then(body => { if (body.data.pending_settings) { return fetch(`/v2/devices/${identifier}`, { body: JSON.stringify({ identifier: identifier, settings: body.data.pending_settings, }), method: 'POST', headers: { 'content-type': 'application/json', }, credentials: 'same-origin', }).then(response => response.json()) .then((body) => { if (window.confirm('Reload?\n\n' + JSON.stringify(body, null, 2))) { location.reload(); } }); } alert('No pending settings'); }); })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment