Skip to content

Commit

Permalink
localStorage works again
Browse files Browse the repository at this point in the history
  • Loading branch information
nsimmonds committed Nov 6, 2012
1 parent f94e51f commit 6a12134
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 61 deletions.
70 changes: 31 additions & 39 deletions mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ var yahoo;
var owa;
var live;

chrome.extension.sendMessage("gmail", function(response) {
gmail = response
});
chrome.extension.sendMessage("yahoo", function(response) {
yahoo = response
});
chrome.extension.sendMessage("owa", function(response) {
owa = response
});
chrome.extension.sendMessage("live", function(response) {
live = response
});


//Context menu entry for Gmail fires this block
function clickHandleGmail(){
// info starts out undefined, so this returns the whole function
Expand Down Expand Up @@ -65,40 +51,46 @@ function clickHandleOWA() {
window.open(link);
}
}
// remove pre-existing context menu items

chrome.contextMenus.removeAll()


// create the context menu items

if (gmail != "false") {
if (localStorage["gmail"] != "false") {
chrome.contextMenus.create({
"title" : "Send via Gmail",
"contexts" :["link"],
"onclick" : clickHandleGmail()
});
};
"onclick" : clickHandleGmail(),
"id": "gmail"
});
}


if (yahoo != "false") {
chrome.contextMenus.create({
"title" : "Send via Yahoo!",
"contexts" : ["link"],
"onclick" : clickHandleYmail()
});
};
if (localStorage["yahoo"] != "false") {
chrome.contextMenus.create({
"title" : "Send via Yahoo!",
"contexts" : ["link"],
"onclick" : clickHandleYmail(),
"id":"yahoo"
});
}

if (live != "false") {
chrome.contextMenus.create({
"title" : "Send via Microsoft Live Mail",
"contexts" : ["link"],
"onclick" : clickHandleLmail()
});
};
if (localStorage["live"] != "false") {
chrome.contextMenus.create({
"title" : "Send via Microsoft Live Mail",
"contexts" : ["link"],
"onclick" : clickHandleLmail(),
"id":"live"
});
}

if (owa != "false") {
chrome.contextMenus.create({
"title" : "Send via OWA",
"contexts" : ["link"],
"onclick" : clickHandleOWA()
});
};
if (localStorage.owa != "false") {
chrome.contextMenus.create({
"title" : "Send via OWA",
"contexts" : ["link"],
"onclick" : clickHandleOWA(),
"id":"owa"
});
}
10 changes: 5 additions & 5 deletions mailscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ var owaHTTP = localStorage["owaUrl"];
var owaUrl = "https://"+owaHTTP+"/owa/?ae=Item&a=New&t=IPM.Note&to=";
var subject = "&subject=";
var url = "";
var toggle;
var tog;
var def;
var mailUrl;

// Send a request to the extension for toggle status
chrome.extension.sendMessage("toggle", function(response){
toggle = response;
chrome.extension.sendMessage({sendMe: "toggle"}, function(response){
tog = response;
})

//send a request to the extension for the default mail type
chrome.extension.sendMessage(("default"), function(response){
chrome.extension.sendMessage({sendMe: "default"}, function(response){
def = response;
switch (def) {
case "g":
Expand Down Expand Up @@ -54,7 +54,7 @@ chrome.extension.sendMessage(("default"), function(response){
// the script is fully loaded. This is clearly a bug. Luckily, the way the below
// function is written, it doesn't take place until after the page is fully loaded.
$("a").click(function() {
if (toggle === "on") {
if (tog === "on") {
var url = this.href;
url = url.replace("mailto:",mailUrl);
url = url.replace("?subject=",subject);
Expand Down
9 changes: 5 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Post Office",
"version": "0.85",
"version": "0.9",
"manifest_version": 2,
"options_page" : "preferences.html",
"description": "Chrome email functions",
Expand All @@ -19,9 +19,10 @@
],
"background" : {
"scripts": [
"mail.js",
"toggle.js"
]
"listener.js",
"mail.js",
"toggle.js"
]
},

"permissions": [
Expand Down
10 changes: 8 additions & 2 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ function saveOptions() {
localStorage["owa"] = document.getElementById("owa").checked;
localStorage["owaUrl"] = document.getElementById("owaUrl").value;
localStorage["default"] = document.getElementById("default").value;
document.getElementById("output").innerHTML = "Saved! Please close and re-open Chrome to apply changes.";
document.getElementById("output").innerHTML = "Saved!";
chrome.extension.getBackgroundPage().window.location.reload();
}
// Restores page elements state to saved value from localStorage.
function restoreOptions() {
Expand All @@ -34,4 +35,9 @@ document.addEventListener('DOMContentLoaded', function () {
});

//this resets the options when the page is loaded
document.addEventListener('DOMContentLoaded', restoreOptions);
document.addEventListener('DOMContentLoaded', restoreOptions);

chrome.extension.onMessage.addListener(
function(message, sender, sendResponse) {
sendResponse(localStorage[message.sendMe]);
});
3 changes: 2 additions & 1 deletion preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
</head>
<script src="options.js">
</script>
<script src="toggle.js"></script>
<body>
<img src="bigicon.png" />
<p>Select the webmail providers you use:</p>
<input type="checkbox" id="gmail" checked="yes" /> Gmail<br />
<input type="checkbox" id="gmail"/> Gmail<br />
<input type="checkbox" id="yahoo" /> Yahoo! mail<br />
<input type ="checkbox" id="live" /> Microsoft Live mail<br />
<input type="checkbox" id="owa" /> Outlook Web Access - <input type="text" id="owaUrl" value="Enter OWA address here" /><br />
Expand Down
23 changes: 13 additions & 10 deletions toggle.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Copyright (c) 2012 by Nick Simmonds. All rights reserved.

function setStorage() {
if (localStorage["toggle"] === null) {
localStorage["toggle"] === "no";
if (localStorage["toggle"] === undefined) {
localStorage["toggle"] = "no"
}
if (localStorage["gmail"] === undefined){
localStorage["gmail"] = true
}
if (localStorage["owa"] === undefined){
localStorage["owa"] = false
}
}

function setIcon() {
Expand Down Expand Up @@ -36,13 +42,10 @@ chrome.browserAction.onClicked.addListener(function (tab) {
} else {
chrome.browserAction.setIcon({path:"midicon.png"});
localStorage["toggle"] = "on";
};
}
})

//respond to any requests with the state of toggle
function localStorageReq (request, sender, sendResponse) {
sendResponse(localStorage[request]);
}

// calls the toggleReq function whenever a request is sent
chrome.extension.onMessage.addListener(localStorageReq);
chrome.extension.onMessage.addListener(
function(message, sender, sendResponse) {
sendResponse(localStorage[message.sendMe]);
});

0 comments on commit 6a12134

Please sign in to comment.