-
-
Save scottferg/179365 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"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"] | |
} | |
] | |
} |
This file contains hidden or 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 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> |
This file contains hidden or 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
// 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