Skip to content

Commit

Permalink
Remove ability to select when to reset stat clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Josephine-Chen committed Mar 8, 2017
1 parent 0503945 commit db98b95
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 65 deletions.
16 changes: 4 additions & 12 deletions extension/background.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Notification
// chrome.alarms.create("notificationAlarm", {periodInMinutes: 2});
// chrome.alarms.onAlarm.addListener(function(alarm) {
// if (alarm.name === "notificationAlarm") {
// console.log('alarm');
// chrome.notifications.create('notificationAlarm', {type: 'basic', iconUrl: 'icon128.png', title: 'Notification', message: 'This is a notification!'});
// }
// });
//Clearing data
//Clear data every 24 hours at midnight
//Add new field to database with the updated [date, time] IFF site is blacklisted


//Send information to app every half hour
chrome.alarms.create("updateApp", {periodInMinutes: 30});
Expand Down Expand Up @@ -37,10 +33,6 @@ function sendAppStats() {
}

// Check blacklist and handle notification cases
// 1 is blackout
// 2 is block after exceeding
// 3 is warn after exceeding

//BLACKOUT CASE
//Check tabs for update
chrome.tabs.onUpdated.addListener(function(tabId, changedInfo, tab) {
Expand Down
11 changes: 7 additions & 4 deletions extension/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ Object.defineProperty(Config.prototype, "timeDisplayFormat", {
*/
Object.defineProperty(Config.prototype, "clearStatsInterval", {
get: function() {
if (!localStorage.clearStatsInterval) {
localStorage.clearStatsInterval = "0";
}
return parseInt(localStorage.clearStatsInterval, 10);
// if (!localStorage.clearStatsInterval) {
// localStorage.clearStatsInterval = "86400";
// }
// return parseInt(localStorage.clearStatsInterval, 10);
//return 86400;
console.log('get clear stats interval');
return 120;
},
set: function(i) {
if (i !== this.clearStatsInterval) {
Expand Down
7 changes: 2 additions & 5 deletions extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<div id="blackout_display" ></div>
<b> Block After Exceeding </b>:
<div id="block_display">
<!-- <table id>
<tbody id="block_display"></tbody>
</table> -->
</div>
<b> Warn After Exceeding </b>: <br />
<div id="warn_display" ></div>
Expand All @@ -36,13 +33,13 @@
</select><br/>
<button id="remove_ignored">Remove Selected</button>
<br/>
<b>Clear Statistics Every</b>:
<!-- <b>Clear Statistics Every</b>:
<select id="clear_stats_interval">
<option value="0">never</option>
<option value="3600">Hour</option>
<option value="86400">Day</option>
<option value="604800">Week</option>
</select><br/>
</select><br/> -->
<button id="download">Download CSV</button><br/>
</body>
</html>
34 changes: 17 additions & 17 deletions extension/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ function updateBlacklist(){
}

//Update the interval to clear stats
function updateClearStatsInterval() {
var select = document.getElementById("clear_stats_interval");
var option = select.options[select.selectedIndex];
config.clearStatsInterval = option.value;
restoreOptions();
}
// function updateClearStatsInterval() {
// var select = document.getElementById("clear_stats_interval");
// var option = select.options[select.selectedIndex];
// config.clearStatsInterval = option.value;
// restoreOptions();
// }

//Upate the format of time display
function updateTimeDisplay() {
Expand Down Expand Up @@ -145,15 +145,15 @@ function restoreOptions() {
select.appendChild(option);
}

var clearStatsInterval = config.clearStatsInterval;
select = document.getElementById("clear_stats_interval");
for (var i = 0; i < select.options.length; i++) {
var option = select.options[i];
if (option.value == clearStatsInterval) {
option.selected = true;
break;
}
}
// var clearStatsInterval = config.clearStatsInterval;
// select = document.getElementById("clear_stats_interval");
// for (var i = 0; i < select.options.length; i++) {
// var option = select.options[i];
// if (option.value == clearStatsInterval) {
// option.selected = true;
// break;
// }
// }

var timeDisplay = config.timeDisplayFormat;
select = document.getElementById("time_display");
Expand Down Expand Up @@ -188,8 +188,8 @@ document.addEventListener("DOMContentLoaded", function () {
"click", addIgnoredSite);
document.getElementById("remove_ignored").addEventListener(
"click", removeIgnoredSites);
document.getElementById("clear_stats_interval").addEventListener(
"change", updateClearStatsInterval);
// document.getElementById("clear_stats_interval").addEventListener(
// "change", updateClearStatsInterval);
document.getElementById("time_display").addEventListener(
"change", updateTimeDisplay);
document.getElementById("download").addEventListener(
Expand Down
54 changes: 27 additions & 27 deletions extension/popup.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
var config = new Config();
var gsites = new Sites(config);

function sendToApp() {
var sendDataBtn = document.createElement("button");
var sendDataBtnTxt = document.createTextNode("Send Data");
sendDataBtn.appendChild(sendDataBtnTxt);
document.body.appendChild(sendDataBtn);
sendDataBtn.setAttribute("id", "testButton");
sendDataBtn.onclick = function() {
// Get all sites and store in array to be parsed and stored in db
var allSites = [];
for(var prop in gsites.sites) {
allSites.push({url: prop, time: gsites.sites[prop], freq: 0});
}
$.ajax({
type: 'POST',
url: `http://localhost:7777/api/users/${localStorage.auth0_id}/extension_data`,
contentType: 'application/json',
data: JSON.stringify({ urls:allSites }),
success: function(data) {
console.log('success!', data);
},
error: function(err) {
console.log('error', err);
},
});
};
}
// function sendToApp() {
// var sendDataBtn = document.createElement("button");
// var sendDataBtnTxt = document.createTextNode("Send Data");
// sendDataBtn.appendChild(sendDataBtnTxt);
// document.body.appendChild(sendDataBtn);
// sendDataBtn.setAttribute("id", "testButton");
// sendDataBtn.onclick = function() {
// // Get all sites and store in array to be parsed and stored in db
// var allSites = [];
// for(var prop in gsites.sites) {
// allSites.push({url: prop, time: gsites.sites[prop], freq: 0});
// }
// $.ajax({
// type: 'POST',
// url: `http://localhost:7777/api/users/${localStorage.auth0_id}/extension_data`,
// contentType: 'application/json',
// data: JSON.stringify({ urls:allSites }),
// success: function(data) {
// console.log('success!', data);
// },
// error: function(err) {
// console.log('error', err);
// },
// });
// };
// }

//Add to ignored sites
function addIgnoredSite(new_site) {
Expand Down Expand Up @@ -188,7 +188,7 @@ function clearStats() {

function initialize() {
addLocalDisplay();
sendToApp();
//sendToApp();

if (config.lastClearTime) {
var div = document.getElementById("lastClear");
Expand Down

0 comments on commit db98b95

Please sign in to comment.