Skip to content

Instantly share code, notes, and snippets.

@scottferg
Forked from wmbest2/Manifest.json
Created September 1, 2009 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottferg/179365 to your computer and use it in GitHub Desktop.
Save scottferg/179365 to your computer and use it in GitHub Desktop.
{
"name": "Sizerator",
"version": "1.0",
"description": "The first extension that I made.",
"toolstrips": [
"my_toolstrip.html"
],
"permissions": [
"tabs"
],
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["resizer.js"]
}
]
}
<script type="text/javascript">
var page_port = null;
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(data) {
// Assign the content-script port to a global.
// Dunno if this will do the trick, but now we know what
// port to talk to.
page_port = port;
});
});
// Real men use jQuery
document.getElementById("button").onclick = function() {
// This fires off the message to tell the content-script
page_port.postMessage({width:800, height:600});
}
</script>
<div class="toolstrip-button" id="button">
<span>800 x 600</span>
</div>
// Connects up a message listener when the page loads
// This will receive the port.postMessage() from the extension
var port = chrome.extension.connect();
port.onMessage().addListener(function(data) {
// Resize your shit here
});
// Fire off a message just to say "hi" to the toolstrip
port.postMessage({});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment