Created
March 20, 2019 16:28
-
-
Save KrashLeviathan/2bcf6674b1c3b6cd66649f86054fd8d6 to your computer and use it in GitHub Desktop.
Used to collect data from Squarespace analytics charts (or any react chart tooltips for that matter)
This file contains hidden or 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
myCollector = { | |
data: {}, | |
intervalId: 0, | |
intervalMillis: 5, | |
selectors: { | |
container: '.react-charts-tooltip', | |
header: '.react-charts-tooltip-header', | |
rows: '.react-charts-tooltip-row' | |
}, | |
start: function() { | |
var that = this; | |
this.intervalId = setInterval(function() { | |
if (document.querySelector(that.selectors.container) == null) { | |
return; | |
} | |
var header = document.querySelector(that.selectors.header).innerText; | |
that.data[header] = []; | |
document.querySelectorAll(that.selectors.rows).forEach(function(row) { | |
that.data[header].push(row.innerText); | |
}); | |
}, this.intervalMillis); | |
}, | |
stop: function() { | |
clearInterval(this.intervalId); | |
}, | |
resetData: function() { | |
this.data = {}; | |
}, | |
copyData: function() { | |
var copyEl = document.createElement('textarea'); | |
copyEl.setAttribute('id','my-copy-element'); | |
var contents = JSON.stringify(this.data, null, 2); | |
document.body.appendChild(copyEl); | |
copyEl = document.querySelector('#my-copy-element'); | |
copyEl.value = contents; | |
copyEl.select(); | |
document.execCommand('copy'); | |
copyEl.remove(); | |
//return contents; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment