Skip to content

Commit d6532ff

Browse files
committed
Trigger goto action if exists, also fix getVisible
1 parent 2fb1553 commit d6532ff

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/inject/inject.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function initShortcuts(shortcut, backgroundShortcut) {
7979
function initListViewShortcut(regexp) {
8080
$(document).on("keypress", function(event) {
8181
// Shortcut: bind ctrl + return
82-
selected = getVisible(document.querySelectorAll('.PE ~ [tabindex="0"]'))
82+
selected = getVisible(document.querySelectorAll('.zA[tabindex="0"]'))
8383
if( event.ctrlKey && event.keyCode == 13 && selected ) {
8484
generateUrlAndGoTo(selected, regexp)
8585
}
@@ -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() : fakeClick()
93+
event = backgroundOrNot ? fakeBackgroundClick() : fakeEvent('click')
9494

9595
$(".github-link:visible")[0].dispatchEvent(event)
9696
setTimeout( function(){ window.idled = true }, 100)
@@ -103,15 +103,21 @@ function generateUrlAndGoTo (selected, regexp) {
103103

104104
// org name coms from a label
105105
regexp = new RegExp(regexp)
106-
org = selected.querySelectorAll('.av')[0].innerText.toLowerCase().match(regexp)
106+
label = selected.querySelectorAll('.av')[0]
107+
if (label) org = label.innerText.toLowerCase().match(regexp)
107108

108-
if(org) {
109+
// quick action ?!
110+
gotoaction = selected.querySelectorAll('.aKS [role="button"]')[0]
111+
112+
if(gotoaction) {
113+
gotoaction.dispatchEvent(fakeEvent('mousedown'))
114+
} else if(org) {
109115
org = org[1]
110116
repo = title[1]
111117
issue_no = title[2]
112118

113119
url = "https://github.com/" + org + "/" + repo + "/issues/" + issue_no
114-
linkWithUrl(url).dispatchEvent(fakeClick())
120+
linkWithUrl(url).dispatchEvent(fakeEvent('click'))
115121
}
116122
}
117123
}
@@ -144,9 +150,9 @@ function processRightCombinationBasedOnShortcut (shortcut, event) {
144150
}
145151

146152
// .click() doesn't usually work as expected
147-
function fakeClick () {
153+
function fakeEvent (event) {
148154
var click = document.createEvent("MouseEvents")
149-
click.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
155+
click.initMouseEvent(event, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
150156
return click
151157
}
152158

@@ -167,7 +173,7 @@ function getVisible (nodeList) {
167173
if(nodeList.length) {
168174
var node
169175
$(nodeList).map(function() {
170-
if(typeof node == 'undefined' && (this.offsetTop > 0 || this.offsetLeft > 0)) {
176+
if(typeof node == 'undefined' && (this.clientWidth > 0 || this.clientHeight > 0)) {
171177
node = this
172178
}
173179
})

0 commit comments

Comments
 (0)