Copy URL as <a href="...">Title</a> ??

Discussion of general topics about Mozilla Firefox
tvh2k
Posts: 13
Joined: January 18th, 2004, 12:45 pm

Copy URL as <a href="...">Title</a> ??

Post by tvh2k »

I was just wondering, is there a way to add context-menu functionality to FF simlar to that in IEB, where you can copy the page title and URL to clipboard in the form: <a href="...">Title</a> ?? I don't know if an extension would do this, if I would have to suggest this as an enhancement bug, or if the option is already built-in, perhaps hidden in the massive "about:config" or prefs.js. Either way, I appreciate any suggestions.

-tvh2k
finuvir
Posts: 735
Joined: July 27th, 2003, 4:52 pm
Location: Dublin, Ireland
Contact:

Post by finuvir »

That would be a trivial extension to implement. Perhaps if you suggest it in the extensions forum, someone will put it together for you. It would not take an experienced extention writer long (a couple of minutes at a guess). I'd try it myself, but I've never used the clipboard with an extension, so I'd have to do some research.
User avatar
BenBasson
Moderator
Posts: 13671
Joined: February 13th, 2004, 5:49 am
Location: London, UK
Contact:

Post by BenBasson »

I could probably write the JavaScript, but I need to learn how to package up extensions. As this is the case, I'll try and do the "core" part of this if you like, but someone else will have to extensionize it from my script... how would you like the output? I'd go for something like these, but you tell me what you want...

Code: Select all

MozillaZine : http://www.mozillazine.org

Code: Select all

MozillaZine
http://www.mozillazine.org

Code: Select all

MozillaZine (http://www.mozillazine.org)
User avatar
sensemann
Posts: 755
Joined: February 6th, 2003, 12:29 pm
Location: Dresden, Germany
Contact:

Post by sensemann »

oh... i'd be very interested in this. please keep this thread updated on your efforts ;)
perhaps it's be possible to choose from different version? I for myself could need it with just the title - no url.
: sensemann.com :
.:: Extensions :.
.:: Themes :.
finuvir
Posts: 735
Joined: July 27th, 2003, 4:52 pm
Location: Dublin, Ireland
Contact:

Post by finuvir »

I think the OP wanted:

Code: Select all

<a href="http://www.mozillazine.org">mozillaZine - Your Source for Daily Mozilla News and Advocacy</a>

That is, a link to the page with the page title as the link text.
User avatar
BenBasson
Moderator
Posts: 13671
Joined: February 13th, 2004, 5:49 am
Location: London, UK
Contact:

Post by BenBasson »

Raw HTML Test & JavaScript is here.
You might have to save it to your desktop first, I cant seem to make it run remotely anymore, due to security settings (look in the JS console, permission is being denied). If you run it from your desktop, it seems to prompt you about the security setting, and if you say yes, it copies it.

Over to someone who's good with extensionizing...
User avatar
BenBasson
Moderator
Posts: 13671
Joined: February 13th, 2004, 5:49 am
Location: London, UK
Contact:

Post by BenBasson »

Update: There's now 4 buttons, and 4 ways of copying the URLS.. I also threw in a textarea so that you can test. Once again, it probably only works locally... Source for main function is here:
http://www.krikkit.net/howto_javascript ... board.html

...oh and if you go into your about:config and set the following pref, you'll be able to try it direct from the web:
signed.applets.codebase_principal_support with the value true, or in user.js:
user_pref("signed.applets.codebase_principal_support", true);
finuvir
Posts: 735
Joined: July 27th, 2003, 4:52 pm
Location: Dublin, Ireland
Contact:

Post by finuvir »

Okay, I'm working on extension-izing this code. I just thought I'd put a note here to let other people know, so no-one else starts doing the same. I want to avoid duplication of effort.
finuvir
Posts: 735
Joined: July 27th, 2003, 4:52 pm
Location: Dublin, Ireland
Contact:

Post by finuvir »

Okay, you can now get the copytitle extension from my server. I was delayed by a very hard to find typo (actually I had mis-named a file)! Argh!

I think I can clean it up a bit if people would prefer, for example, the options to be in a submenu of the context menu or in a menu in the menubar. Feedback is very welcome as this is my first extension. Of course the main part of the code is Cusser's, and I'd like to know how to handle the copyright attributions and credits. The main thing is that it's available though. Enjoy!

Edit: Now on version 0.2. I've moved the three options (HTML Link, Forum Link and 'Title (URL)') into a submenu called Copy Title.
chuonthis
Posts: 519
Joined: July 23rd, 2003, 10:17 am

Post by chuonthis »

Sweet. Nice extension, a couple requests:
1) Can there be an option for whether or not to have the options in a submenu?
2) Not sure if there's already an extension for this but can you make it so that if you are right clicking on a link instead of a normal part of a page, it puts the link's information into the clipboard instead of the current page's information? Preferably, you can have everything inside the A tag so if it is an image, it'd copy the code for the image too (and use IMG tags for HTML Link and [img] tags for the Forum Link). Any part of this request would be kewl.
User avatar
BenBasson
Moderator
Posts: 13671
Joined: February 13th, 2004, 5:49 am
Location: London, UK
Contact:

Post by BenBasson »

Great work finuvir :) Um, regarding copyright and credit... AFAIK, nobody is going to worry about it.
In the JavaScript section if you just acknowledge me as "Ben Basson (Cusser)" and link the site I mentioned above for the original source, then it's probably covered all bases. I dont take much credit, as I really didn't do a lot... :D

[edit]I'll update my web-page testing thingy to incorporate the link/image copying shortly, finuvir, feel free to implement it as part of this extension, if you wish. It shouldn't be too hard to make Firefox figure out whether you're on a link or not... hopefully my code will do the rest. I'll post back when it's done.[/edit]
User avatar
BenBasson
Moderator
Posts: 13671
Joined: February 13th, 2004, 5:49 am
Location: London, UK
Contact:

Post by BenBasson »

I've done it (or at least appear to have)... check it out:
http://www.internet-trashcan.co.uk/misc ... tails.html
Right clicking will copy the link (and all it's contents - even images) as HTML or forum code to the clipboard. Check the forum code box if you want to try it.

Finuvir, over to you, if you wanna do it. If not, I could modify what you've done so far, but seeing as you'll probably do it faster, I'll leave it to you to decide.
User avatar
sensemann
Posts: 755
Joined: February 6th, 2003, 12:29 pm
Location: Dresden, Germany
Contact:

Post by sensemann »

great indeed. thanks alot, this extension is really helping me a bunch! :)

nevertheless, as always, there are some more requests:
- can you add that functionality to a "Copy Link" item? right now i can create a link for a page I'm on. another cool thing would be if I could right-click a link and instead of copying the url only i could copy the whole anchor (right now i'm either writing it myself or copy it via page source).
- how hard would it be to add some options to this extension, e.g. i'd like to have a target="_blank" in that anchor ;)

thanx
: sensemann.com :
.:: Extensions :.
.:: Themes :.
User avatar
BenBasson
Moderator
Posts: 13671
Joined: February 13th, 2004, 5:49 am
Location: London, UK
Contact:

Post by BenBasson »

I've basically just done all of that in my page. I've updated it as well... Hopefully either Funuvir or myself will incorporate it all, depending on if he's willing... will take slightly longer if not, as I suck. If you want the target to be generated, I can do that too... do you want to specify whether to add target="_blank" or just pick it out from the page (if it's there)?

Incidentally, the code that I've posted up will not copy all the text properly if you have nested tags within the link (i.e. <a href="blah"><i>italic<b>bold and italic</b></i></a>. In this example, only "italic" would be copied. Thankfully, I cant think of an example of this being used, but for sake of completeness, it should probably be a "known issue".
User avatar
sensemann
Posts: 755
Joined: February 6th, 2003, 12:29 pm
Location: Dresden, Germany
Contact:

Post by sensemann »

hehe, should be no problem though - most of the times it's only a normal text node anyways.
i would want to choose the target myself, not pick it from the page btw. for myself i wouldn't moan if this was hardcoded into it, but i doubt everyone using this extension would like that. so it would be best to be able to choose the standard target somewhere in the extension options, if possible.
: sensemann.com :
.:: Extensions :.
.:: Themes :.
Post Reply