Last active
January 13, 2021 04:35
-
-
Save mermop/4c3ade9e0c1364b6e51f904c32abe521 to your computer and use it in GitHub Desktop.
Export all active devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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