71

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.

31
  • 3
    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, 2011 at 18:03
  • 1
    There is no information about this at that README link.
    – Fred Nurk
    May 21, 2011 at 6:16
  • 1
    @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, 2011 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, 2012 at 20:02
  • 1
    @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, 2012 at 19:53
  • 1
    @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, 2012 at 23:31
  • 1
    @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, 2012 at 23:34
  • 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, 2012 at 20:38
  • 2
    @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, 2012 at 21:11
  • 1
    @doncherry Pushed out changes just now, so if you grab the latest you should be good to go. Let me know if you have any other issues.
    – Tim Stone
    Nov 27, 2012 at 16:06
  • 1
    @doncherry I'm indirectly involved with it, I'll take a look.
    – Tim Stone
    Nov 28, 2012 at 1:24
  • 2
    @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, 2014 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. Dec 30, 2014 at 15:48
  • 1
    @SevenSidedDie Have you updated to the latest? If not, someone reported this on GitHub and I fixed it the other day. I need to look into proper updating...will add to the todo list
    – Tim Stone
    Oct 10, 2016 at 19:10
  • 1
    @SevenSidedDie That is a very good point, hahah! I'll add to the updates list here too, thanks!
    – Tim Stone
    Oct 10, 2016 at 19:13

8 Answers 8

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
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.

2
3

With the latest version, a couple recent comments have gotten mangled, leaving garbage text after the title + link.

This may due to a recent change on the SO side (not the script) to allow %hex escapes in URLs instead of discarding strange characters.

e.g. https://stackoverflow.com/questions/60442321/what-does-%D0%A1-semaphoreslim-guarantee-is-it-full-memorybarrier-what-we-can-be-s copies in chromium as that URL, but the %D0%A1 part of the URL doesn't show up in the location bar.

turns into

[What does С# SemaphoreSlim guarantee? Is it full memorybarrier? What we can be sure of code between two different semaphore Wait() and Release()?](https://stackoverflow.com/q/60442321)%D0%A1-semaphoreslim-guarantee-is-it-full-memorybarrier-what-we-can-be-s

So it's correct output with trailing part of the URL not replaced. Probably we just need to include a % as something that the URL regex can match.


You can test this without actually posting a comment by trying to submit a comment that's more than 600 characters. It will do the text replace and then leave the comment textbox open.

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

2
  • Hmm, interesting. Looking into it.
    – Tim Stone
    Sep 23, 2012 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, 2012 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)) {
    
3
  • 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. Jan 22, 2019 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). Jan 22, 2019 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. Jan 22, 2019 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?

2
  • The latest update of the script made this change anyway, so this is completed. But IIRC, this might have already been fixed by Stack Overflow some time ago so //site/q/... links do get picked up. (I might have mixed this up in my memory; I think I had manually changed my local copy of the script because of this, but later changed it back or let a previous update use // instead of https://.) Mar 3, 2020 at 0:04
  • On further testing, it looks like // links do get linked, but don't update the page right away after posting a comment + refreshing. Maybe it takes an overnight reprocess of changed pages for the link to show up in that case. Mar 9, 2020 at 3:20
0

Escaped right brackets \] cause over-enthusiastic link conversion

Just ran into this when trying to use escaped square brackets \[...\] inside the link text of a link in a comment. The link helper script doesn't respect that the right bracket is escaped, and treats the link as if it's bare and should be converted.

Comments with only an escaped left bracket \[ are unaffected.

Repro steps:

  1. Enter a comment with at least one escaped right bracket \] in the link text:
  • [this is a \[test\]](https://stackapps.com/questions/2378/se-comment-link-helper)
    
  1. Post the comment; link will be converted by the script into the following:
  • [this is a \[test\]]([SE Comment Link Helper](https://stackapps.com/q/2378))
    

    Which renders as:

    [this is a [test]](SE Comment Link Helper)

Desired/ expected behavior:

  • No conversion, resulting in rendering the original Markdown:

this is a [test]

0

You must log in to answer this question.

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