Skip to content

Commit 7c3dd34

Browse files
committed
Export to csv all data
1 parent 97252ca commit 7c3dd34

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

options.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
The site is already in the list
7979
</div>
8080
</div>
81+
<div class="margin-top-10">
82+
<input type="button" value="Export to CSV" id='exportToCsv'>
83+
</div>
8184
<div class="margin-top-10">
8285
<label>Data in memory use </label><label id='memoryUse'></label>
8386
</div>

scripts/settings.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ document.addEventListener('DOMContentLoaded', function () {
1818
document.getElementById('clearAllData').addEventListener('click', function () {
1919
clearAllData();
2020
});
21+
document.getElementById('exportToCsv').addEventListener('click', function () {
22+
exportToCSV();
23+
});
2124
document.getElementById('addBlackSiteBtn').addEventListener('click', function () {
2225
addNewBlackSiteClickHandler();
2326
});
@@ -101,6 +104,29 @@ function viewRestrictionList(items) {
101104
}
102105
}
103106

107+
function exportToCSV(){
108+
storage.getSettings(STORAGE_TABS, function (item) {
109+
toCsv(item);
110+
});
111+
}
112+
113+
function toCsv(tabsData){
114+
var str = '';
115+
for (var i = 0; i < tabsData.length; i++) {
116+
var line = tabsData[i].url + ',' + convertSummaryTimeToString(tabsData[i].summaryTime);
117+
str += line + '\r\n';
118+
}
119+
120+
var csvFile = new Blob([str], {type:"text/csv"});
121+
var downloadLink;
122+
downloadLink = document.createElement("a");
123+
downloadLink.download = 'domains.csv';
124+
downloadLink.href = window.URL.createObjectURL(csvFile);
125+
downloadLink.style.display = "none";
126+
document.body.appendChild(downloadLink);
127+
downloadLink.click();
128+
}
129+
104130
function clearAllData() {
105131
var tabs = [];
106132
chrome.extension.getBackgroundPage().tabs = tabs;

0 commit comments

Comments
 (0)