Skip to main content
added 561 characters in body
Source Link
brunnerh
  • 661
  • 3
  • 10
// ==UserScript==
// @name           Direct Question Edit Links
// @namespace      stackoverflow
// @include        *stackoverflow.com*
// ==/UserScript==

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

    function queryQuestions() { return document.querySelectorAll("div.question-summary"); }
    
    function waitForQuestions()
    {
        var questions = document.querySelectorAllqueryQuestions("div.question-summary");
        if (questions.length == 0)
        {
            if (!cancelWaiting) window.setTimeout(waitForQuestions, 100);
        }
        else
        {
            addLinks(questions);
            var container = document.querySelector("#questions");
            if (container != null)
            {
                var obs = new MutationObserver(function() {
                    addLinks(queryQuestions());
                });

                obs.observe(container, { childList: true, subtree: true });
            }
        }
    }

    function addLinks(questions)
    {
        Array.prototype.forEach.call(questions, function (e)
        {
            if (e.getAttribute("data-edit-linked") == "true")
                return;
            
            var header = e.querySelector("div.summary h3");
            var id = header.querySelector("a")
                .getAttribute("href")
                .match(/[0-9]+(?=\/)/)[0];
            var link = document.createElement("a");
            link.setAttribute("href", "/posts/" + id + "/edit");
            link.textContent = "Edit";
            link.style.marginLeft = "5px";
            link.style.color = "grey";
            link.style.fontSize = "small";
            link.hidden = true;

            e.addEventListener("mouseenter", function ()
            {
                link.hidden = false;
            });
            e.addEventListener("mouseleave", function ()
            {
                link.hidden = true;
            });

            header.appendChild(link);
            
            e.setAttribute("data-edit-linked", "true");
        });
    }
})();
  • There were some issues with including jQuery directly, removed static reference.
  • Removed jCancer
  • Observe changes to support loading of new questions
// ==UserScript==
// @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 questions = document.querySelectorAll("div.question-summary");
        if (questions.length == 0)
        {
            if (!cancelWaiting) window.setTimeout(waitForQuestions, 100);
        }
        else
        {
            addLinks(questions);
        }
    }

    function addLinks(questions)
    {
        Array.prototype.forEach.call(questions, function (e)
        {
            var header = e.querySelector("div.summary h3");
            var id = header.querySelector("a")
                .getAttribute("href")
                .match(/[0-9]+(?=\/)/)[0];
            var link = document.createElement("a");
            link.setAttribute("href", "/posts/" + id + "/edit");
            link.textContent = "Edit";
            link.style.marginLeft = "5px";
            link.style.color = "grey";
            link.style.fontSize = "small";
            link.hidden = true;

            e.addEventListener("mouseenter", function ()
            {
                link.hidden = false;
            });
            e.addEventListener("mouseleave", function ()
            {
                link.hidden = true;
            });

            header.appendChild(link);
        });
    }
})();
  • There were some issues with including jQuery directly, removed static reference.
  • Removed jCancer
// ==UserScript==
// @name           Direct Question Edit Links
// @namespace      stackoverflow
// @include        *stackoverflow.com*
// ==/UserScript==

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

    function queryQuestions() { return document.querySelectorAll("div.question-summary"); }
    
    function waitForQuestions()
    {
        var questions = queryQuestions();
        if (questions.length == 0)
        {
            if (!cancelWaiting) window.setTimeout(waitForQuestions, 100);
        }
        else
        {
            addLinks(questions);
            var container = document.querySelector("#questions");
            if (container != null)
            {
                var obs = new MutationObserver(function() {
                    addLinks(queryQuestions());
                });

                obs.observe(container, { childList: true, subtree: true });
            }
        }
    }

    function addLinks(questions)
    {
        Array.prototype.forEach.call(questions, function (e)
        {
            if (e.getAttribute("data-edit-linked") == "true")
                return;
            
            var header = e.querySelector("div.summary h3");
            var id = header.querySelector("a")
                .getAttribute("href")
                .match(/[0-9]+(?=\/)/)[0];
            var link = document.createElement("a");
            link.setAttribute("href", "/posts/" + id + "/edit");
            link.textContent = "Edit";
            link.style.marginLeft = "5px";
            link.style.color = "grey";
            link.style.fontSize = "small";
            link.hidden = true;

            e.addEventListener("mouseenter", function ()
            {
                link.hidden = false;
            });
            e.addEventListener("mouseleave", function ()
            {
                link.hidden = true;
            });

            header.appendChild(link);
            
            e.setAttribute("data-edit-linked", "true");
        });
    }
})();
  • There were some issues with including jQuery directly, removed static reference.
  • Removed jCancer
  • Observe changes to support loading of new questions
