-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSECommentContextFix.user.js
67 lines (59 loc) · 2.4 KB
/
SECommentContextFix.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// ==UserScript==
// @name SE Comment Context Fix
// @description An attempted workaround for Firefox contenxt menu enter key presses being misinterpreted
// @include http://stackoverflow.com/questions/*
// @include http://meta.stackoverflow.com/questions/*
// @include http://superuser.com/questions/*
// @include http://meta.superuser.com/questions/*
// @include http://serverfault.com/questions/*
// @include http://meta.serverfault.com/questions/*
// @include http://askubuntu.com/questions/*
// @include http://meta.askubuntu.com/questions/*
// @include http://answers.onstartups.com/questions/*
// @include http://meta.answers.onstartups.com/questions/*
// @include http://nothingtoinstall.com/questions/*
// @include http://meta.nothingtoinstall.com/questions/*
// @include http://seasonedadvice.com/questions/*
// @include http://meta.seasonedadvice.com/questions/*
// @include http://*.stackexchange.com/questions/*
// @exclude http://chat.stackexchange.com/*
// @exclude http://chat.*.stackexchange.com/*
// @exclude http://api.*.stackexchange.com/*
// @exclude http://odata.stackexchange.com/*
// @exclude http://area51.stackexchange.com/*
// @author @Tim Stone
// ==/UserScript==
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 hook() {
var commentBoxes = $("textarea[name='comment']:not(.patched)"),
events = commentBoxes
.addClass("patched")
.data('events'),
found = false;
if (!commentBoxes.length || !events)
return;
if (events.keyup) {
for (var i = events.keyup.length - 1; !found && i > 0; --i) {
var stringified = events.keyup[i].handler.toString();
if (found = stringified.match(/\.which ?== ?13 ?&& ?![^.]+\.shiftKey/)) {
var handler = events.keyup.splice(i, 1)[0].handler;
commentBoxes.bind('keydown', handler);
}
}
}
}
$(function () {
$('.comments-link:visible').click(hook);
$(document).ajaxComplete(function(event, request, options) {
if (options && options.url && options.url.match(/^\/posts\/[0-9]+\/comments/)) {
hook();
}
});
});
});