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.

Tim Stone
  • 4,686
  • 3
  • 22
  • 32
  • 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 01 '11 at 18:03
  • 1
    There is no information about this at that README link. – Fred Nurk May 21 '11 at 06: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 '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
  • 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 '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: http://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 'SO- stop being evil' Jul 25 '12 at 23:22
  • 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 '12 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 '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 'SO- stop being evil' 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
  • 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 '12 at 21:11
  • @TimStone No problem, I'm glad it'll be working again, thanks for your work! – doncherry Nov 26 '12 at 21:36
  • 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 '12 at 16:06
  • @TimStone http://stackapps.com/questions/2378/se-comment-link-helper works, thanks :). Are you also involved with SEReputationAuditHelper.user.js? That only works on [so], but on none of the other sites I'm registered at, even though it is supposed to act on all of them. – doncherry Nov 28 '12 at 01:18
  • 1
    @doncherry I'm indirectly involved with it, I'll take a look. – Tim Stone Nov 28 '12 at 01:24
  • @TimStone: I see API quota throttling a lot more lately, perhaps because I also started using this script from time to time. – Martijn Pieters Nov 14 '13 at 15:42
  • Stackoverflow finally seems to support https, but your script is hardcoded for http://. – Martin Schröder Jan 05 '14 at 11:13
  • 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 05 '14 at 15:39
  • I think (but I’m not entirely certain) that this script has an issue with comment links which refer to different SE sites. Is this possible? Exhibit A: I couldn’t post the comment at http://stackoverflow.com/q/27707987/1968 without first disabling the plugin. – Konrad Rudolph Dec 30 '14 at 15:33
  • @KonradRudolph Hmm, it shouldn't, but I'll test. Even in a worst-case scenario it shouldn't prevent the comment, so I'll make sure that's handled correctly too. – Tim Stone Dec 30 '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
  • How can I install this script? I clicked the install/update link but it just displays the js file – phuclv Jan 31 '15 at 09:18
  • @LưuVĩnhPhúc: You should have User Scripts extension installed on your browser – Michael Freidgeim Jan 30 '16 at 12:12
  • This script appears to have been broken recently; from the timing I suspect by SE's recent jQuery update: http://meta.stackexchange.com/questions/284996/we-have-updated-jquery-to-1-12-4-please-report-related-bugs-here (See? I shouldn't be able to post a bare link like that. ;) – SevenSidedDie Oct 10 '16 at 19:09
  • 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 '16 at 19:10
  • @TimStone I looked for an update here first in the post text and didn't see one, so no. I will update now, thanks! – SevenSidedDie Oct 10 '16 at 19:11
  • 1
    @SevenSidedDie That is a very good point, hahah! I'll add to the updates list here too, thanks! – Tim Stone Oct 10 '16 at 19:13
  • [a-z]+=1 should be ([a-z]+=1)(&[a-z]+=1)* or something like that. Linked posts are ?noredirect=1&lq=1, which doesn't work with the former. – NotThatGuy Oct 17 '17 at 18:18
  • Hello, Tim Stone. The repository doesn't contain any open-source licensing information, which means others just can't legitimately use the code. Would you mind adding one? MIT and Apache 2.0 are good ones to start with. – iBug Dec 08 '18 at 10:02

8 Answers8

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.

Gaurang Tandon
  • 537
  • 3
  • 13
Kevin Vermeer
  • 251
  • 2
  • 6
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:

Gaurang Tandon
  • 537
  • 3
  • 13
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.

Glorfindel
  • 6,772
  • 3
  • 20
  • 46
Peter Cordes
  • 131
  • 3
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

Martijn Pieters
  • 901
  • 7
  • 17
  • Hmm, interesting. Looking into it. – Tim Stone Sep 23 '12 at 01: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 03: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?

Gaurang Tandon
  • 537
  • 3
  • 13
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)) {
    
robe007
  • 109
  • 2
  • 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 '19 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 '19 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 '19 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?

Rubiksmoose
  • 101
  • 3
  • 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://.) – Peter Cordes Mar 03 '20 at 00: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. – Peter Cordes Mar 09 '20 at 03: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]

zcoop98
  • 141
  • 6