function setupContextMenus() {
  if (sendUri == null) {
    sendUri = contextMenu.Item({
      label:         "Send this link to device...",
      context:       contextMenu.SelectorContext("a[href]"),
      contentScript: 'self.on("click", function(node) {' +
                     '  let title = document.title;' +
                     '  let uri = node.href;' +
                     '  self.postMessage([uri, title]);' +
                     '});',
      onMessage:     function onMessage(data) {
        promptAndSendURIToDevice(data[0], data[1]);
      }
    });
  }

  if (sendPage == null) {
    sendPage = contextMenu.Item({
      label:         "Send this page to device...",
      context:       contextMenu.PageContext(),
      contentScript: 'self.on("click", function(node) {' +
                     '  let title = document.title;' +
                     '  let uri = document.URL;' +
                     '  self.postMessage([uri, title]);' +
                     '});',
      onMessage:     function onMessage(data) {
        promptAndSendURIToDevice(data[0], data[1]);
      }
    });
  }
}
Exemple #2
0
var prepare_open_menu = function() {
    remove_items();

    var open_link_item = cm.Item({
        label: "Abrir link en Modo Privado",
        image: data.url("img/privacy-link16.png"),
        context: cm.SelectorContext("a[href]"),
        contentScriptFile: data.url("js/cm-openlink.js"),
        onMessage: function(src) {
            url_to_open = src;
            pb.activate();
        }
    });
    menuitems.push(open_link_item);

    var open_private_item = cm.Item({
        label: "Abrir Modo Privado",
        image: data.url("img/privacy16.png"),
        contentScript: 'self.on("click", self.postMessage)',
        onMessage: function() {
            pb.activate();
        }
    });
    menuitems.push(open_private_item);
};
exports.example1 = function example1() {
	var contextMenu = require("context-menu");

	// Create a new context menu item.
	var menuItem = contextMenu.Item({

	    label: "TW Travel Assistant",

	    // A CSS selector. Matching on this selector triggers the
	    // display of our context menu.
	    context: "a[href]",

	    // When the context menu item is clicked, perform a Google
	    // search for the link text.
	    onClick: function(contextObj, item) {
	        var anchor = contextObj.node;
	        // var twTravel = require("tw-travel");
	        //     twTravel.log(anchor.textContent);
	        var searchUrl = "http://www.google.com/search?q=" +
	        anchor.textContent;
	        contextObj.window.location.href = searchUrl;
	    }
	});

	// Add the new menu item to the application's context menu.
	contextMenu.add(menuItem);
};
function createAskDax() {
    menuItem = contextMenu.Item({
        label: "Ask DuckDuckGo about that",
        context: contextMenu.SelectionContext(),
        contentScript: 'self.on("context", function () {' +
                   '  var input = window.getSelection().toString();' +
                   '  self.postMessage(input); ' +
                   '  return "Ask the duck"; ' +
                   '});' + 
                   'self.on("click", function(){ ' +
                   '  var input = window.getSelection().toString();' +
                   '  window.open("https://duckduckgo.com/?q=" + input, "_blank");' +
                   '});' ,
        image: data.url('img/icon_16.png'),
        onMessage: function(msg){
            res = result(msg);
            if (res !== null && res[0] !== '' && res[0] !== undefined) {
                this.label = res[0];
                this.image = res[1];
            } else {
                this.image = data.url('img/icon_16.png');
                this.label = 'Ask Dax about ' + msg ;
            }
        }
    });
}
Exemple #5
0
exports.main = function() {
    var myItem = contextMenu.Item({
        label: "copy tinyurl",
        context: contextMenu.SelectorContext("a[href]"),
        contentScript:  'on("click", function(node, data) {' +
                        '   postMessage(node.href);'+
                        '});',
        onMessage: function(mes) {
            var req = new xhr.XMLHttpRequest();
            var url = "http://tinyurl.com/api-create.php?url=";
            req.open("GET", url+encodeURI(mes));
            req.send(null);
            req.onreadystatechange = function() {
                if (req.readyState == 4 ) {
                    if (req.status == 200) {
                        clipboard.set(req.responseText);
                        notify("successed!");
                    }
                    else {
                        notify("faild!");
                    }
                }
            };
        }
    });
};
 var createContextMenus = function(data) {
     var item = (data.type == 'separator') ? cm.Separator() : cm.Item({ 
         label: data.title, 
         contentScript: 'self.on("click", function() { self.postMessage("click"); });',
         onMessage: data.onclick
     });
     contextMenu.items.push(item);
     return item;
 };
Exemple #7
0
exports.main=function(options){

if(options.loadReason=="install"){
	require("tabs").open(data.url("welcome.html")); //Welcome HTML file
	//Configurar con pagina XUL o HTML o Javascript
	
}
if(options.loadReason=="upgrade"){
	require("tabs").open(data.url("changelog.html")); //Changelog HTML file
}

 var mm = require("context-menu");
 var menuItem = mm.Item({
  label: "Share on Google+",
  contentScript: 'self.on("click", function () {' +
                 '  self.postMessage(document.URL);' +
                 '});',
  onMessage: function (url) {
    ShareURL(url);
  }
});
var shareHotKey = Hotkey({
  combo: prefs.hotkey,
  //combo: "accel-shift-s",
  onPress: function() {
    ShareURL(tab.activeTab.url);
  }
});

require("simple-prefs").on("review",function (){
	require("tabs").open("http://addons.mozilla.org/en/firefox/addon/google-share");
});


var pluspanel=panel.Panel({
	height: prefs.height,
	width: prefs.width,
	contentURL: "about:blank"

});

var pluswidget=widget.Widget({
	id: "google-share-widget",
	label: "Google+ Share",
	contentURL: data.url("icon64.png"), 	
	panel: pluspanel,
	onClick: function() {
		pluspanel.contentURL="http://plus.google.com/share?url="+tab.activeTab.url;		
	}
});


}
Exemple #8
0
 var createMenuItemFor = function (kontext) {
   return  contextMenu.Item({
     label: "View Google's cache",
     image: self.data.url ("images/icon.png"),
     context: kontext,
     contentScript: 'self.on("click", function () {' +
       '  self.postMessage();' +
       '});',
     onMessage: function () {
       loadCachedPage ();
     }
   });
 };
Exemple #9
0
var prepare_close_menu = function() {
    remove_items();

    var close_item = cm.Item({
        label: "Salir del Modo Privado",
        image: data.url("img/privacy16.png"),
        contentScript: 'self.on("click", self.postMessage)',
        onMessage: function() {
            pb.deactivate();
        }
    });
    menuitems.push(close_item);
};
Exemple #10
0
(function(){
	var cm = require("context-menu");
	cm.Item({
	  label: "微博搜索",
	  context: cm.SelectionContext(),
	  contentScript: 'self.on("context", function () {' +
	                 '  var text = window.getSelection().toString();' +
	                 '  if (text.length > 20)' +
	                 '    text = text.substr(0, 20) + "...";' +
	                 '  return "微博搜索 " + text ;' +
	                 '});' +
	                 'self.on("click", function (node, text) {window.open("http://s.weibo.com/weibo/" + window.getSelection().toString())});'
	});
})();
Exemple #11
0
function createContextMenu(kontext) {
	var enableOrDisable = contextMenu.Item({
		label: "Enable",
		data: 'enable',
		contentScriptFile: [data.url('enable_disable.js')],
		context: kontext,
		onMessage: function(data) {
			if (data.kind == 'context') {
				this.data = data.data;
			}
		}
	}),
	separator = contextMenu.Separator(),
	hindi = contextMenu.Item({
		label: "Hindi",
		data: 'hi',
		context: kontext
	});
	malayalam = contextMenu.Item({
		label: "Malayalam",
		data: 'ml',
		context: kontext
	});
	var varnamMenu = contextMenu.Menu({
		label: "Varnam",
		context: kontext,
		contentScriptWhen: 'ready',
		contentScriptFile: [data.url('context_menu.js')],
		items: [enableOrDisable, separator, hindi, malayalam],
		image: data.url('icons/icon.png'),
		onMessage: function(data) {
            enableOrDisableVarnam (data);
		}
	});

	return varnamMenu;
};
Exemple #12
0
exports.main = function(options, callbacks) {

    var contextMenu = require("context-menu");

    var editImageItem = contextMenu.Item({
        label: "Edit image with Picnik",
        onClick: function (context) {
            require("tab-browser").Tabs.add('http://www.picnik.com/?import=' + escape(context.node.src), true);
        },
        context: 'img'
    });

    contextMenu.add(editImageItem);

}
Exemple #13
0
exports.main = function() { 
  var copyPlainText = contextMenu.Item({ 
    label: "Copy - Plain Text", 
    // Show this item when a selection exists. 
    context: contextMenu.SelectionContext(), 
    // When this item is clicked, post a message to the item with the selected text
    contentScript: 'self.on("click", function () {' +
                   '  var text = window.getSelection().toString();' +
                   '  self.postMessage(text);' +
                   '});', 
    //set the clipboard to what is in the message
    onMessage: function(text) { 
        clipboard.set(text);  
    }
  }); 
}  
Exemple #14
0
exports.main = function(options,callback){

    // Load old shift key and other CSS for saved notification
    var pmod = pageMod.PageMod({
        include: ['*'],
        contentScriptWhen: 'end',
        contentScriptFile: [data.url('jquery-1.5.2.min.js'),
                            data.url('initialize.js')]
    });

    // Right clicking on image shows up a new menu item for Saving to cubbi.es
    var menuItem = contextMenu.Item({
        label: "Save to Cubbi.es",
        context: contextMenu.SelectorContext("img"),
        contentScriptFile: [data.url('utils.js')]
    });
}
Exemple #15
0
exports.main = function (options, callbacks) {
	function getGeneratorContent(menuData) {
		var actionUrl = menuData.formAction || menuData.locationHref;
		return {
			domainKey: eTLDSvc.getBaseDomainFromHost(actionUrl.split("/")[2]),
			masterKey: menuData.passwordFieldValue,
			reqLength: (menuData.passwordFieldMaxLen > 8 && menuData.passwordFieldMaxLen < 48) ? menuData.passwordFieldMaxLen : 48,
			savedUrl: menuData.locationHref.split("/").slice(0,3).join("/"),
			savedFormUrl: actionUrl.split("/").slice(0,3).join("/"),
			savedUsrField: menuData.usernameFieldName,
			savedPwField: menuData.passwordFieldName,
			savedUsername: menuData.usernameFieldValue
		};
	}

	var generatorPanel = panel.Panel({
		width: 600,
		height: 480,
		contentURL: data.url("generator.html"),
		contentScriptFile: [
			data.url('generator.js'),
			data.url('sha256.js'),
			data.url('linear-congruential-generator.js')
		],
		onShow: function () {
			this.postMessage(this.content);
		}
	}),

		menuItem = contextMenu.Item({
		label: "Generate Password",
		context: contextMenu.SelectorContext("input[type=password]"),
		contentScriptFile: data.url('context-menu.js'),
		onMessage: function(data) {
			generatorPanel.content = getGeneratorContent(data);
			console.log(generatorPanel.content.toSource());
			generatorPanel.show();
		}
	});

	generatorPanel.port.on('hide', function () {
		generatorPanel.hide();
	});

};
exports.example2 = function example2() {
	// Import the APIs we need.
	var contextMenu = require("context-menu");
	var request = require("request");
	var selection = require("selection");

	// Create a new context menu item.
	var menuItem = contextMenu.Item({

	    label: "Translate Selection",

	    // Show this item when a selection exists.
	    context: contextMenu.SelectionContext(),

	    // When this item is clicked, post a message to the item with the
	    // selected text and current URL.
	    contentScript: 'on("click", function () {' +
	    '  var text = window.getSelection().toString();' +
	    '  postMessage({ text: text, url: document.URL });' +
	    '});',

	    // When we receive the message, call the Google Translate API with the
	    // selected text and replace it with the translation.
	    onMessage: function(selectionInfo) {
	        var req = request.Request({
	            url: "http://ajax.googleapis.com/ajax/services/language/translate",
	            content: {
	                v: "1.0",
	                q: selectionInfo.text,
	                langpair: "|en"
	            },
	            headers: {
	                Referer: selectionInfo.url
	            },
	            onComplete: function(response) {
	                selection.text = response.json.responseData.translatedText;
	            }
	        });
	        req.get();
	    }
	});

	// Add the new menu item to the application's context menu.
	contextMenu.add(menuItem);
}
Exemple #17
0
exports.main = function(options, callbacks) {
  //console.log(options.loadReason);
 
  // Create a new context menu item.
  var menuItem = contextMenu.Item({
 
    label: "Translate Selection",
 
    // Show this item when a selection exists.
 
    context: contextMenu.SelectionContext(),
 
    // When this item is clicked, post a message to the item with the
    // selected text and current URL.
    contentScript: 'on("click", function () {' +
                   '  var text = window.getSelection().toString();' +
                   '  postMessage(text);' +
                   '});',
 
    // When we receive the message, call the Google Translate API with the
    // selected text and replace it with the translation.
    onMessage: function (text) {
      if (text.length == 0) {
        throw ("Text to translate must not be empty");
      }
      //console.log("input: " + text)
      var req = request.Request({
        url: "http://ajax.googleapis.com/ajax/services/language/translate",
        content: {
          v: "1.0",
          q: text,
          langpair: "|zh"
        },
        onComplete: function (response) {
          translated = response.json.responseData.translatedText;
          //console.log("output: " + translated)
          selection.text = translated;
        }
      });
      req.get();
    }
  });
};
Exemple #18
0
exports.main = function(options, callbacks) {
  console.log(options.loadReason);
 
  // Create a new context menu item.
  var menuItem = contextMenu.Item({
    label: "Calculate Readability",
    // Show this item when a selection exists.
    context: contextMenu.SelectionContext(),
    // When this item is clicked, post a message back with the selection
    contentScript: 'self.on("click", function () {' +
                   '  var text = window.getSelection().toString();' +
                   '  self.postMessage(text);' +
                   '});',
    // When we receive a message, look up the item
    onMessage: function (selText) {
      console.log('Calculating readability value for :"' + selText + '"');
      calculateReadability(selText);
    }
  });
};
Exemple #19
0
exports.main = function(options, callbacks) {
  console.log(options.loadReason);
 
  // Create a new context menu item.
  var menuItem = contextMenu.Item({
    label: "Ask AMEE about this",
    // Show this item when a selection exists.
    context: contextMenu.SelectionContext(),
    // When this item is clicked, post a message back with the selection
    contentScript: 'self.on("click", function () {' +
                   '  var text = window.getSelection().toString();' +
                   '  self.postMessage(text);' +
                   '});',
    // When we receive a message, look up the item
    onMessage: function (item) {
      console.log('looking up "' + item + '"');
      lookup(item);
    }
  });
};
exports.main = function(options, callbacks) {
  console.log(options.loadReason);
 
  var menuItem = contextMenu.Item({
 
    label: "Lookup in WikiPedia",
    context: contextMenu.SelectionContext(),
    contentScript: 'self.on("click", function () {' +
		   ' var text = window.getSelection().toString();' +
                   '  self.postMessage(text);' +
                   '});',
 
    // When we receive the message, call the Google Translate API with the
    // selected text and replace it with the translation.
    onMessage: function (text) {
      if (text.length === 0) {
        throw ("Text to translate must not be empty");
      }
      windows.open("http://en.wikipedia.org");
      console.log("input: " + text);
      var req = request.Request({
        url: "http://ajax.googleapis.com/ajax/services/language/translate",
        content: {
          v: "1.0",
          q: text,
          langpair: "|en"
        },
        onComplete: function (response) {
          translated = response.json.responseData.translatedText;
          console.log("output: " + translated);
          selection.text = translated;
        }
      });
      req.get();
    }
  });
};
Exemple #21
0
  setupContextMenu: function () {
    // The whole decryption logic. It is somewhat simpler than the encryption
    // logic as we don't need to show a panel in-between and the "gpg" module
    // takes care of prompting the user for a passphrase.
    context.Item({
      label: _("decrypt_menu_item"),
      context: context.PageContext(),
      contentScriptFile: self.data.url("page-decrypt-context-menu.js"),
      onMessage: function ({ className, text: [head, pgpBlock, tail] }) {
        // So, the user requested that we decrypt the text it found in the node
        // with class {className}; {head} is the text before the PGP block,
        // {tail} is the text that comes after it, and {pgpBlock} is the entire
        // PGP block.
        let tab = tabs.activeTab;
        console.log("Decryption requested", className);

        // The "gpg" module takes care of everything for us.
        gpg.decrypt({
          text: pgpBlock
        }, function (pgpBlock) {
          console.log("Decryption performed", className);

          // And now we attach a worker to replace the DOM node with the
          // decrypted text.
          let worker = tab.attach({
            contentScriptFile: self.data.url("page-decrypt.js"),
            onMessage: function(aMessage) {
              // As usual, the worker is a nice guy and will tell us when we can
              // destroy it.
              if (aMessage == "seppuku") {
                console.log("Worker destroyed");
                worker.destroy();
              }
            },
          });
          worker.postMessage({ className: className, text: [head, pgpBlock, tail] });
        });
      },
    });

    // The whole encryption logic.
    context.Item({
      label: _("encrypt_menu_item"),
      contentScriptFile: self.data.url("page-encrypt-context-menu.js"),
      onMessage: function ({ className, text }) {
        // We assume the active tab is the one from which the right click
        // originates, so we save it.
        let tab = tabs.activeTab;
        console.log("Encryption requested", className);

        // We need to display a panel so that the user can pick the recipient.
        let thePanel = panel.Panel({
          contentURL: self.data.url("panel-recipient.html"),
          contentScriptFile: self.data.url("panel-recipient.js"),
          height: 60,
        });

        // Once the panel notifies us with a recipient, we can launch the
        // encryption.
        thePanel.port.on("ok", function({ recipient }) {
          console.log("User asked to encrypt for", recipient);
          gpg.encrypt({
            text: text,
            recipient: recipient
          }, function (text) {
            // Once we get the results of the encryption, we attach a worker to
            // the content page; the worker will take care of modifying the DOM
            // to replace the put the encrypted text in the right place.
            console.log("Encryption performed", className);
            thePanel.destroy();
            let worker = tab.attach({
              contentScriptFile: self.data.url("page-encrypt.js"),
              onMessage: function(aMessage) {
                // We try to destroy the worker as soon as possible.
                if (aMessage == "seppuku") {
                  console.log("Worker destroyed");
                  worker.destroy();
                }
              },
            });
            // Let's give the worker the data it needs.
            worker.postMessage({ className: className, text: text });
          });
        });

        thePanel.show();
      },
    });
  },
        title: "URL Shortened!",
        text: json.id + " has been copied to the clipboard."
    });
};

/**
 * Create the context-menu item.
 */
let cm = require("context-menu");
cm.Item({
    label: "Shorten URL",
    /* only display for links */
    context: cm.SelectorContext("a[href]"),
    /* the content script */
    contentScript: 'self.on("click", function (node) {' +
                 '  self.postMessage(node.href)' +
                 '});',
    /* handle the postMessage from the content script */
    onMessage: function(href) {
        shorten(href, completionCallback);
    }
});

/**
 * Create the key binding.
 */
let shortenHotKey = require("hotkeys").Hotkey({
    combo: "accel-shift-u",
    onPress: function() {
        if (/^http[s]*:\/\//.test(tabs.activeTab.url)) {
            shorten(tabs.activeTab.url, completionCallback);
Exemple #23
0
exports.main=function(options)
{
	if(options.loadReason=="install"){
		require("tabs").open("http://adrianarroyocalle.github.io/firefox-addons/page/divel-notepad/welcome.html");
		require("tabs").open("http://sites.google.com/site/divelmedia");	
	}
	if(options.loadReason=="upgrade"){
		notifications.notify({
			title: "Divel Notepad",
			text: "Succesfully upgraded to Divel Notepad 1.3",
			iconURL: data.url("open64.png")
		});
		require("tabs").open("http://adrianarroyocalle.github.io/firefox-addons/page/divel-notepad/changelog.html");
		require("tabs").open("http://sites.google.com/site/divelmedia");
	}
	require("simple-prefs").on("review",function (){
		require("tabs").open("http://addons.mozilla.org/en/firefox/addon/divel-notepad");
	});
	var xulapp=require("sdk/system/xul-app");
	if(xulapp.name=="Firefox")
	{
		firefox=true;
	}
	if(xulapp.name=="Fennec")
	{
		fennec=true;
	}
	if(xulapp.name=="SeaMonkey")
	{
		seamonkey=true;
	}
	if(xulapp.name=="Thunderbird")
	{
		thunderbird=true;
	}
	if(firefox==true)
	{
		var mm = require("context-menu");
 		var quicknote = mm.Item({
 		 label: "Quick Note",
 		 contentScript: 'self.on("click", function () {' +
                 '  self.postMessage(document.URL);' +
                 '});',
 		 onMessage: function (url) {
 		   QuickNote();
 		 }
		});
		var managenotes = mm.Item({
 		 label: "View notes",
 		 contentScript: 'self.on("click", function () {' +
                 '  self.postMessage(document.URL);' +
                 '});',
 		 onMessage: function (url) {
 		   ViewNote();
 		 }
		});
	}
	if(firefox==true)
	{
		var widget=require("widget");
		var pluswidget=widget.Widget({
			id: "divel-notepad-view",
			label: "Quick Note",
			contentURL: data.url("save32.png"),
			onClick: function() {
				QuickNote();	
			}
		});
		var managewidget=widget.Widget({
			id: "divel-notepad-manage",
			label: "View notes",
			contentURL: data.url("open32.png"), 	
			onClick: function() {
				ViewNote();
			}
		});
	}
}
Exemple #24
0
var contextMenu = require("context-menu");
var menuItem = contextMenu.Item({
  // 右键菜单显示的文字
  label: "Log Selection",

  // context 类型,这里是选中 context,当选中一段文字后出现该上下文菜单
  context: contextMenu.SelectionContext(),
  contentScript: 'self.on("click", function () {' +
               '  var text = window.getSelection().toString();' +
               '  self.postMessage(text);' +
               '});',

  // 用来接收来自 content script 的消息
  onMessage: function (selectionText) {
    console.log(selectionText);
  }
});
// Context-menu example.
let contextMenu = require('context-menu');
contextMenu.Item({
  label: 'Search Stack Overflow',
  image: require('self').data.url('favicon.ico'),
  context: contextMenu.SelectionContext(),
  contentScript: 'self.on("click", self.postMessage);',
  onMessage: function () {
    let selection = require('selection').text;
    let url = 'http://stackoverflow.com/search?q=' + selection;
    require('tabs').open(url);
  }
});


// Widget example.
require("widget").Widget({
  id: "StackOverflowJetpack",
  label: "Stack Overflow Search - Jetpack",
  contentURL: require('self').data.url('favicon.ico'),
  onClick: function() {
    require('tabs').open('http://stackoverflow.com/search?q=jetpack');
  }
});


// Panel example.
var panel = require("panel").Panel({
  contentURL: 'http://stackoverflow.com/search?q=jetpack'
});
Exemple #26
0
exports.main = function(options, callbacks) {
	console.log('Lookup ' + options.loadReason);
	
	var context = contextMenu.SelectionContext();
	var keywd = '';
	
	// Context menu items
	/*
	var cald = contextMenu.Item({
		label: "Cambridge Advanced Learner's",
		data: self.data.url('query_form.html#')
	});
	*/
	var ldoce = contextMenu.Item({
		label: "Longman Contemporary English",
		data: self.data.url('http://www.ldoceonline.com/search/?q=')
	});
	
	var freedict = contextMenu.Item({
		label: "The Free Dictionary",
		data: "http://www.thefreedictionary.com/"
	});
	var urbanDict = contextMenu.Item({
		label: "Urban Dictionary",
		data: "http://www.urbandictionary.com/define.php?term="
	});
	var mwDict = contextMenu.Item({
		label: "Merriam Webster Dictionary",
		data: "http://www.merriam-webster.com/dictionary/"
	});
	var wiktionary = contextMenu.Item({
		label: "Wiktionary",
		data: "http://en.wiktionary.org/wiki/"
	});
	var googleDef = contextMenu.Item({
		label: "Google definitions",
		data: "http://www.google.com/search?tbs=dfn:1&q="
	});

	var LookupMenu = contextMenu.Menu({
		label: "Lookup definitions online",
		context: context,
		contentScript: 'on("click", function (node, data) {' +
			'postMessage(data);' +
		'});',
		items: [ldoce, freedict, urbanDict, mwDict, wiktionary, googleDef],
		onMessage: function(url) { tabs.open(url+keywd); }
	});
	
	// TODO
	function _processKeyword(text) {
		text = text.replace(/^\s+|\s+$/g, '');
		text = text.substring(0,45);
		return text;
	}
	
	tabs.on('activate', function onActivate(tab) {
	 	worker = tabs.activeTab.attach({
			contentScript:'postMessage(window.getSelection().toString());',
			onMessage: function (data) {
				keywd = _processKeyword(data);
				console.log('Lookup - keyword reset -> \''+keywd+'\'');
			}
		});
	});
	
	// for selection context
	function myListener() {
		keywd = _processKeyword(selection.text);
		console.log('Lookup -> keyword set -> \''+keywd+'\'');
	}
	selection.on('select', myListener);
	
};
// This is an active module of the Google by Image Add-on
exports.main = function() {};
var contextMenu = require("context-menu");
var tabs = require("tabs");
var searchMenu = contextMenu.Item({
      label: "Google by Image",
  context: contextMenu.SelectorContext("img"),
  data: "http://images.google.com/searchbyimage?image_url=",
  contentScript: '  self.on("click", function (node, data) {' +
                 '  var searchURL = data + node.src;' +
                 '  self.postMessage(searchURL)' +
                 '});',
  onMessage: function (imgSrc) {
     tabs.open(imgSrc);
  }
});
exports.main = function (options, callbacks) {
    /* {{{ First-Run */
    if ('startup' != options.loadReason) {
        Languages.setup();
    }

    /* }}} */
    /* {{{ Settings */
    simple_prefs.on('FavoriteLanguages', function () {
        LanguagesPanel.show();
        
        LanguagesPanel.port.emit('init', {
            languages : Languages.languages,
            favorites : Languages.getFavorites(),
            tts_langs : Languages.speakLanguages,
        });
    });

    var LanguagesPanel = panels.Panel({
        width: 380,
        height: 280,
        contentURL : data.url('favorite-languages.html'),
        contentScriptFile : data.url('favorite-languages.js')
    });

    LanguagesPanel.port.on('close', function () {
        LanguagesPanel.hide();
    });

    LanguagesPanel.port.on('save', function (favs) {
        Languages.saveFavorites(favs);
        LanguagesPanel.hide();
    });
    

    /* }}} */
    /* {{{ Text Translation */
    var onTranslateText = function (text) {
        textTranslatePanel.show();
        textTranslatePanel.port.emit('init', {
            text : text,
            languages : Languages.languages,
            favorites : Languages.getFavorites(),
            speakLanguages : Languages.speakLanguages,
            locales : {
                'Original_Text' : _('Original_Text'),
                'To' : _('To'),
                'From' : _('From'),
                'Unknown' : _('Unknown'),
                'Translation_Error' : _('Translation_Error'),
                'Close' : _('Close')
            }
        });
    };

    cm.Item({
        label : _('Translate_This_Text'),
        image : data.url('images/icons/translator-16.png'),
        context : cm.SelectionContext(),
        contentScript : 'self.on("click", function () { self.postMessage(window.getSelection().toString());});',
        onMessage : onTranslateText
    });

    var textTranslatePanel = panels.Panel({
        width: 400,
        height: 320,
        contentURL : data.url('translate-text.html'),
        contentScriptFile : [data.url('jquery-1.8.2.min.js'), data.url('translate-text.js')],
    });

    textTranslatePanel.on('hide', function () {
        textTranslatePanel.port.emit('hide');
    });

    textTranslatePanel.port.on('close', function () {
        textTranslatePanel.hide();
    });

    textTranslatePanel.port.on('translate', function (options) {
        translator.text(options, function (data) {
            textTranslatePanel.port.emit('translation-complete', {
                result : data.result,
                status: data.status,
                to : options.to  
            });
        });
    });
    
    textTranslatePanel.port.on('detect', function (text) {
        translator.detect(text, function (data) {
            textTranslatePanel.port.emit('detect-complete', data.json);
        });
    });

    textTranslatePanel.port.on('speak', function (options) {
        translator.speak(options, function (data) {
            textTranslatePanel.port.emit('speak-complete', data.json);
        });
    });

    textTranslatePanel.port.on('save-favorites', function (favorites) {
        Languages.saveFavorites(favorites);
    });
    /* }}} */
    /* {{{ Webpage Translation */
    var translatePanel = panels.Panel({
        width : 200,
        height: 170,
        contentURL : data.url('translate-page.html'),
        contentScriptFile : [
            data.url('translate-page.js'),
            data.url('jquery-1.8.2.min.js')
        ]
    });

    translatePanel.on('show', function () {
        this.port.emit('init', {
            languages : Languages.generateSelectList(),
            locales : {'Auto_Detect' : _('Auto_Detect')}
        });
    });
    
    translatePanel.port.on('close', function () {
        translatePanel.hide();
    });

    translatePanel.port.on('translate-page', function (options) {

        if (true == options.auto) {
            Languages.setFavorite(options.to);
            prefs.set(prefs_branch+'.one_click', true);
        }

        translator.page({
            from : options.from, 
            to : options.to, 
            url : tabs.activeTab.url
        });

        translatePanel.hide();
    });

    var widget = widgets.Widget({
        id: "translator-toolbar-button",
        label: "Translator",
        contentURL: data.url('images/icons/translator-16.png'),
        onClick : function () {
            if (translator.validURL(tabs.activeTab.url)) { 
                if (simple_prefs.prefs.one_click) {
                    translator.page({
                        from : '',
                        to : Languages.getFavorite()['code'],
                        url : tabs.activeTab.url
                    }); 
                } else {
                    translatePanel.show();
                }
            }
        }
    });

    pageMod.PageMod({
        include: 'http://translate.google.com/translate?*',
        contentScriptFile: data.url("gtranslate-page-mod.js"),
        contentStyleFile: data.url("gtranslate-page-mod.css"),
        onAttach: function(worker) {
            worker.port.emit('attach');
        }
    });

    /* }}} */
};
exports.main=function(options)
{
	if(options.loadReason=="install")
	{
		//Create pre-generated CSS
		storage.colorHeader="#0e87c8";
		storage.backgroundImage=""; 
		storage.notificationsColor="#0e87c8";
		//Create pre-generated Gadgets
		storage.gadget="<h1>Bienvenido a Next Tuenti</h1>";
	}
	var cm = require("context-menu");
	var shareItem = cm.Item({
		label: "Compartir en Tuenti",
		contentScript: 'self.on("click", function () {' +
				'  self.postMessage(document.URL);' +
				'});',
		context: cm.PageContext(),
		onMessage: function (url) {
			ShareURL(url);
		}
	});
	var stylesItem = cm.Item({
		label: "Temas para Tuenti",
		contentScript: 'self.on("click", function(){self.postMessage();});',
		onMessage: function (){
			OpenStyleWindow();
		}
	});
	var downloadItem = cm.Item({
		label: "Descargar imagen",
		contentScript: 'self.on("click",function(){'+
			'self.postMessage(document.getElementById("photo_image").src);'+
			'});',
		onMessage: function(imageurl)
		{
			SaveImage(imageurl);
		}
	});
	var gadgetItem = cm.Item({
		label: "Mis gadgets",
		contentScript: 'self.on("click", function(){self.postMessage();});',
		onMessage: function()
		{
			OpenGadgetWindow();
		}
	});
	var menu=cm.Menu({
		label: "Next Tuenti",
		image: data.url("tuenti64.png"),
		items: [shareItem,stylesItem,downloadItem,gadgetItem]

	});
	//PageMod for styles
	var nextMod=require("page-mod").PageMod({
		include: "*.tuenti.com",
		contentStyle: GenerateCSS(),
		contentScriptFile: data.url("nextmod.js"),
		onAttach: function(worker)
		{
			worker.port.on("notifications",function(number){
				Notify("Tienes "+number+" notificaciones");
			});
			worker.port.emit("gadget",storage.gadget);
		}
	});

}
Exemple #30
0
 init: function() {
   //keyboard shortcut for translating whole entire page
   main.translateHotkey = Hotkey({
     combo: main.modifier + main.settings("keyCode"),
     onPress: function() {
       main.translatePage(tabs.activeTab.url);
     }
   });
   //set button in addon bar
   //BUG: Events will stop working when button is moved around. Will continue working again when browser is restarted
   main.translateWidget = widget.Widget({
       id: "translate-button",
       label: main.name + " - Translate Page",
       contentURL: main.iconSmall,
       contentScriptWhen: 'ready',
       contentScriptFile: main.widget
   });
   //check for left click, if there is a left click open a new tab with the translated version of the page
   main.translateWidget.port.on('left-click', function() {
       main.translatePage(tabs.activeTab.url, main.settings("language"));
   });
   //This used to open a settings panel, now direct users to about:addons
   main.translateWidget.port.on('right-click', function() {
       main.notify("Just a note...", "The settings panel has moved, you can find it under the addons area.")
       tabs.open("about:addons");
   });
   //Translate selection
   main.menuItem = contextMenu.Item({
       label: main.name + " - Selection",
       image: main.iconSmall,
       // Show this item when a selection exists.
       context: contextMenu.SelectionContext(),
       // When this item is clicked, post a message to the item with the text
       contentScript: 'self.on("click", function () {' +
                      '  self.postMessage(window.getSelection().toString());' +
                      '});',
       //Translate text
       onMessage: function(text) {
         main.translateText(text);
       }
   });
   //Translate current page
   main.pageItem = contextMenu.Item({
     label: main.name + " - Page",
     image: main.iconSmall,
     contentScript: 'self.on("click", function () {' +
                    '  self.postMessage(document.URL);' +
                    '});',
     onMessage: function(url) {
       main.translatePage(url);
     }
   });
   //Translate links
   main.linkItem = contextMenu.Item({
     label: main.name + " - Link",
     image: main.iconSmall,
     // Show this item when a selection exists.
     context: contextMenu.SelectorContext("a[href]"),
     // When this item is clicked, post a message to the item with the link's URL
     contentScript: 'self.on("click", function (node) {' +
                    '   self.postMessage(node.href);' +
                    '});',
     onMessage: function (url) {
       main.translatePage(url);
     }
   });
   return this;
 },