3

1. Request

It would be nice, if will be script for share short links to comments on Stack Exchange sites, not long links.


2. Justification

I found out, that links to comments may be short. For example,

is the same link as

Second link is more preferred because:

  1. Some web forms has a limit the number of characters.

3. Desirable behavior

I open any page of any Stack Exchange site → near each comment I saw link, for example, clipboard → I click to clipboard → short link to comment will be transfer to my clipboard.

0
1

Here is a Greasemonkey/Tampermonkey script that should work. It is untested and unhosted at the moment. :

// ==UserScript==
// @name        Stack Exchange, Comment cleanup
// @description See stackapps.com/questions/7202/
// @match       *://*.askubuntu.com/questions/*
// @match       *://*.mathoverflow.net/questions/*
// @match       *://*.serverfault.com/questions/*
// @match       *://*.stackapps.com/questions/*
// @match       *://*.stackexchange.com/questions/*
// @match       *://*.stackoverflow.com/questions/*
// @match       *://*.superuser.com/questions/*
// @exclude     *://api.stackexchange.com/*
// @exclude     *://data.stackexchange.com/*
// @exclude     *://blog.stackexchange.com/*
// @exclude     *://blog.stackoverflow.com/*
// @exclude     *://chat.stackexchange.com/*
// @exclude     *://chat.stackoverflow.com/*
// @exclude     *://elections.stackexchange.com/*
// @exclude     *://openid.stackexchange.com/*
// @exclude     *://stackexchange.com/*
// @exclude     *://*/review
// @require     http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant       GM_addStyle
// @version     0.5
// @history     0.5 Initial release, untested
// ==/UserScript==

waitForKeyElements ("a.comment-link", useShortLinkFormat);

function useShortLinkFormat (jNode) {
    var oldHref     = jNode.attr ("href");
    var commentNum  = oldHref.match (/.+?comment(\d+).+/);
    if (commentNum  &&  commentNum.length > 1) {
        var commentNum = commentNum[1];
        jNode.attr ("href", '/posts/comments/' + commentNum)
        jNode.append ('<small> sl</small>')
    }
}
4
  • Brock Adams, thanks for a script! If I hover my mouse to sl, I see short link. But if I click to sl, page reload for me, but short link not transfer to my clipboard. Windows 64-bit EN, Firefox 51.0.1. Thanks. Feb 4 '17 at 4:58
  • 1
    @СашаЧерных, Sorry, I slapped that script together quickly and forgot about your clipboard wish. Until I add it, you can right-click the link and select Copy Link Location to get it to the clipboard. ... Meanwhile, let me know if there are other issues. Feb 4 '17 at 5:07
  • @BrockAdams I recommend searching on google copy to clibpoard javascript and you will find some code to copy to clipboard. May 9 '19 at 14:18
  • Thanks, @smileycreations15. But I stopped work on this script because I had a plethora of higher priorities and because it appears to be of no interest to anyone outside the OP. I'll probably revisit it now, though just for the sake of completeness. May 9 '19 at 14:27

You must log in to answer this question.

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