Skip to main content
1 of 6
brunnerh
  • 661
  • 3
  • 10

Direct Question Edit Links

A screenshot

This script adds an edit link to the question summary, saving frequent editors the trouble of "entering" the question first.

Adjust includes as needed:

// ==UserScript==
// @require        https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// @name           Direct Question Edit Links
// @namespace      stackoverflow
// @include        *stackoverflow.com*
// ==/UserScript==

(function ()
{
    var cancelWaiting = false;
    window.setTimeout(function () { cancelWaiting = true; }, 5000);
    waitForQuestions();

    function waitForQuestions()
    {
        var jQuestions = $("div.question-summary");
        if (jQuestions.length == 0)
            if (!cancelWaiting) window.setTimeout(waitForQuestions, 100);
        else
            addLinks(jQuestions);
    }

    function addLinks(jQuestions)
    {
        jQuestions.each(function (i, e)
        {
            var jQuestion = $(e);
            var jHeader = $("div.summary h3", e);
            var id = $("a", jHeader)
                .attr("href")
                .match(/[0-9]+(?=\/)/)[0];
            var link = $("<a/>");
            link.attr("href", "/posts/" + id + "/edit");
            link.html("Edit");
            link.css("margin-left", "5px");
            link.css("color", "grey");
            link.css("font-size", "small");
            link.css("visibility", "hidden");

            jQuestion.mouseenter(function ()
            {
                link.css("visibility", "visible");
            });
            jQuestion.mouseleave(function ()
            {
                link.css("visibility", "hidden");
            });

            jHeader.append(link);
        });
    }
})();
brunnerh
  • 661
  • 3
  • 10