Perl programmer for hire: download my resume (PDF).
John Bokma MexIT
freelance Perl programmer

Copy URL+ extension for Firefox

Thursday, January 18, 2007 | 3 comments

Sometime ago I wrote a small Greasemonkey script that adds 3 HTML input elements to the page I am viewing in Firefox, each containing the address of the current page and additional info in a different format: HTML, BBCode, and MediaWiki markup.

HTML input elements generated by my Greasemonkey script.
HTML input elements generated by my Greasemonkey script.

I was not really happy with this quick hack. Most of the time I have it turned off because the 3 input fields at the top of each page look ugly. And also due to bugs the script sometimes didn't copy the entire title of the page. I had been thinking about rewriting the Greasemonkey script, and make it copy to the clipboard instead, and access it via the context menu of Firefox.

Today, while cleaning up my bookmarks in Firefox by copying useful ones to a local wiki using the aforementioned Greasemonkey script, I rediscovered an extension I had never tested: Copy URL+.

Moreover the following remark on the Copy URL+ home page:

As of version 1.1, you can also extend Copy URL+ with your own menu entries. See the Customize Copy URL+ section.

convinced me that I had to try this extension.

Downloading and installing Copy URL+

At first I tried to install the Copy URL+ extension by clicking on the "V1.3.2 XPI INSTALL LINK" on the Copy URL+ installation page. I was however quite sure that this wouldn't work because the changes mentioned a "Fix for Firefox v1.5", and I running Mozilla Firefox 2.0.0.1 at the time of writing.

And I was right, the extension couldn't be installed: "Copy URL + 1.3.2 could not be installed because it is not compatible with Firefox 2.0.0.1 (Copy URL + 1.3.2 will only work with Firefox versions from 1.0 to 1.6)". So I decided to see if Updating a Firefox extension would work for Copy URL+ as well.

So I opened copyurlplus-v1.3.2.xpi via the 7-Zip File Manager, copied the install.rdf file to a folder, opened the file in TextPad, changed maxVersion from 1.6 into 2.1, and dropped the now modified file back into the 7-Zip File Manager, replacing the original.

Too fast? Read Updating a Firefox extension for step-by-step instructions.

After dropping the modified copyurlplus-v1.3.2.xpi into the Firefox main window, a flawless installation, and a restart, the extension worked perfectly.

Customizing Copy URL+

The next step was to customize Copy URL+ in such a way that I got the same formats available as via the Greasemonkey hack I wrote some time ago. New entries to the Copy URL+ submenu (available via the context menu, right mouse button on Windows) can be added by adding two lines per entry to the user.js file: one to define a menu label, and one to define what information should be copied to the clipboard, see customize Copy URL+ on how to locate the user.js file on your computer. If you can't find it in your xxxxxxxx.default folder (with xxxxxxxx several random characters), just create a new file like I did.

I added the following lines to the newly created user.js file:

// user preferences for the Copy URL+ extension

user_pref('copyurlplus.menus.1.label', 'HTML link');
user_pref('copyurlplus.menus.1.copy',
          '<a href="%URL_HTMLIFIED%">%TITLE_HTMLIFIED%</a>');

user_pref('copyurlplus.menus.2.label', 'HTML selection link');
user_pref('copyurlplus.menus.2.copy',
          '<a href="%URL_HTMLIFIED%">%SEL_HTMLIFIED%</a>');

user_pref('copyurlplus.menus.3.label', 'HTML li link');
user_pref('copyurlplus.menus.3.copy',
          '<li><a href="%URL_HTMLIFIED%">%TITLE_HTMLIFIED%</a></li>');

user_pref('copyurlplus.menus.4.label', 'HTML li selection link');
user_pref('copyurlplus.menus.4.copy',
          '<li><a href="%URL_HTMLIFIED%">%SEL_HTMLIFIED%</a></li>');

user_pref('copyurlplus.menus.5.label', 'HTML li link - selection');
user_pref('copyurlplus.menus.5.copy',
'<li><a href="%URL_HTMLIFIED%">%TITLE_HTMLIFIED%</a> - %SEL_HTMLIFIED%</li>');

user_pref('copyurlplus.menus.6.label', 'WikiMedia link');
user_pref('copyurlplus.menus.6.copy',  '[%URL% %TITLE%]');


user_pref('copyurlplus.menus.7.label', 'WikiMedia selection link');
user_pref('copyurlplus.menus.7.copy',  '[%URL% %SEL%]');

user_pref('copyurlplus.menus.8.label', 'WikiMedia * link');
user_pref('copyurlplus.menus.8.copy',  '* [%URL% %TITLE%]');


user_pref('copyurlplus.menus.9.label', 'WikiMedia * selection link');
user_pref('copyurlplus.menus.9.copy',  '* [%URL% %SEL%]');

user_pref('copyurlplus.menus.10.label', 'WikiMedia * link - selection');
user_pref('copyurlplus.menus.10.copy',  '* [%URL% %TITLE%] - %SEL%');

user_pref('copyurlplus.menus.11.label', 'BBCode link');
user_pref('copyurlplus.menus.11.copy',  '[url=%URL%]%TITLE%[/url]');

user_pref('copyurlplus.menus.12.label', 'BBCode selection link');
user_pref('copyurlplus.menus.12.copy',  '[url=%URL%]%SEL%[/url]');

user_pref('copyurlplus.menus.13.label', 'BBCode quoted selection link');
user_pref('copyurlplus.menus.13.copy',
          '[quote]%SEL%[/quote]%EOL%Source: [url=%URL%]%TITLE%[/url]');

You can select the above user preferences and copy them to your own user.js file.

My customized version of Copy URL+.
My customized version of Copy URL+.

See customize Copy URL+ for a list of all available variables and more examples.

Extension Related

Also today

Please post a comment | read 3 comments, latest by Matthew Cornell | RSS feed