Skip to content

Instantly share code, notes, and snippets.

@mermop
Last active January 13, 2021 04:35
Show Gist options
  • Save mermop/4c3ade9e0c1364b6e51f904c32abe521 to your computer and use it in GitHub Desktop.
Save mermop/4c3ade9e0c1364b6e51f904c32abe521 to your computer and use it in GitHub Desktop.
Export all active devices
// View by: device
// Device +
// Scroll to bottom to load everything
// This downloads a file with no defined name - you'll need to rename it to something.csv
// Could break at any time
var deviceTable = document.querySelector('.popup-wrapper ess-table')
var tableRows = deviceTable.querySelectorAll('.particle-table-row')
var firstRow = tableRows.item(1)
var devicesArray = [["Device name", "Number of active devices"]]
for (let i = 0; i < tableRows.length; i++) {
let row = tableRows.item(i);
let device = row.querySelectorAll('.main-text').item(0).textContent.replace(/,/g,'').replace(/"/g,'');
let value = row.querySelectorAll('.main-text').item(1).textContent.replace(/,/g,'');
devicesArray.push([device, value]);
}
var arrayToCSV = function(array) {
var csvContent = "data:text/csv;charset=utf-8,";
array.forEach(function(row, index) {
dataString = row.join(",");
csvContent += index < array.length ? dataString+ "\n" : dataString;
})
return(csvContent);
}
csv = arrayToCSV(devicesArray);
var encodedUri = encodeURI(csv);
window.open(encodedUri);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment