LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Modify Firefox pop-up menu (http://www.linuxquestions.org/questions/programming-9/modify-firefox-pop-up-menu-4175414880/)

danielbmartin 07-04-2012 09:57 AM

Modify Firefox pop-up menu
 
I may be browsing a web site and see a character string of particular interest. In this example it is a street address but it could be a person's name or something else.

I highlight the string and right click on it. This produces a pop-up menu like this:
Code:

Copy
Select All
Search Google For "13 Park Ave"
View Selection Source
Inspect Element

I want to add an optional action to launch my self-written application FV6 with the highlighted string as a parameter. The expanded pop-up menu would look like this
Code:

Copy
Select All
Search Google For "13 Park Ave"
View Selection Source
Inspect Element
Invoke FV6 with "13 Park Ave"

How should this be done? There are Firefox add-ons which claim to do something like this but I am reluctant to install them one-by-one until finding something suitable. Perhaps other LQers have blazed this trail and can give advice.

Daniel B. Martin

Slackyman 07-04-2012 12:11 PM

Can you give me the path to your application?

danielbmartin 07-04-2012 01:19 PM

Quote:

Originally Posted by Slackyman (Post 4719218)
Can you give me the path to your application?

The path is:
Code:

/home/daniel/Desktop/RexxScripts/fv6.rex
FV6 is a REXX program run with the regina interpreter. As things stand, to run the program I launch a terminal session and enter:
Code:

regina /home/daniel/Desktop/RexxScripts/fv6.rex
FV6 prompts the user for a search string but it could be passed as a parameter.

Daniel B. Martin

Slackyman 07-04-2012 01:28 PM

I'm trying developing your firefox addons.
I'm now chatting in developers irc mozilla channel since I don't know how to run locally binary files.
Things are changed since I was used developing in XUL! :)

firstfire 07-04-2012 01:29 PM

Hi, Daniel.

Is this what you are looking for?

danielbmartin 07-04-2012 02:07 PM

Quote:

Originally Posted by firstfire (Post 4719271)
Is this what you are looking for?

Thank you, firstfire, for this pointer. It looks promising but I cannot dig into it just now. Other projects cry out for immediate attention!

Daniel B. Martin

firstfire 07-04-2012 02:32 PM

Quote:

Originally Posted by danielbmartin (Post 4719297)
Thank you, firstfire, for this pointer. It looks promising but I cannot dig into it just now. Other projects cry out for immediate attention!

Daniel B. Martin

No problem. My biggest project right now, which cries out for immediate attention, is to manage to sleep a bit before the work, as it is 1:32 AM here :)

Slackyman 07-06-2012 01:38 AM

Fine!
Just register to Add-on Builder, create your own addon and use this code:
Code:

/* Slackyman Regina add-on for Firefox */

var contextMenu = require("context-menu"); /* create instance for handling context-menu */
var selection = require("selection"); /* create instance for handling selectiont */
const { Cc, Ci } = require('chrome'); /* required to access XPCOM components */
const proc = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
const ifile = Cc["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); 
ifile.initWithPath("/usr/bin/regina"); 
proc.init(ifile); 
 
// Run the process. 
// If first param is true, calling thread will be blocked until 
// called process terminates. 
// Second and third params are used to pass command-line arguments 
// to the process. 

exports.main = function(options, callbacks) {
  console.log(options.loadReason);
 
  // Create a new context menu item.
  var menuItem = contextMenu.Item({
    label: "FV6 selected",
    // 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);' +
                  '});',
    // When we receive the message, call the regina interpreter with
    // the path of the script and the selected text.
    onMessage: function (text) {
    var args = ['/home/daniel/Desktop/RexxScripts/fv6.rex', text];
    proc.run(false, args, args.length);
    }
  });
};


danielbmartin 07-08-2012 08:54 PM

Quote:

Originally Posted by Slackyman (Post 4720546)
Just register to Add-on Builder, create your own addon and use this code ...

Thank you, Slackyman, for writing this code. Please don't think I've ignored it. I registered to Add-on Builder which included establishing a password. Since that time I've been going roundy-round trying to create the add-on. It tells me the password is bad, so I reset it, and the password is still bad, etc. No doubt I've misread their instructions or botched an attempt to follow them. I'll keep trying.

Daniel B. Martin


All times are GMT -5. The time now is 06:24 AM.