-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
82 lines (73 loc) · 1.89 KB
/
content.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Repo owner key pair value.
*/
const repos = {};
/**
* Dynamically injected styles.
*/
const styleElement = document.createElement('style');
/**
* Listen for the card clicks.
*/
document.addEventListener('click', function(event) {
if ( event.altKey ) {
return;
}
const card = event.target.closest( '.zhc-issue-card' );
if ( ! card ) {
return;
}
storeRepos();
hideUI();
openIssue( card );
setTimeout( () => {
unHideUI();
}, 1000 );
} );
/**
* Hide the original
*/
const hideUI = () => {
var css = '.react-portal-container, .zhc-repo-filter__container .zhc-selection-list-deprecated { display: none !important; }';
document.head.appendChild(styleElement);
styleElement.appendChild( document.createTextNode( css ) );
}
/**
* Unhide the original UI.
*/
const unHideUI = () => {
document.querySelector( '.zhc-sidebar__flyover-close-target' ).click();
styleElement.textContent = '';
}
/**
* Get the repos from the dropdown as repo => owner key value pairs.
*/
const storeRepos = () => {
const button = document.querySelector( '[data-cy="repo-filter-container"] button' );
button.click();
document.querySelectorAll( '.zhc-repo-filter__container .zhc-repo-item__repository' ).forEach( (repo) => {
repos[ repo.textContent ] = repo.nextSibling.textContent;
} );
button.click();
}
/**
* Open the issue in a new tab given a card element.
*
* @param {HTMLElement} card
*/
const openIssue = ( card ) => {
const repo = card.querySelector( '.zhc-issue-card__repo-name' ).textContent;
const number = card.querySelector( '.zhc-issue-card__issue-number' ).textContent.replace( '#', '' );
const issueUrl = getIssueUrl( repo, number );
window.open( issueUrl, '_blank' );
}
/**
* Get the issue URL.
*
* @param {string} repo
* @param {number} number
* @returns
*/
const getIssueUrl = ( repo, number ) => {
return `https://github.com/${repos[ repo ] }/${ repo }/issues/${ number }`;
}