Skip to content

Commit

Permalink
Added resetButton reset urlBlacklist functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewliang committed Sep 13, 2018
1 parent 076a7f1 commit 056d247
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 13 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ var urlBlacklist = [];
To load existing urlBlacklist from localStorage into local urlBlacklist array if conditions met
on browser load.
*/
if(window.localStorage && (JSON.parse(localStorage.getItem("urlBlacklist")) != null)) {
if(window.localStorage && (JSON.parse(window.localStorage.getItem("urlBlacklist")) != null)) {
// Browser supports localStorage and urlBlacklist already exists with items.
// Set localStorageSupport to true.
// Load existing urlBlacklist URLs into urlBlacklist array.
localStorageSupport = true;
urlBlacklist = JSON.parse(localStorage.getItem("urlBlacklist"));
urlBlacklist = JSON.parse(window.localStorage.getItem("urlBlacklist"));
console.log("Loaded Existing URL Blacklist: " + urlBlacklist);
}

Expand All @@ -34,12 +34,21 @@ if(window.localStorage && (JSON.parse(localStorage.getItem("urlBlacklist")) != n
close any tabs that are on the blacklist.
*/
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
// Reset URL Blacklist
if(request.reset) {
// If localStorage supported, clear urlBlacklist from localStorage.
if(window.localStorage) {
window.localStorage.removeItem("urlBlacklist");
}
// Clear local urlBlacklist
urlBlacklist = [];
}
// Update urlBlacklist with new URL.
if(window.localStorage) {
// Browser supports localStorage.
// Store blacklist in localStorage.
urlBlacklist.push(request.url);
localStorage.setItem('urlBlacklist', JSON.stringify(urlBlacklist));
window.localStorage.setItem('urlBlacklist', JSON.stringify(urlBlacklist));
} else {
// Browser doesn't support localStorage.
// Store blacklist in array.
Expand All @@ -63,7 +72,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
function tabRemover(tabs) {
console.log("DistractMeNot Background Inspect Console");
if(localStorageSupport) {
urlBlacklist = JSON.parse(localStorage.getItem("urlBlacklist"));
urlBlacklist = JSON.parse(window.localStorage.getItem("urlBlacklist"));
}
for(let i = 0; i < tabs.length; i++) {
for(let j = 0; j < urlBlacklist.length; j++) {
Expand Down
6 changes: 6 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ addURLButton.onclick = function() {
console.log(response.backendMessage);
});
};

resetButton.onclick = function() {
chrome.runtime.sendMessage({ reset: true }, function(response) {
console.log(response.backendMessage);
});
};

0 comments on commit 056d247

Please sign in to comment.