Created
November 16, 2011 02:31
-
-
Save sterfry1988/1369092 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="sample.js"> | |
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { | |
if (request.method == "getLocalStorage") | |
console.log("Request received"); | |
sendResponse({data: localStorage[request.key]}); | |
else | |
sendResponse({}); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head><title>My Test Extension Options</title></head> | |
<script type="text/javascript"> | |
// Saves options to localStorage. | |
function save_options() { | |
var select = document.getElementById("tasaddr"); | |
var startaddr = select.value; | |
localStorage.setItem("saddr", startaddr); | |
} | |
// Restores select box state to saved value from localStorage. | |
function restore_options() { | |
var address = localStorage.getItem("saddr"); | |
var txtAddress = document.getElementById("tasaddr"); | |
txtAddress.value = address; | |
} | |
</script> | |
<body onload="restore_options()"> | |
Your Starting address: | |
<textarea id="tasaddr" rows ="2" cols="20"> | |
Enter your address here | |
</textarea> | |
<br> | |
<button onclick="save_options()">Save</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
// A generic onclick callback function. | |
function genericOnClick(info, tab) { | |
console.log("mouse clicked"); | |
chrome.extension.sendRequest({method: "getLocalStorage", key: "saddr"}, | |
function(response) { | |
console.log("request made"); | |
var sText = info.selectionText; | |
var daddr = sText.split(' ').join('+'); | |
var saddr = response.data; | |
var homeTxt = "http://maps.google.com/maps?" + "saddr=" | |
+ saddr.split(' ').join('+') + "&daddr="; | |
var url = homeTxt + daddr; | |
chrome.tabs.create({url:url}); | |
console.log("item " + info.menuItemId + " was clicked"); | |
console.log("info: " + JSON.stringify(info)); | |
console.log("tab: " + JSON.stringify(tab)); | |
} | |
); | |
} | |
// Create one test item for each context type. | |
var contexts = ["selection"]; | |
for (var i = 0; i < contexts.length; i++) { | |
var context = contexts[i]; | |
var title = "Get Directions"; | |
var id = chrome.contextMenus.create({"title": title, "contexts":[context], | |
"onclick": genericOnClick}); | |
console.log("'" + context + "' item:" + id); | |
} | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment