Skip to content

Commit

Permalink
Toggle working, still requires a reload
Browse files Browse the repository at this point in the history
  • Loading branch information
nsimmonds committed Nov 8, 2012
1 parent 6a12134 commit b42c989
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 55 deletions.
77 changes: 38 additions & 39 deletions mailscripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,49 @@ var url = "";
var tog;
var def;
var mailUrl;

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

//send a request to the extension for the default mail type
chrome.extension.sendMessage({sendMe: "default"}, function(response){
def = response;
switch (def) {
case "g":
mailUrl = gMailUrl;
// Gmail uses a different subject identifier
subject = gMailSub;
break;

case "y":
mailUrl = yMailUrl;
break;

case "l":
mailUrl = lMailUrl;
break;

case "o":
mailUrl = owaUrl;
break;

// use Gmail as the default option, just in case.
default:
mailUrl = gMailUrl;
subject = gMailSub;
}
});




var port = chrome.extension.connect({name: "localStorage"})

port.onMessage.addListener(function(storage){
if (storage.toggle == "on")
tog = true
else
tog = false
def = storage["default"]
console.log(storage)
})
port.postMessage({sendMe: "localStorage"})

switch (def) {
case "g":
mailUrl = gMailUrl;
// Gmail uses a different subject identifier
subject = gMailSub;
break;

case "y":
mailUrl = yMailUrl;
break;

case "l":
mailUrl = lMailUrl;
break;

case "o":
mailUrl = owaUrl;
break;

// use Gmail as the default option, just in case.
default:
mailUrl = gMailUrl;
subject = gMailSub;
}

// note (for debugging/learning purposes) that the function above doesn't fire until
// 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 (tog === "on") {
port.postMessage({sendMe: "localStorage"})
if (tog === true) {
var url = this.href;
url = url.replace("mailto:",mailUrl);
url = url.replace("?subject=",subject);
Expand Down
9 changes: 3 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Post Office",
"version": "0.9",
"version": "0.95",
"manifest_version": 2,
"options_page" : "preferences.html",
"description": "Chrome email functions",
Expand All @@ -10,7 +10,7 @@
},
"content_scripts": [
{
"matches": ["http://*/*"],
"matches": ["*://*/*"],
"js": [
"jquery-1.7.2.min.js",
"mailscripts.js"
Expand All @@ -19,16 +19,13 @@
],
"background" : {
"scripts": [
"listener.js",
"mail.js",
"toggle.js"
]
},

"permissions": [
"contextMenus",
"http://*/*",
"https://*/*"
"*://*/*"
],

"icons": {
Expand Down
5 changes: 0 additions & 5 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,3 @@ document.addEventListener('DOMContentLoaded', function () {

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

chrome.extension.onMessage.addListener(
function(message, sender, sendResponse) {
sendResponse(localStorage[message.sendMe]);
});
2 changes: 1 addition & 1 deletion preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<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 />
<input type="checkbox" id="owa" /> Outlook Web Access - https://<input type="text" id="owaUrl" value="Enter OWA address here" />/owa<br />
<p>Select your primary webmail. This will be the default when the Post Office icon is toggled on.</p>
<select id="default">
<option value="g">Gmail</option>
Expand Down
10 changes: 6 additions & 4 deletions toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ chrome.browserAction.onClicked.addListener(function (tab) {
}
})

chrome.extension.onMessage.addListener(
function(message, sender, sendResponse) {
sendResponse(localStorage[message.sendMe]);
});
// Create listener that responds with the localStorage status
chrome.extension.onConnect.addListener(function(port){
port.onMessage.addListener(function(request){
port.postMessage(localStorage);
})
})

0 comments on commit b42c989

Please sign in to comment.