Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Created September 23, 2015 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiny-Giant/7e0540f736e7698e1222 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/7e0540f736e7698e1222 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://your.homepage/
// @version 0.1
// @description enter something useful
// @author You
// @include /^https?://(meta\.)?(stackoverflow|stackexchange|serverfault|superuser|askubuntu|stackapps)\.com/questions/[0-9]+.*/
// @grant none
// ==/UserScript==
(function(){
function e(e, t, n, i) {
t.fadeIn(n, i), e.hide()
}
$(".post-menu .edit-post")[0].innerHTML += '';
$(".post-menu .edit-post").live("click", function(t) {
if (!(t.ctrlKey || t.altKey || t.metaKey || t.shiftKey)) {
var n = $(this),
i = n.closest(".question, .answer");
if (1 == n.data("handling-event")) return !1;
n.data("handling-event", 1), i.find("#edit-tags-cancel").length && StackExchange.inlineTagEditing.restoreCurrentTags(!0);
var o = $("#show-editor-button"),
a = o.is(":visible");
a && o.hide(), n.addSpinner();
var r = "",
s = i.hasClass("answer");
s && (r = " class='answer'");
var c = i.find(".postcell,.answercell"),
l = c.find("> *"),
u = $('<div class="inline-editor"/>').hide().appendTo(c);
return u.load(n.attr("href") + "-inline", function(t, r) {
var d;
if (u.find("[tabindex]").each(function() {
$(this).attr("tabindex", parseInt($(this).attr("tabindex") - 20))
}), StackExchange.helpers.removeSpinner(), i.offset().top < $(window).scrollTop() && $("html, body").animate({
"scrollTop": $(i).offset().top - 55
}, 200), "error" == r) StackExchange.helpers.showErrorMessage(c, "The post could not be loaded"), u.remove(), n.data("handling-event", 0);
else {
e(l, u, 300);
var f = function(t) {
if (StackExchange.navPrevention) {
if (!StackExchange.navPrevention.confirm("You have started editing this post. Abandon this edit?")) return !1;
StackExchange.navPrevention.stop()
}
return a && o.show(), n.data("handling-event", 0), e(u, t, 300, function() {
u.remove()
}), t.offset().top < $(window).scrollTop() && $("html, body").animate({
"scrollTop": $(i).offset().top - 55
}, 200), !1
},
h = "input keyup",
p = function() {
w.unbind(h, g), S.trigger(d)
},
g = function() {
return S.trigger(w[0].value), !0
};
u.find(".cancel-edit").click(function() {
p(), f(l)
});
var m = StackExchange.helpers.DelayedReaction(function(e) {
$.ajax({
"type": "POST",
"data": {
"hide": e
},
"url": "/user/save-pref/hide-preview-for-inline-editing"
})
}, 1e3, {
"sliding": !0
}),
v = u.find(".hide-preview");
v.click(function() {
var e = u.find(".wmd-preview"),
t = e.is(":visible");
return t ? (e.slideUp(), v.text("show preview")) : (e.slideDown(), v.text("hide preview")), m.trigger(t), !1
});
var b = u.find('input[type="submit"]'),
x = (b.attr("id").replace("submit-button", ""), u.find("form")),
w = u.find("#title"),
y = $("#question-header a"),
k = w.data("question-state-suffix");
k = k ? " " + k : "", d = w.val();
var S = StackExchange.helpers.DelayedReaction(function(e) {
"undefined" != typeof e && (y.text(e + k), "undefined" != typeof MathJax && MathJax.Hub.Queue(["Typeset", MathJax.Hub, y[0]]))
}, {
"sliding": !0
});
w.bind(h, g), u.find("#title,.wmd-input,#tagnames,.edit-comment").keydown(function(e) {
return e.ctrlKey === !0 && 13 == e.keyCode ? (x.submit(), !1) : 27 == e.keyCode ? (p(), f(l), !1) : void 0
}), StackExchange.using("postValidation", function() {
StackExchange.postValidation.initOnBlurAndSubmit(x, s ? 2 : 1, "edit", !1, function(e) {
var t = e.html,
n = $(t).hide();
c.replaceWith(n), s || $("#question-header a").text(e.title), $("html").trigger("inline-edit-complete", [n, e.title]), styleCode(), f(n)
})
})
}
})
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment