Skip to content

Instantly share code, notes, and snippets.

@sajirdalas
Created April 10, 2015 12:16
Show Gist options
  • Save sajirdalas/641836e715cdea23b297 to your computer and use it in GitHub Desktop.
Save sajirdalas/641836e715cdea23b297 to your computer and use it in GitHub Desktop.
Code written during tutorial 10
//main.js
var cm = require("sdk/context-menu");
var item = cm.Item({
label: "Search on google",
data: "MyId",
//context: cm.PageContext()
//context: cm.URLContext(["*.mozilla.org","*.reddit.com"])
//context: cm.SelectionContext()
//context: cm.SelectorContext("#header-img")
contentScriptFile: "./CMcontentScript.js",
onMessage: function(payload){
tabs.open(payload);
}
});
//CMcontentScript.js
self.on("click",function(node,data){
console.log(node.href);
self.postMessage(node.href);
});
self.on("context",function(node){
if(typeof node.href != "undefined"){
return true;
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment