Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?
 
PerlMonks  

Monk Links - Copy Perlmonks-links to the clipboard in on-site-format

by holli (Monsignor)
on Mar 06, 2005 at 04:56 UTC ( #436993=perlmeditation: print w/ replies, xml ) Need Help??

Fellow monks,

I just have created an extension for Firefox called Monk Links. It creates a new context menu entry (Copy link as PM shortcut) that copies links from perlmonks.org, perlmonks.com or perlmonks.thepen.com to the clipboard while transforming it to the internal site format.

For example, if you invoke the context menu on a link like

http://www.perlmonks.org/?node_id=12345,

and choose Copy link as PM shortcut, the text

[id://12345]

will end up in your system's clipboard.

Then you can easily paste it wherever you want. In your article, the CB, etc.

Tested on WindowsXP and Firefox 1.0 only. Let me know if it does not work for your system.

download version 0.2
download version 0.3

Caveat:
To install you need to save the xpi-file to disk and then do
File->open file->open monklinks.xpi
That is because the perlmonk-server does not send the correct mime-type for the xpi-file. I'll contact jcwren to fix that.


You also have to restart Firefox after the install to make it work (just as with any other extension).

Update:
Added support for perlmonks.com, www is now optional.

Update:
Added .htaccess file as adviced by The Mad Hatter

Update:
Added version 0.3 that copes with cpan:// and kobes:// links and links from perlmonks.thepen.org.

Update:
bart has made various upgrades to the extension. However, there's still the version problem. In barts version runs only till FF 2.0. To get it run a in higher version do the following:
  • Download the .xpi-file
  • Rename it to .zip
  • Extract the file install.rdf
  • edit the file and replace <em:maxVersion>2.0</em:maxVersion> with the version of your FF
  • put the file back in the .zip
  • rename the .zip file back .xpi
  • install the extension


holli, /regexed monk/

Comment on Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
Select or Download Code
Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by gaal (Parson) on Mar 06, 2005 at 06:55 UTC
    Good stuff!

    Suggestion: make the regexp more lenient towards the PM base URL. I use http://perlmonks.org/, and I know for a fact that some other monks use http://www.perlmonks.com/ — this is exactly the reason we prefer [id://] in the first place!

    So your monklinksOverlay.js needs a change, at least. (Maybe other files too, and sorry I'm not sending a patch, I'm on a machines with limited dev fu.)

Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by data64 (Chaplain) on Mar 06, 2005 at 15:26 UTC

    Nice idea.

    Is this Firefox specific or will it work on Mozilla Suite as well ?

      installed on Moz 1.4x under w2k. Runs fine!
      ++ Holli!
Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by The Mad Hatter (Priest) on Mar 06, 2005 at 16:07 UTC
    To get Apache to report the correct MIME type, add this line to a .htaccess file where the XPI is:
    AddType application/x-xpinstall .xpi
    (And make sure the .htaccess is readable by all, or at least the webserver process.)
Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by Tanktalus (Canon) on Mar 06, 2005 at 20:36 UTC

    It took me a bit to realise what you were doing. Especially since I don't know anything about XPIs, Javascript, or XULs.

    First off, I want to say that I have it working (finally) on Firefox on Linux. So there should be some good news there - it's been tested on non-Windows :-)

    Secondly, "invoking" is not entirely clear to me. So I want to expand on how it's working for me, which I presume is how it's working for everyone else.

    Basically, you must right-click on an actual href anchor link, aka, <a href="http://(?:www)\.perlmonks\.(?:com|org)"> in HTML. The actual text above, "http://www.perlmonks.org/?node_id=12345", doesn't quite cut it, as I erroneously inferred. Thus, right-click here. Of course, if you're using a left-handed mouse, left-click there. Whatever. ;-) Then one of the options will be "make PM-link". Select that, obviously. Note that, at least here, it's not coming up with a keyboard shortcut (no letter is underlined).

    What would be cool for extentions, holli, is if you did likewise for perldoc, doc, and cpan links. :-) Of course, isn't it always the case - start off with something simple and cool, and everyone wants to add stuff to make it ugly and bloated ;-} Regardless of whether you do this or not, I've got this version installed. Thank you!

      Ah, it seems I am not very good at writing documentations.
      What would be cool for extentions, holli, is if you did likewise for perldoc, doc, and cpan links.
      Actually I have a new version ready that works for cpan://* and kobes://* links, but there is a ugly bug. The entity %3A (double colon) gets not correctly decoded by the decodeURI function. I am trying to figure out why.

      As for the perldoc, I will add that when I am sure the currently selected perldoc site will not change.


      holli, /regexed monk/
        As a quick hack, you could do decodeURI(s).replace('%3a',':');.
        That might be because decodeURI is a complement to encodeURI which encodes non-valid entities. : is avalid entity in a URI

        --
        In Bob We Trust, All Others Bring Data.

        decodeURI "does not decode escape sequences that could not have been introduced by encodeURI."

        In other words, decodeURI won't return an invalid URI, like decoding %3A does or could do. You can't safely decode an entire URI. Each path segment, each attribute key and each attribute value must be isolated before they can be decoded. For example http%3A//www.google.com/ (a relative URI) and http://www.google.com/ (an absolute URI) are not equivalent.

        Not what you want:

        decodeURI("http://search.cpan.org/search?mode=module&query=XML%3A%3APa +rser")

        What you want:

        decodeURIComponent("XML%3A%3AParser")

        Since your code already extracts the compenent, simply use

        clickedLink = "[cpan://" + decodeURIComponent(array[1]) + "]";
Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by holli (Monsignor) on Dec 30, 2005 at 18:08 UTC
    It turned out the extension is not compatible with Firefox 1.5 (credits to Tanktalus for pointing me at it). I have just updated it, so it's now version 0.5. Unfortunately, I have no own webspace at the moment (perlmonk.org is down), so I put it on planetscape's server (thank you honey) in the meantime. Get it here.


    holli, /regexed monk/
      Apart from the bugs that you have tried to patch up earlier, kwaping found another link that didn't work well in your current FF extension: Voting/Experience System. So I took the plunge and looked at how it all ticked...

      I found out you were using the wrong function, you shouldn't have used decodeURI(), but unescape()!

      There still is a bug in FF though, because when testing Javascript using alert(), both in the extension and from the Javascript Console command line, I found that it was partially decoding the string, and thus, what alert() showed wasn't the original string, but a partly decoded variation of it.

      Anyway, unescape() fixed it, and I could just completely remove your kludge.

      Get the patched version at http://users.pandora.be/bartl/monklinks/. There are two archives: the patched XPI file, and a ZIP archive containing the same files but unpacked, ready for editing, plus a little Windows batch script (just run it by doubleclicking) to wrap up the files, possibly after editing, back into a new XPI file. You need an Info-ZIP compatible command line ZIP, which comes with UnxUtils, for example.

      BTW people, if you're having trouble installing the XPI file directly from the site, just save it to disk and drop it on Firefox, either on a window, or on its program icon.

      Ah, another feature I added was support for plain links, which get turned into the [http://...|link text] format, taking care to remove any "[", "]" and "|" characters from the text.

      Oh, and I moved its position in the popupmenu to a more appropriate place, right under the "Copy Link Location" item.

      I've got a few more ideas still, like adding support for other types of PM links, such as to http://perldoc.org/, as well as copying the URL and title (or perhaps selected text) of the current page in case you rightclicked on something other than a link — thus, something like Copy URL + does. The latter seems like a big change to me, so it will be for another day. Ideally, it should still work after you submitted a POST, so, in that case, it should scan for the node id in the current page.

      I left your copyright and author notices completely unaltered, I just bumped the version number from 0.3 to 0.3.1. It's still your baby.

      p.s. I don't have Firefox 2 as yet, so it's not compatible with it yet. Feel free to try if it could still work, by editing install.rdf in the root dir, and bumping up the <em:maxVersion> value, and repackage.

      p.p.s. I started out from the version you put up on planetscape's site. You say here it's version 0.5, though internally, everything said 0.3. Oh well.

      Update Now version 0.3.2, supports more link styles: module:// and dist:// for CPAN, doc:// for perldoc.perl.org, href:// for odd links on this site, and plain http:// for anything else. It'll try to uyse the actual link text for the less normalized URLs (the latter two). And I've upped the maxVersion to 2.0, though I haven't tried it, I have the impression not much has changed in the Firefox Extension API. Here's for hoping.

      Same URL for the directory listing.

        Update Now version 0.3.2, supports more link styles: module:// and dist:// for CPAN, doc:// for perldoc.perl.org, href:// for odd links on this site, and plain http:// for anything else. It'll try to uyse the actual link text for the less normalized URLs (the latter two). And I've upped the maxVersion to 2.0, though I haven't tried it, I have the impression not much has changed in the Firefox Extension API. Here's for hoping.

        Tested for some time now on 2.0 and seems to work like a charm. Thank you!

Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by Tanktalus (Canon) on Oct 25, 2006 at 00:06 UTC

    holli,

    You can probably guess what I'm going to ask about... ;-) Firefox 2.0 is out. And monklinks doesn't work... probably just a compatibility flag... is there an update available? ;-)

    (Monklinks is actually a primary reason I still use firefox instead of going to Konqueror or some other browser, especially when using Perlmonks!)

      Well the idea is simple. You could consider to write the same for your favorite browser? Anyway, I will have a look at the issue next week. This weeks is to busy.

      regards,


      holli, /regexed monk/
Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by davido (Archbishop) on Nov 02, 2006 at 06:00 UTC

    At least for currently visible top node, if you modify your "Custom Node Title Definition" in Display Settings, you can add the following: "%T: %N" (as I do), so that whatever node you're looking at will display its name and title in your browser's title bar (and in my case, in the page's Firefox tab)

    If I have multiple Firefox tabs pointing to multiple pages, each tab will have the node name, and the node ID displayed on the tab itself. Very handy! If I'm discussing several nodes in one of my posts, I usually just open those nodes in separate tabs so that I can quickly see the node ID's.

    Available tokens are %T (title), %D (create date), %N (node id), and %S (section; e.g. SOPW, Q&A, but only for root nodes).


    Dave

Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by sabari (Beadle) on Jun 28, 2007 at 06:45 UTC
    Dear Member, when i was trying to install it says error. Details, Webbrowser:Firefox 1.5.0.4 OS:Linux (Debian).
    Best Regards, S.Sabarinathan,
      One of the various versions should run with Firefox 1.5. Kill me if I know which one. If it doesnt't, get a fresh Firefox.


      holli, /regexed monk/
Re: Monk Links - Copy Perlmonks-links to the clipboard in on-site-format
by naikonta (Curate) on Jun 28, 2007 at 08:38 UTC
    Wow, I just found this, and I'd really like to have it, but when I tried to install from the links (0.3) above, I got error in the message box saying (it might not be the exact words because I couldn't copy-paste):
    "Monk Links!" could not be installed because of an error in its Instal +l Manifest ("{9AA4XSF-1002-4c06-97AF-5035170633FX}" is not a valid GU +ID). Please contact the author of this item about the problem.

    So I downloaded it manually and executes the steps you explain in update (except that I didn't have to rename it to .zip), put it on my local server, set the AddType directive in .htaccess. And I got the same error as above :( Any alternative or workaround? Thanks for providing this, although not working for me (yet).

    Info: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/2006120814 Firefox/2.0.0.1


    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

      This is the same bug as described here. Get version 0.5 or higher. The latest version is the one with bart's modifications.


      holli, /regexed monk/

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://436993]
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2014-04-19 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls