Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Firefox to qm
#1
now that i know how to add toolbar buttons and contextmenu items to firefox,
i ask you for ideas how to use it.

main function is pass url to qm.

but its also possible to pass url + title + selection ...
pi
#2
qm in firefox context menu:

[Image: qm_in_firefox.jpg]
pi
#3
AHHHHH....i just thought of a way to use this but i need your help.

i'd like to have a ff context menu to fire off a macro that will grap the url that i'm hovering over and put it in a text file so i can load them all at once when i go to lunch.

i've got everything except the context menu thing and how to grab the url i'm hovering over.

any help would be very apprciated.

Ken
An old blog on QM coding and automation.

The Macro Hook
#4
first install:
ChromEdit Plus Special Edition
http://webdesigns.ms11.net/chromeditpSE.html

and take a look at
http://webdesigns.ms11.net/ChromeFiles.zip

put the attached file into \chrome\UCJSFiles\

On Windows XP/2000, the path is usually %AppData%\Mozilla\Firefox\Profiles\xxxxxxxx.default\, where xxxxxxxx is a random string of 8 characters. Just browse to C:\Documents and Settings\[User Name]\Application Data\Mozilla\Firefox\Profiles\ and the rest should be obvious.

this is only neccerary when you want to have an icon in the menu:
add the following code the userChrome.css (you will have to change the path to your qm icon) and restart FF.
Code:
Copy      Help
menuitem[label="LaunchQM"]  {
   background-image: url("file:///C:/Dokumente und Einstellungen/pi/Eigene Dateien/My QM/qm.png") !important;
   background-position: top left !important;
   background-repeat: no-repeat !important;
}

in the script i call function ff2qm (line 44),
Code:
Copy      Help
var args = ["Q","+","M","+ff2qm+","A",[aURI.spec],"context"];
in case you don't the second argument just remove it (example function has to be changed too Idea ).

Code:
Copy      Help
var args = ["Q","+","M","+ff2qm+","A",[aURI.spec]];

ff2qm
Code:
Copy      Help
/
function [$a1] [lpstr'a2]

sel a2
,case "context"
,,_s=a1
,,_s.setclip
,case else
,,out a1


Attached Files
.zip   LaunchQM.uc.zip (Size: 1.08 KB / Downloads: 374)
.zip   qm_png.zip (Size: 407 bytes / Downloads: 385)
pi
#5
this way you can pass only one url at a time to qm (no mulitple selection),
but i have a code snippet which could send text selection to qm.
then you would have to parse the selection for urls.
pi
#6
awesome...thanks.
pretty involved but i'll try to get in going.
An old blog on QM coding and automation.

The Macro Hook
#7
i made some progress.

here is an example firefox content menu script

Code:
Copy      Help
var LaunchQM = {
    mSchemes: ["file", "ftp", "http", "https"],

    init: function()
    {
        this.mItem = document.createElement("menuitem");
        this.mItem.setAttribute("label", "Tweet! this");
        this.mItem.setAttribute("accesskey", "q");
        document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function() { LaunchQM.onPopupShowing(this); }, false);
    },

    onPopupShowing: function(aPopup)
    {
        aPopup.insertBefore(this.mItem, document.getElementById("context-sep-" + ((gContextMenu.onLink)?"open":"stop")));
        this.mItem.setAttribute("oncommand", "LaunchQM.launch(" + ((gContextMenu.onLink)?"gContextMenu.linkURI":"gBrowser.currentURI") + ");");
        //this.mItem.hidden = !gContextMenu.onLink && (gContextMenu.isTextSelected || gContextMenu.onImage || gContextMenu.onTextInput);
        this.mItem.setAttribute("disabled", this.mItem.hidden || !this.isSupported((gContextMenu.onLink)?gContextMenu.linkURI:gBrowser.currentURI));
    },

    launch: function(aURI, aApp)
    {
        if (!this.isSupported(aURI))
        {
            throw new Error("LaunchQM: unsupported URI scheme '" + aURI.scheme + "'!");
        }
        
        var qm = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
        try
        {
            var regkey = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
            regkey.open(Components.interfaces.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\" + (aApp || "QM.EXE"), Components.interfaces.nsIWindowsRegKey.ACCESS_READ);
            iexplore.initWithPath(regkey.readStringValue(""));
            regkey.close();
        }
        catch (ex)
        {
            qm.initWithPath((Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get("PROGRAMFILES") || "C:\\Program Files") + "\\Quick Macros 2\\qm.exe");
        }
        var focusedWindow = document.commandDispatcher.focusedWindow;
        var winWrapper = new XPCNativeWrapper(focusedWindow, "document", "getSelection()");
        var selection = winWrapper.getSelection().toString();
        var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
        process.init(qm);
        var args = ["Q","+","M","+ff2qm+","A",[aURI.spec], selection, "context"];
        //var args = ["Q","+","M","+ff2qm+","A",str,"context"];
        process.run(false, args, args.length);
    },

    isSupported: function(aURI)
    {
        return this.mSchemes.indexOf(aURI.scheme) > -1;
    }
};

LaunchQM.init();

the lines
this.mItem.setAttribute("label", "Tweet! this");
var args = ["Q","+","M","+ff2qm+","A",[aURI.spec], selection, "context"];

are very important.
1. set context menu label
2. everything after "A", will be passed to a qm function.

replace "+ff2qm+" with your own function.
your function has to be enclosed with + !!!

you also need to replace LaunchQM to something else.
pi


Forum Jump:


Users browsing this thread: 1 Guest(s)