Skip to content

Commit bbd7725

Browse files
committed
Use MouseEvent because we are in the future, and bubbles everywhere
1 parent 7613337 commit bbd7725

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/inject/inject.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function initListViewShortcut(regexp) {
9090
function triggerGitHubLink (backgroundOrNot) {
9191
// avoid link being appended multiple times
9292
window.idled = false
93-
event = backgroundOrNot ? fakeBackgroundClick() : fakeEvent('click')
93+
event = backgroundOrNot ? fakeBackgroundClick() : fakeEvent('click', false)
9494

9595
getVisible(document.getElementsByClassName('github-link')).dispatchEvent(event)
9696
setTimeout( function(){ window.idled = true }, 100)
@@ -102,7 +102,7 @@ function generateUrlAndGoTo (selected, regexp) {
102102

103103
if(gotoaction) {
104104
// if there's a gotoaction
105-
gotoaction.dispatchEvent(fakeEvent('mousedown'))
105+
gotoaction.dispatchEvent(fakeEvent('mousedown', true))
106106

107107
} else if( (title = selected.innerText.match(/\[(.*)\]\s.*\s\(\#(\d*)\)/)) ) {
108108
// If the title looks like a GitHub notification email.
@@ -118,7 +118,7 @@ function generateUrlAndGoTo (selected, regexp) {
118118
issue_no = title[2]
119119

120120
url = "https://github.com/" + org + "/" + repo + "/issues/" + issue_no
121-
linkWithUrl(url).dispatchEvent(fakeEvent('click'))
121+
linkWithUrl(url).dispatchEvent(fakeEvent('click', false))
122122
}
123123
}
124124
}
@@ -151,15 +151,13 @@ function processRightCombinationBasedOnShortcut (shortcut, event) {
151151
}
152152

153153
// .click() doesn't usually work as expected
154-
function fakeEvent (event) {
155-
var click = document.createEvent("MouseEvents")
156-
click.initMouseEvent(event, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
154+
function fakeEvent (event, bubbles) {
155+
var click = new MouseEvent(event, {bubbles: bubbles})
157156
return click
158157
}
159158

160159
function fakeBackgroundClick () {
161-
var click = document.createEvent("MouseEvents")
162-
click.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, true, 0, null)
160+
var click = new MouseEvent('click', {metaKey: true})
163161
return click
164162
}
165163

0 commit comments

Comments
 (0)