deleted 247 characters in body
Source Link
brunnerh
  • 661
  • 3
  • 10
// ==UserScript==
// @name           Direct Question Edit Links
// @namespace      stackoverflow
// @include        *stackoverflow.com*
// ==/UserScript==

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

    function jq_wait()
    {
        if (typeof unsafeWindow.jQuery == 'undefined')
        {
            window.setTimeout(jq_wait, 100);
        } else
        {
            $ = unsafeWindow.jQuery;
            window.setTimeout(function () { cancelWaiting = true; }, 5000);
            $(document).ready(waitForQuestions();
        }
    }

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

    function addLinks(jQuestionsquestions)
    {
        jQuestionsArray.eachprototype.forEach.call(questions, function (i, e)
        {
            var jQuestionheader = $(e);
            var jHeader = $.querySelector("div.summary h3", e);
            var id = $header.querySelector("a", jHeader)
                .attrgetAttribute("href")
                .match(/[0-9]+(?=\/)/)[0];
            var link = $document.createElement("<a/>""a");
            link.attrsetAttribute("href", "/posts/" + id + "/edit");
            link.html("Edit");textContent = "Edit";
            link.css("margin-left",style.marginLeft "5px");= "5px";
            link.css("color",style.color "grey");= "grey";
            link.css("font-size",style.fontSize "small");= "small";
            link.css("visibility",hidden "hidden");= true;

            jQuestione.mouseenteraddEventListener("mouseenter", function ()
            {
                link.css("visibility",hidden "visible");= false;
            });
            jQuestione.mouseleaveaddEventListener("mouseleave", function ()
            {
                link.css("visibility",hidden "hidden");= true;
            });

            jHeaderheader.appendappendChild(link);
        });
    }
})();
  • There were some issues with including jQuery directly, removed static reference.
  • Removed jCancer
// ==UserScript==
// @name           Direct Question Edit Links
// @namespace      stackoverflow
// @include        *stackoverflow.com*
// ==/UserScript==

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

    function jq_wait()
    {
        if (typeof unsafeWindow.jQuery == 'undefined')
        {
            window.setTimeout(jq_wait, 100);
        } else
        {
            $ = unsafeWindow.jQuery;
            window.setTimeout(function () { cancelWaiting = true; }, 5000);
            $(document).ready(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);
        });
    }
})();
  • There were some issues with including jQuery directly, removed static reference.
// ==UserScript==
// @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 questions = document.querySelectorAll("div.question-summary");
        if (questions.length == 0)
        {
            if (!cancelWaiting) window.setTimeout(waitForQuestions, 100);
        }
        else
        {
            addLinks(questions);
        }
    }

    function addLinks(questions)
    {
        Array.prototype.forEach.call(questions, function (e)
        {
            var header = e.querySelector("div.summary h3");
            var id = header.querySelector("a")
                .getAttribute("href")
                .match(/[0-9]+(?=\/)/)[0];
            var link = document.createElement("a");
            link.setAttribute("href", "/posts/" + id + "/edit");
            link.textContent = "Edit";
            link.style.marginLeft = "5px";
            link.style.color = "grey";
            link.style.fontSize = "small";
            link.hidden = true;

            e.addEventListener("mouseenter", function ()
            {
                link.hidden = false;
            });
            e.addEventListener("mouseleave", function ()
            {
                link.hidden = true;
            });

            header.appendChild(link);
        });
    }
})();
  • There were some issues with including jQuery directly, removed static reference.
  • Removed jCancer
edited tags
Link
Brock Adams
  • 13k
  • 5
  • 39
  • 64
added 334 characters in body
Source Link
brunnerh
  • 661
  • 3
  • 10
Loading
deleted 20 characters in body
Source Link
brunnerh
  • 661
  • 3
  • 10
Loading
Source Link
brunnerh
  • 661
  • 3
  • 10
Loading