What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 130 Stack Exchange communities.

I just tried to link some comment from the election page only to find out there is no link on the timestamp.

Is this by design? If so: can this be reconsidered. Sometimes I want to link to comments in chat which is not easy to do now.

To make my question a bit less dupe. The comments once linked by doing heavy manual labor (looking up the id in the DOM) also don't onebox in chat.

share|improve this question
    
Also, clicking the link button on the post actually opens the link, rather than the fancy copy-paste box like we all expect. Sad pandas are sad! –  animuson Feb 25 '13 at 22:50
    
Crap :( As always I see a dupe once I've posted my question. I have searched and I have glanced the dupe list when entering my title. Really... :) –  PeeHaa Feb 25 '13 at 22:50
    
And meta.stackexchange.com/questions/135225/… –  Bart Feb 25 '13 at 22:55
1  
Yesyesyes. Was going to post my own feature request for this. Comment permalinking is a somewhat new feature, but there's no place where it makes more sense than the elections page. There's tons of comments there -- the feature is basically overloaded to be used as a forum thread. –  Josh Caswell Feb 26 '13 at 6:31
    
@Oded - The status is completed now! –  hims056 Sep 20 '13 at 11:33

3 Answers 3

Not yet thoroughly tested. I confirm that it supports the case of loading more comment, and it should also support posting/deleting comment.

I have made some updates since my first revision to fix some bugs.

This is currently Revision 3

// ==UserScript==
// @name           Timestamp in Election comment
// @namespace      nhahtdh
// @include        http://stackoverflow.com/election*
// @grant          metadata
// @author         nhahtdh

function with_jquery(f) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.textContent = "(" + f.toString() + ")(jQuery)";
    document.body.appendChild(script);
};

with_jquery(function ($) {
    function addCommentLink(ref) {
        $('.comment', ref).each(function () {
            $('.comment-date > .relativetime-clean', this).wrapAll($('<a href="' + '#' + this.id + '"></a>'));
        });
    }

    addCommentLink(document);

    $(document).ajaxComplete(function (e, xhr, settings) {
        if (/\/comments/.test(settings.url)) {
            addCommentLink(document);
        }
    });
});
share|improve this answer

You can construct a URL that will point to a comment.

All you need is to take a look at the id of the actual comment -

http://stackoverflow.com/election/4?#comment-21205321
-------------------------------------------^

It's not too comfortable, and a little hacky... but it works never-the-less!

share|improve this answer
    
I know I can look it up in the DOM (that's the part about not be easy). I should have added that in my question. Sorry that I suck at this :( –  PeeHaa Feb 25 '13 at 22:52
2  
I smell a userscript brewing ;) –  Lix Feb 25 '13 at 22:53
    
@PeeHaa - Nothing feels better than finding someone else has already done your work ;) –  Lix Feb 25 '13 at 23:00
    
Why are you referring to me as pee. That's very offensive! Especially bad when you are running for mod! Flagged! ;) –  PeeHaa Feb 25 '13 at 23:03
    
@PeeHaa - sorry for that.. I'm used to using the minimum 3 character @ replies... –  Lix Feb 25 '13 at 23:04
    
Also it seems that Manishearth's script doesn't work any more... –  Lix Feb 25 '13 at 23:05
2  
That's ok. I forgive you :-) Would be nice if this would be "fixed" though at some point imho (the functionality I mean although a userscript could be a temporary solution). –  PeeHaa Feb 25 '13 at 23:09
2  
@Lix It works, but only on the visible comments. Doesn't work on comments that show up after you click "add / show n more comments". –  Yannis Feb 25 '13 at 23:24

Put your hands in the air like you just don't care (for such crass abstractions as jQuery)

Edit: slight improvement to expando link callback to prevent multiple calls and wait until all additional comments have been loaded

// ==UserScript==
// @name Election comment linkifier
// @description Linkify comment timestamps in SO moderator election
// @version 1.0
// @author DaveRandom
// @namespace https://github.com/DaveRandom
// @match http://stackoverflow.com/election/*
// ==/UserScript==

(function() {

  function addLinksToUnprocessedPosts() {
    var i, l, linkSpan, linkText, anchorElement,
        comments = document.querySelectorAll('tr[id^=comment-]:not(.linkmaker-processed)');

    pending = false;

    for (i = 0, l = comments.length; i < l; i++) {
      linkSpan = comments[i].querySelector('span.comment-date span');
      linkText = linkSpan.firstChild;
      linkSpan.removeChild(linkText);

      anchorElement = document.createElement('a');
      anchorElement.href = '#' + comments[i].id;
      anchorElement.appendChild(linkText);

      linkSpan.appendChild(anchorElement);

      comments[i].className += ' linkmaker-processed';
    }
  }
  addLinksToUnprocessedPosts();

  var i, l, pending = false,
      expandoLinks = document.querySelectorAll('.comments-link');
  for (i = 0, l = expandoLinks.length; i < l; i++) {
    expandoLinks[i].parentNode.querySelector('tbody').addEventListener('DOMNodeInserted', function(e) {
      if (e.srcElement.nodeType === 1 && e.srcElement.tagName.toLowerCase() === 'tr' && !pending) {
        pending = true;
        setTimeout(addLinksToUnprocessedPosts, 0);
      }
    });
  }

}());

Tested in a real browser (Google Chrome), but I suppose if you must you may sully my fine craftsmanship by using it in that other one...

share|improve this answer
1  
Good guy Dave strikes again! –  PeeHaa Feb 26 '13 at 0:09
    
DOMNodeInserted event is deprecated, at least according to MDN –  nhahtdh Feb 26 '13 at 0:15
2  
@nhahtdh Indeed it is, and for very good reasons. However the main problem is with bubbling - not too much of a problem because the node(s) I attached it to have very few child nodes and they don't really change apart from when you click the link. The alternative (mutation observers) is, however, a lot more of a pita to work with. I agreed it's not an ideal mechanism but the other option - without resorting to jQuery - was to poll the DOM for completion which is even more horrible (IMO). Side note: the way in which the SE code deals with adding the extra posts to the DOM is very inefficient. –  David X. Random Feb 26 '13 at 0:24
    
@DavidX.Random: +1 for a great comment. I don't code web-related stuffs much, so this is great insight. –  nhahtdh Feb 26 '13 at 0:28
2  
@nhahtdh In a couple of years (hopefully) MutationObserver will be the way to do things like this but at the moment it is only supported in Chrome and Firefox, and in Chrome it uses a non-standard name (Webkit prefix). Mutation events are very inefficient on the DOM (especially in Firefox) which is why they have been deprecated but for real-world applications where cross browser support is required, i.e. not little overlays like this, unfortunately you are stuck with them at the moment. I started work on an observer abstraction with fallback to events a while ago, but it doesn't work yet. –  David X. Random Feb 26 '13 at 0:36

You must log in to answer this question.

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