Skip to main content
v1.1c
Source Link
brasofilo
  • 992
  • 7
  • 22

I've made a couple of fixes to make this work again, it does, but produces. While I don't fork and ask for a strange error on Stack Exchange's codemerge, in the replace bellow:

//This is where the real work starts - add the 'auto' link next to each comment 'help' link
//use most local root-nodes possible (have to exist on page load) - #questions is for review pages
$("#content").delegate(".comments-link", "click", function () {
  var divid = $(this).attr('id').replace('-link', '');

I'll leavehere it is a copy of my script for convenience, the modifications are indicated with comments:. The matches of sites has been revised as well.

// ==UserScript==
// @name           stackoverflow-comment-reply
// @namespace      stackoverflowstackapps
// @description    Add "reply" links to comments
// @version        1.1b1c
// @match          *://stackoverflow.com/*
// @match          *://serverfault.com/*
// @match          *://superuseraskubuntu.com/*
// @match          *://meta*.stackoverflowmathoverflow.comnet/*
// @match          *://meta*.serverfault.com/*
// @match          *://meta.superuser.com/*
// @match          *://.stackapps.com/*
// @match          *://*.stackexchange.com/*
// @match          *://askubuntu.com/*
// @match          *://meta.askubuntustackoverflow.com/*
// @match          *://answers*.onstartupssuperuser.com/*
// @match          *://meta.answersarea51.onstartupsstackexchange.com/proposals/*
// @match@author         Benjamin *:Dumke-von der Ehe
//mathoverflow.net ==/*UserScript==
/ 
/* @matchMOD: don't run if not SE and user not logged in *://area51.stackexchange.com/proposals/*
// @author     if (!window.StackExchange || window.StackExchange.options.user.isAnonymous Benjamin)
 Dumke-von der Ehe
// ==/UserScript==return;

// Thanks to Shog9 for this idea for making the script work in both
// Chrome and Firefox:
// http://meta.stackoverflow.com/questions/46562
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($) {
        
    $(document).ajaxComplete(function(){
        setTimeout(function () {
            $(".comments").each(put_reply_links);
        }, 100);
    });
        
    // event handler for a click on the reply links
    function reply() {
        /* MOD: changed the following 2 lines to detect the new Add Comment link */
        var commentlinkId = $(this).closest(".comments").next().attr("id");
        var commentlink = $('#'+commentlinkId + ' a.js-add-link')[0].click();
        var username = goodify($(this).prev().text().replace(/♦/, ""))
        var formid = commentlinkId.replace(/^.*-(\d+)$/, "add-comment-$1");
        var ta = $("#" + formid + " textarea")[0];
        var start = ta.selectionStart;
        var end = ta.selectionEnd;
        var shift = username.length + 3;
        ta.value = "@" + username + ": " + ta.value;
        ta.focus();
        ta.selectionStart = start + shift;
        ta.selectionEnd = end + shift;
    };

    function put_reply_links() {
        $(this).find(".comment:not(:has(.reply-link)) .comment-user").each(function () {
            /* MOD: // changed click by on(click) */
            $("<span class='reply-link' style='cursor:pointer;'pointer;opacity:0.3' title='reply'> &crarr;</span>").on('click',reply).insertAfter(this); 
        });
    }
            
    $(".comments").each(put_reply_links);
    
    function goodify(s) {
        return s.replace(/ +/g, "");
    }   
});

I've made a couple of fixes to make this work again, it does, but produces a strange error on Stack Exchange's code, in the replace bellow:

//This is where the real work starts - add the 'auto' link next to each comment 'help' link
//use most local root-nodes possible (have to exist on page load) - #questions is for review pages
$("#content").delegate(".comments-link", "click", function () {
  var divid = $(this).attr('id').replace('-link', '');

I'll leave a copy of my script for convenience, the modifications are indicated with comments:

// ==UserScript==
// @name           stackoverflow-comment-reply
// @namespace      stackoverflow
// @description    Add "reply" links to comments
// @version        1.1b
// @match          *://stackoverflow.com/*
// @match          *://serverfault.com/*
// @match          *://superuser.com/*
// @match          *://meta.stackoverflow.com/*
// @match          *://meta.serverfault.com/*
// @match          *://meta.superuser.com/*
// @match          *://stackapps.com/*
// @match          *://*.stackexchange.com/*
// @match          *://askubuntu.com/*
// @match          *://meta.askubuntu.com/*
// @match          *://answers.onstartups.com/*
// @match          *://meta.answers.onstartups.com/*
// @match          *://mathoverflow.net/*
// @match          *://area51.stackexchange.com/proposals/*
// @author         Benjamin Dumke-von der Ehe
// ==/UserScript==

// Thanks to Shog9 for this idea for making the script work in both
// Chrome and Firefox:
// http://meta.stackoverflow.com/questions/46562
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($) {
        
    $(document).ajaxComplete(function(){
        setTimeout(function () {
            $(".comments").each(put_reply_links);
        }, 100);
    });
        
    // event handler for a click on the reply links
    function reply() {
        /* MOD: changed the following 2 lines to detect the new Add Comment link */
        var commentlinkId = $(this).closest(".comments").next().attr("id");
        var commentlink = $('#'+commentlinkId + ' a.js-add-link')[0].click();
        var username = goodify($(this).prev().text().replace(/♦/, ""))
        var formid = commentlinkId.replace(/^.*-(\d+)$/, "add-comment-$1");
        var ta = $("#" + formid + " textarea")[0];
        var start = ta.selectionStart;
        var end = ta.selectionEnd;
        var shift = username.length + 3;
        ta.value = "@" + username + ": " + ta.value;
        ta.focus();
        ta.selectionStart = start + shift;
        ta.selectionEnd = end + shift;
    };

    function put_reply_links() {
        $(this).find(".comment:not(:has(.reply-link)) .comment-user").each(function () {
            /* MOD: // changed click by on(click) */
            $("<span class='reply-link' style='cursor:pointer;' title='reply'> &crarr;</span>").on('click',reply).insertAfter(this); 
        });
    }
            
    $(".comments").each(put_reply_links);
    
    function goodify(s) {
        return s.replace(/ +/g, "");
    }   
});

I've made a couple of fixes to make this work again. While I don't fork and ask for a merge, here it is a copy of my script for convenience, the modifications are indicated with comments. The matches of sites has been revised as well.

// ==UserScript==
// @name           stackoverflow-comment-reply
// @namespace      stackapps
// @description    Add "reply" links to comments
// @version        1.1c
// @match          *://*.askubuntu.com/*
// @match          *://*.mathoverflow.net/*
// @match          *://*.serverfault.com/*
// @match          *://*.stackapps.com/*
// @match          *://*.stackexchange.com/*
// @match          *://*.stackoverflow.com/*
// @match          *://*.superuser.com/*
// @match          *://area51.stackexchange.com/proposals/*
// @author         Benjamin Dumke-von der Ehe
// ==/UserScript==
 
/* MOD: don't run if not SE and user not logged in */
if (!window.StackExchange || window.StackExchange.options.user.isAnonymous )
    return;

// Thanks to Shog9 for this idea for making the script work in both
// Chrome and Firefox:
// http://meta.stackoverflow.com/questions/46562
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($) {

    $(document).ajaxComplete(function(){
        setTimeout(function () {
            $(".comments").each(put_reply_links);
        }, 100);
    });

    // event handler for a click on the reply links
    function reply() {
        /* MOD: changed the following 2 lines to detect the new Add Comment link */
        var commentlinkId = $(this).closest(".comments").next().attr("id");
        var commentlink = $('#'+commentlinkId + ' a.js-add-link')[0].click();
        var username = goodify($(this).prev().text().replace(/♦/, ""))
        var formid = commentlinkId.replace(/^.*-(\d+)$/, "add-comment-$1");
        var ta = $("#" + formid + " textarea")[0];
        var start = ta.selectionStart;
        var end = ta.selectionEnd;
        var shift = username.length + 3;
        ta.value = "@" + username + ": " + ta.value;
        ta.focus();
        ta.selectionStart = start + shift;
        ta.selectionEnd = end + shift;
    };

    function put_reply_links() {
        $(this).find(".comment:not(:has(.reply-link)) .comment-user").each(function () {
            /* MOD: // changed click by on(click) */
            $("<span class='reply-link' style='cursor:pointer;opacity:0.3' title='reply'> &crarr;</span>").on('click',reply).insertAfter(this); 
        });
    }

    $(".comments").each(put_reply_links);

    function goodify(s) {
        return s.replace(/ +/g, "");
    }   
});
Source Link
brasofilo
  • 992
  • 7
  • 22

I've made a couple of fixes to make this work again, it does, but produces a strange error on Stack Exchange's code, in the replace bellow:

//This is where the real work starts - add the 'auto' link next to each comment 'help' link
//use most local root-nodes possible (have to exist on page load) - #questions is for review pages
$("#content").delegate(".comments-link", "click", function () {
  var divid = $(this).attr('id').replace('-link', '');

I'll leave a copy of my script for convenience, the modifications are indicated with comments:

// ==UserScript==
// @name           stackoverflow-comment-reply
// @namespace      stackoverflow
// @description    Add "reply" links to comments
// @version        1.1b
// @match          *://stackoverflow.com/*
// @match          *://serverfault.com/*
// @match          *://superuser.com/*
// @match          *://meta.stackoverflow.com/*
// @match          *://meta.serverfault.com/*
// @match          *://meta.superuser.com/*
// @match          *://stackapps.com/*
// @match          *://*.stackexchange.com/*
// @match          *://askubuntu.com/*
// @match          *://meta.askubuntu.com/*
// @match          *://answers.onstartups.com/*
// @match          *://meta.answers.onstartups.com/*
// @match          *://mathoverflow.net/*
// @match          *://area51.stackexchange.com/proposals/*
// @author         Benjamin Dumke-von der Ehe
// ==/UserScript==

// Thanks to Shog9 for this idea for making the script work in both
// Chrome and Firefox:
// http://meta.stackoverflow.com/questions/46562
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($) {
        
    $(document).ajaxComplete(function(){
        setTimeout(function () {
            $(".comments").each(put_reply_links);
        }, 100);
    });
        
    // event handler for a click on the reply links
    function reply() {
        /* MOD: changed the following 2 lines to detect the new Add Comment link */
        var commentlinkId = $(this).closest(".comments").next().attr("id");
        var commentlink = $('#'+commentlinkId + ' a.js-add-link')[0].click();
        var username = goodify($(this).prev().text().replace(/♦/, ""))
        var formid = commentlinkId.replace(/^.*-(\d+)$/, "add-comment-$1");
        var ta = $("#" + formid + " textarea")[0];
        var start = ta.selectionStart;
        var end = ta.selectionEnd;
        var shift = username.length + 3;
        ta.value = "@" + username + ": " + ta.value;
        ta.focus();
        ta.selectionStart = start + shift;
        ta.selectionEnd = end + shift;
    };

    function put_reply_links() {
        $(this).find(".comment:not(:has(.reply-link)) .comment-user").each(function () {
            /* MOD: // changed click by on(click) */
            $("<span class='reply-link' style='cursor:pointer;' title='reply'> &crarr;</span>").on('click',reply).insertAfter(this); 
        });
    }
            
    $(".comments").each(put_reply_links);
    
    function goodify(s) {
        return s.replace(/ +/g, "");
    }   
});