Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
cleanup of settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Meredith committed Sep 14, 2016
1 parent 35641e2 commit b3b6d77
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
]
},
"permissions": [
"activeTab",
"notifications",
"storage"
],
"optional_permissions": [
"<all_urls>",
"activeTab",
"cookies"
],
"options_page": "html/options.html"
Expand Down
38 changes: 19 additions & 19 deletions extension/scripts/background.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
chrome.browserAction.onClicked.addListener(function (activeTab) {
chrome.permissions.request({
permissions: ['cookies'],
permissions: ['activeTab', 'cookies'],
origins: [activeTab.url]
},
function (granted) {
var message = "Omnomnomnom";

if (granted) {
chrome.storage.sync.get("sound", function(data) {
if (data.sound) {
var audio = new Audio();
audio.src = chrome.extension.getURL('/sound/omnomnom.mp3');
audio.play();

chrome.storage.sync.get(
['sound', 'clearLocalStorage', 'clearSessionStorage'],
function(data) {
if (data.sound) {
var audio = new Audio();
audio.src = chrome.extension.getURL('/sound/omnomnom.mp3');
audio.play();
}

if (data.clearLocalStorage) {
chrome.tabs.executeScript({code:'localStorage.clear();'})
}

if (data.clearSessionStorage) {
chrome.tabs.executeScript({code:'localStorage.clear();'})
}
}
});
);

chrome.cookies.getAll({url: activeTab.url}, function (cookies) {
$.each(cookies, function (index, cookie) {
Expand All @@ -24,18 +36,6 @@ chrome.browserAction.onClicked.addListener(function (activeTab) {
);
});
});

chrome.storage.sync.get("clearLocalStorage", function(data) {
if (data.clearLocalStorage) {
chrome.tabs.executeScript({code:'localStorage.clear();'})
}
});

chrome.storage.sync.get("clearSessionStorage", function(data) {
if (data.clearSessionStorage) {
chrome.tabs.executeScript({code:'localStorage.clear();'})
}
});
} else {
message = "Cookie Monster is sad that there are no cookies";
}
Expand Down
20 changes: 12 additions & 8 deletions extension/scripts/options.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
(function ($) {
$(function () {
chrome.storage.sync.get("sound", function(data) {
$('#sound').prop("checked", data.sound);
console.log(data);
});
chrome.storage.sync.get(
['sound', 'clearLocalStorage', 'clearSessionStorage'],
function (data) {
$('#sound').prop("checked", data.sound);
$('#local-storage').prop("checked", data.clearLocalStorage);
$('#session-storage').prop("checked", data.clearSessionStorage);
}
);

$('#save_btn').closest('form').submit(function (e) {
e.preventDefault();
chrome.storage.sync.set({
"sound": $('#sound').prop("checked"),
"clearLocalStorage": $('#local-storage').prop("checked"),
"clearSessionStorage": $('#session-storage').prop("checked"),
}, function() {
'sound': $('#sound').prop("checked"),
'clearLocalStorage': $('#local-storage').prop('checked'),
'clearSessionStorage': $('#session-storage').prop('checked')
}, function () {
window.alert('The options have been saved!');
});
});
Expand Down

0 comments on commit b3b6d77

Please sign in to comment.