66

About

This userscript automatically converts raw Stack Exchange question URLs into the form [title](link) before submitting comments by grabbing their titles from the API. This is similar to conversion done natively on posts, and is in response to this Meta request. The script also tries to shorten links where appropriate, stripping out unnecessary URL content to conserve comment characters.

More information can be found in the SECommentLinkHelper section of the README.

Download

Install / Update the script   (See the script tag-wiki for installation help.)
View the source

Updates

  • 2012-12-08: Thanks to feedback from doncherry, various parsing issues are now corrected. Of note is inclusion of proper support for conversion of comment links and /a/### short-form links.
  • 2014-01-05: The script will now run under HTTPS, and will correctly handle HTTPS links.
  • 2016-09-28: Updated to resolve issue with new jQuery version, switched to use schemeless-links to save characters/be friendly to users using different schemes

Platform

The script should work under all major userscript-supporting browsers. Please file a bug if you encounter any issues.

Contact

Tim Stone actively maintains this script.

Feedback can be given on GitHub, or by "@lerting" the maintainer on Meta Stack Exchange chat.

Code

To fork the code, please visit the GitHub repository.

  • 2
    Note: The script doesn't use an API key at the moment, so I'll need to fix that in the near future. – Tim Stone May 1 '11 at 18:03
  • 1
    There is no information about this at that README link. – Fred Nurk May 21 '11 at 6:16
  • @FredNurk Ah, I forgot to regenerate the HTML from the actual README document. Sorry about that, I'll make sure that gets updated later this evening. – Tim Stone May 23 '11 at 22:41
  • @TimStone: Love the script! Could you implement an option to append the urls with one's user account number so that links contribute towards the Announcer etc. badges? So instead of having x.stackexchange.com/q/31415, it'd be x.stackexchange.com/q/31415/4746 (4746 being your user account number for stackapps). – doncherry Jul 10 '12 at 20:02
  • @doncherry Thanks! You don't receive credit if the link was clicked inside of the Stack Exchange network anyway (as would be the case with comments), which is why it removes the referral slug. – Tim Stone Jul 11 '12 at 19:53
  • @TimStone: I didn't know that! Then my proposal is void, of course. Thanks for letting me know. – doncherry Jul 11 '12 at 20:43
  • Since today (I think), this doesn't work for me any more: stackapps.com/questions/2378/comment-link-autoprettifier I've been using Chrome 20.0.1132.57 for weeks, it used to work in this exact browser version. Is there anything I can do to trace why links in comments are no longer prettified? – Gilles Jul 25 '12 at 23:22
  • @Gilles Hmm...it seems to still be working for me, so I don't suspect anything changed on the sites...Are there are any error messages in the console? It looks like I never got around to registering for an API key for this script (I've now made a note to do so), so there's a very small chance you've exceeded the anonymous API quota somehow, I suppose. – Tim Stone Jul 25 '12 at 23:31
  • @Gilles Oh, and if you have SE Modifications -- Username autocomplete in comments, inline revision source, and utility links installed, it was causing an error as a result of this change that may impact the setup for this script. I've patched that issue now, so be sure to update to the latest version if applicable. – Tim Stone Jul 25 '12 at 23:34
  • @TimStone I do have SE modifications. Updating Comment Link AutoPrettifier to the version you just uploaded makes it work. Thanks! – Gilles Jul 25 '12 at 23:39
  • @TimStone The script hasn't been working for several weeks, if not months. I'm using Firefox 17 on Win, and I just reinstalled the script. Is this expected? Can I provide any more helpful information? (Also, it is confusing that the titles of this StackApp and of the UserScript don't match.) – doncherry Nov 26 '12 at 20:32
  • 1
    @doncherry Hmm, I haven't had any issue in Chrome, but let me check Firefox and get back to you if I need more info. As far as the title goes, I'll take care of that, sorry about the confusion! – Tim Stone Nov 26 '12 at 20:38
  • 1
    @doncherry Ah...apparently this is an issue with Firefox and jQuery's handling of a change I made two months ago that neither side seems inclined to fix. Looks like I can work around it, so I'll do that when I get home today. Sorry for the inconvenience, and I'll make sure that next time I test thoroughly in Firefox. – Tim Stone Nov 26 '12 at 21:11
  • 1
    @MartinSchröder HTTPS isn't officially supported by the Stack Exchange network yet, but I've updated the script to work with it now regardless. Thanks for pointing that out! – Tim Stone Jan 5 '14 at 15:39
  • 1
    @Tim So what’s happening is that the first click on “Add comment” or “return” is discarded, and hitting the button/key again appears to submit the form, but no comment is posted. – Konrad Rudolph Dec 30 '14 at 15:48
3

Links to StackExchange sites' meta posts don't seem to work. When I first hit Enter/click "Add Comment", the page doesn't do anything at all. The second hit forces a page reload, which is unexpected behavior.

I'll post a comment below with these meta posts:

3


When you post a link in inline code, like

The URL `http://electronics.stackexchange.com/q/33477`

the link is rendered as

The URL `[What is the SoC on the ARM9 board TS-7800?](http://electronics.stackexchange.com/q/33477 )`

What should happen is that any URL in inline code should be ignored.

Additionally, links like [http://electronics.stackexchange.com/q/33478](http://electronics.stackexchange.com/q/33478) should use the text http://electronics.stackexchange.com/q/33478 as the name of the URL, rather than adding another layer of Markdown.

Accidentally published this on MSO here, I've gotten so used to this script that I thought it was native until I had to do this admittedly unusual task.

1

Bug report: this script doesn't work

I was in the first posts review queue. I made an edit then attempted to leave a comment.

I saw my browser being redirected to https://patents.stackexchange.com/review-beta/first-posts/328?comment=Patent+%5Btag%3Aus7864163%5D+was+already+discussed+in+a+previous+question%3A+http%3A%2F%2Fpatents.stackexchange.com%2Fquestions%2F260%2Fprior-art-for-double-tap-to-zoom-in-a-structured-document-web-browser for a few seconds, then was brought back to https://patents.stackexchange.com/review-beta/first-posts/328 . Reloading the page, or opening https://patents.stackexchange.com/review-beta/first-posts/328 in a different tab, caused the same behavior. My comment wasn't posted.

I tried with the latest version of the code fresh from https://github.com/rchern/StackExchangeScripts/raw/master/SECommentLinkHelper.user.js as of a few minutes ago. After disabling this extension, or if I removed the naked URL to another post on the same site, I could post the comment.

Browser: Chrome stable 21.0.1180.89

  • Hmm, interesting. Looking into it. – Tim Stone Sep 23 '12 at 1:37
  • 1
    Patents doesn't have a legacy API, so the script broke there. I've updated the script to use API 2.1, which should fix the problem. Let me know if you continue to experience issues after updating. – Tim Stone Sep 23 '12 at 3:00
0

I understand that an an http request has to be made to fetch the title of the post of the corresponding URL. I've seen that this request is made after I submit a comment, resulting in a delay of nearly two seconds before the comment is actually posted. (possibly only 1sec on faster networks, but a delay nonetheless)

I suggest that instead of fetching the title after comment submit, the script should fetch it as soon as a URL is typed. The idea is to have a setInterval running every 500ms, checking for a new StackExchange URL, as soon as one is found, fetch its title and keep it ready in the background. As soon as the user hits Enter, simply replace the url with the pre-fetched title.

I think this wouldn't have any major performance overhead, considering that most of the links a user puts in their comment, end up being posted as well.

Thoughts?

0

I have tested the script, and does not works.

  • It redirects to same as Gilles said on a post above. After redirects no comment is showed.

  • And also the script has problem on line 60:

    while (url = link.exec(comment)) {
    

    should be:

    while (url == link.exec(comment)) {
    
  • The while (url = link.exec(comment)) { line is entirely correct, it is not an equality test, the loop continues while the link.exec() method returns a non-empty result, which is also assigned to the url variable. That's the whole point. – Martijn Pieters Jan 22 at 16:42
  • Next, the issue Gilles reported was corrected in September 2012, you seem to have a different issue here. The comment-link helper needs to call out to the API to retrieve titles, perhaps that's timing out for you locally (can happen if you have an unreliable network connection sometimes). – Martijn Pieters Jan 22 at 16:44
  • Last but certainly not least: as the post notes, feedback such as bug reports should be posted on Github or in the linked chatroom. – Martijn Pieters Jan 22 at 16:45
0

Links do not show up in "Linked" sidebar

If you change your script from formatting the link as //site.stackechange.com to https://site.stackechange.com it seems the parser is able to pick them up though. Consider making that change?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .