Skip to content

Commit d5a9fb7

Browse files
committed
🐛 Fix Chrome compatibility issues (re-fixes jerone#19);
1 parent 66432a2 commit d5a9fb7

2 files changed

Lines changed: 29 additions & 21 deletions

File tree

Github_Comment_Enhancer/Github_Comment_Enhancer.user.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
search: /(.+)([\n]?)/g,
132132
replace: String.format("{0} $1$2", listCharacter),
133133
forceNewline: true,
134-
shortcut: "ctrl+shift+u"
134+
shortcut: "alt+ctrl+u"
135135
},
136136
"function-ol": {
137137
exec: function(button, selText, commentForm, next) {
@@ -149,13 +149,13 @@
149149
}
150150
next(repText);
151151
},
152-
shortcut: "ctrl+shift+o"
152+
shortcut: "alt+ctrl+o"
153153
},
154154
"function-checklist": {
155155
search: /(.+)([\n]?)/g,
156156
replace: String.format("{0} [ ] $1$2", listCharacter),
157157
forceNewline: true,
158-
shortcut: "ctrl+shift+t"
158+
shortcut: "alt+ctrl+t"
159159
},
160160

161161
"function-code": {
@@ -183,15 +183,15 @@
183183
"| Cell | Cell | Cell |\n" +
184184
"| Left | Center | Right |\n",
185185
forceNewline: true,
186-
shortcut: "ctrl+t"
186+
shortcut: "alt+shift+t"
187187
},
188188

189189
"function-clear": {
190190
exec: function(button, selText, commentForm, next) {
191191
commentForm.value = "";
192192
next("");
193193
},
194-
shortcut: "ctrl+shift+x"
194+
shortcut: "alt+ctrl+x"
195195
},
196196

197197
"function-snippets-tab": {
@@ -280,13 +280,13 @@
280280
' </a>' +
281281
' </div>' +
282282
' <div class="button-group btn-group">' +
283-
' <a href="#" id="function-ul" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Unordered List (ctrl+shift+u)">' +
283+
' <a href="#" id="function-ul" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Unordered List (alt+ctrl+u)">' +
284284
' <span class="octicon octicon-list-unordered"></span>' +
285285
' </a>' +
286-
' <a href="#" id="function-ol" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Ordered List (ctrl+shift+o)">' +
286+
' <a href="#" id="function-ol" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Ordered List (alt+ctrl+o)">' +
287287
' <span class="octicon octicon-list-ordered"></span>' +
288288
' </a>' +
289-
' <a href="#" id="function-checklist" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Task List (ctrl+shift+t)">' +
289+
' <a href="#" id="function-checklist" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Task List (alt+ctrl+t)">' +
290290
' <span class="octicon octicon-checklist"></span>' +
291291
' </a>' +
292292
' </div>' +
@@ -301,7 +301,7 @@
301301
' <a href="#" id="function-rule" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Horizontal Rule (ctrl+r)">' +
302302
' <span class="octicon octicon-horizontal-rule"></span>' +
303303
' </a>' +
304-
' <a href="#" id="function-table" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Table (ctrl+t)">' +
304+
' <a href="#" id="function-table" class="btn btn-sm minibutton function-button tooltipped tooltipped-ne" aria-label="Table (alt+shift+t)">' +
305305
' <span class="octicon octicon-three-bars"></span>' +
306306
' </a>' +
307307
' </div>' +
@@ -371,7 +371,7 @@
371371
'</div>' +
372372

373373
'<div style="float:right;">' +
374-
' <a href="#" id="function-clear" class="btn btn-sm minibutton function-button tooltipped tooltipped-nw" aria-label="Clear (ctrl+shift+x)">' +
374+
' <a href="#" id="function-clear" class="btn btn-sm minibutton function-button tooltipped tooltipped-nw" aria-label="Clear (alt+ctrl+x)">' +
375375
' <span class="octicon octicon-circle-slash"></span>' +
376376
' </a>' +
377377
'</div>';
@@ -534,6 +534,9 @@
534534

535535
function commentFormKeyEvent(commentForm, e) {
536536
var keys = [];
537+
if (e.altKey) {
538+
keys.push('alt');
539+
}
537540
if (e.ctrlKey) {
538541
keys.push('ctrl');
539542
}
@@ -542,13 +545,18 @@
542545
}
543546
keys.push(String.fromCharCode(e.which).toLowerCase());
544547
var keyCombination = keys.join('+');
545-
var actionName = Object.keys(MarkDown).find(function(action) {
546-
return MarkDown[action].shortcut && MarkDown[action].shortcut.toLowerCase() === keyCombination;
547-
});
548-
if (actionName) {
548+
549+
var action;
550+
for (var actionName in MarkDown) {
551+
if (MarkDown[actionName].shortcut && MarkDown[actionName].shortcut.toLowerCase() === keyCombination) {
552+
action = MarkDown[actionName];
553+
break;
554+
}
555+
}
556+
if (action) {
549557
e.preventDefault();
550558
e.stopPropagation();
551-
executeAction(MarkDown[actionName], commentForm, null);
559+
executeAction(action, commentForm, null);
552560
return false;
553561
}
554562
}
@@ -632,7 +640,7 @@
632640
button.addEventListener("click", functionButtonClick);
633641
});
634642

635-
commentForm.addEventListener('keypress', commentFormKeyEvent.bind(this, commentForm));
643+
commentForm.addEventListener('keydown', commentFormKeyEvent.bind(this, commentForm));
636644
});
637645
}
638646

Github_Comment_Enhancer/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ Every comment field also got a toolbar, consisting of the following buttons:
2626
* Header 6 (<kbd>ctrl+6</kbd>)
2727
* Link (<kbd>ctrl+l</kbd>)
2828
* Image (<kbd>ctrl+g</kbd>)
29-
* Unordered List (<kbd>ctrl+shift+u</kbd>)
30-
* Ordered List (<kbd>ctrl+shift+o</kbd>)
31-
* Task List (<kbd>ctrl+shift+t</kbd>)
29+
* Unordered List (<kbd>alt+ctrl+u</kbd>)
30+
* Ordered List (<kbd>alt+ctrl+o</kbd>)
31+
* Task List (<kbd>alt+ctrl+t</kbd>)
3232
* Code (<kbd>ctrl+k</kbd>)
3333
* Quote (<kbd>ctrl+q</kbd>)
3434
* Horizontal Rule (<kbd>ctrl+r</kbd>)
35-
* Table (<kbd>ctrl+t</kbd>)
35+
* Table (<kbd>alt+shift+t</kbd>)
3636
* Snippets
3737
* Tab character
3838
* UserAgent
3939
* Contributing message
4040
* Emoji
41-
* Clear comment field (<kbd>ctrl+shift+x</kbd>)
41+
* Clear comment field (<kbd>alt+ctrl+x</kbd>)
4242

4343

4444
## Screenshot

0 commit comments

Comments
 (0)