11// Retriving user options
2- chrome . extension . sendMessage ( { } , function ( settings ) {
2+ chrome . extension . sendMessage ( { } , function ( settings ) {
33 initOnHashChangeAction ( settings [ 'Domains' ] )
44 initShortcuts ( settings [ 'Shortcut' ] , settings [ 'BackgroundShortcut' ] )
55 initListViewShortcut ( )
@@ -11,44 +11,48 @@ function initForInbox() {
1111}
1212
1313function initOnHashChangeAction ( domains ) {
14- allDomains = " //github.com,"
14+ var allDomains = ' //github.com,'
1515 if ( domains ) allDomains += domains
1616
1717 // Take string -> make array -> make queries -> avoid nil -> join queries to string
18- selectors = allDomains . replace ( / \s / , '' ) . split ( ',' ) . map ( function ( name ) {
18+ var selectors = allDomains . replace ( / \s / , '' ) . split ( ',' ) . map ( function ( name ) {
1919 if ( name . length ) return ( ".AO [href*='" + name + "']" )
20- } ) . filter ( function ( name ) { return name } ) . join ( ", " )
20+ } ) . filter ( function ( name ) { return name } ) . join ( ", " )
2121
2222 intervals = [ ]
2323
2424 // Find GitHub link and append it to tool bar on hashchange
25- window . onhashchange = function ( ) {
25+ window . onhashchange = function ( ) {
2626 fetchAndAppendGitHubLink ( )
2727 }
2828
29- function fetchAndAppendGitHubLink ( ) {
29+ function fetchAndAppendGitHubLink ( ) {
3030 // In case previous intervals got interrupted
3131 clearAllIntervals ( )
3232
33- retryForActiveMailBody = setInterval ( function ( ) {
34- mail_body = $ ( '.nH.hx' ) . filter ( function ( ) { return this . clientHeight != 0 } ) [ 0 ]
33+ var retryForActiveMailBody = setInterval ( function ( ) {
34+ var mail_body = Array . prototype . filter . call ( document . querySelectorAll ( '.nH.hx' ) , function ( ) { return this . clientHeight != 0 } ) [ 0 ]
3535
36- if ( mail_body ) {
37-
38- github_links = mail_body . querySelectorAll ( selectors )
39- github_links = reject_unwanted_paths ( github_links )
36+ if ( mail_body ) {
37+ var github_links = reject_unwanted_paths ( mail_body . querySelectorAll ( selectors ) )
4038
4139 // Avoid multple buttons
42- $ ( '.github-link' ) . remove ( )
40+ Array . prototype . forEach . call ( document . querySelectorAll ( '.gitbhub-link' ) , function ( ele ) {
41+ ele . remove ( )
42+ } )
4343
44- if ( github_links . length ) {
44+ if ( github_links . length ) {
4545
46- url = github_links [ github_links . length - 1 ] . href
46+ var url = github_links [ github_links . length - 1 ] . href
4747 // Go to thread instead of .diff link (pull request notifications)
4848 url = url . match ( / \. d i f f / ) ? url . slice ( 0 , url . length - 5 ) : url
49- link = $ ( "<a class='github-link T-I J-J5-Ji lS T-I-ax7 ar7' target='_blank' href='" + url + "'>Visit Thread on GitHub</a>" )
49+ var link = document . createElement ( 'a' )
50+ link . href = url
51+ link . className = 'github-link T-I J-J5-Ji lS T-I-ax7 ar7'
52+ link . target = '_blank'
53+ link . innerText = 'Visit Thread on GitHub'
5054
51- $ ( " .iH > div" ) . append ( link )
55+ document . querySelector ( ' .iH > div' ) . appendChild ( link )
5256 window . idled = true
5357
5458 document . getElementsByClassName ( 'github-link' ) [ 0 ] . addEventListener ( "DOMNodeRemovedFromDocument" , function ( ev ) {
@@ -57,7 +61,7 @@ function initOnHashChangeAction(domains) {
5761 }
5862
5963 clearInterval ( retryForActiveMailBody )
60- } else if ( $ ( '.nH.hx' ) . length == 0 ) {
64+ } else if ( ! document . querySelector ( '.nH.hx' ) ) {
6165 // Not in a mail view
6266 clearInterval ( retryForActiveMailBody )
6367 }
@@ -68,26 +72,32 @@ function initOnHashChangeAction(domains) {
6872}
6973
7074function initShortcuts ( shortcut , backgroundShortcut ) {
71- $ ( document ) . on ( " keydown" , function ( event ) {
75+ document . addEventListener ( ' keydown' , function ( event ) {
7276 // Shortcut: bind user's combination, if a button exist and event not in a textarea
73- $ ( '.gE' ) . removeClass ( 'github-link' )
74- $ ( '.scroll-list-item-open .gE, .scroll-list-item-highlighted .gE' ) . addClass ( 'github-link' )
75- if ( processRightCombinationBasedOnShortcut ( shortcut , event ) && window . idled && getVisible ( document . getElementsByClassName ( 'github-link' ) ) && notAnInput ( event . target ) ) {
77+ if ( document . querySelector ( '.gE' ) ) {
78+ document . querySelector ( '.gE' ) . classList . remove ( 'github-link' )
79+ }
80+
81+ Array . prototype . forEach . call ( document . querySelectorAll ( '.scroll-list-item-open .gE, .scroll-list-item-highlighted .gE' ) , function ( ele ) {
82+ ele . classList . add ( 'github-link' )
83+ } )
84+
85+ if ( processRightCombinationBasedOnShortcut ( shortcut , event ) && window . idled && getVisible ( document . getElementsByClassName ( 'github-link' ) ) && notAnInput ( event . target ) ) {
7686 triggerGitHubLink ( false )
7787 }
7888
7989 // Bacground Shortcut: bind user's combination, if a button exist and event not in a textarea
80- if ( processRightCombinationBasedOnShortcut ( backgroundShortcut , event ) && window . idled && getVisible ( document . getElementsByClassName ( 'github-link' ) ) && notAnInput ( event . target ) ) {
90+ if ( processRightCombinationBasedOnShortcut ( backgroundShortcut , event ) && window . idled && getVisible ( document . getElementsByClassName ( 'github-link' ) ) && notAnInput ( event . target ) ) {
8191 triggerGitHubLink ( true )
8292 }
8393 } )
8494}
8595
8696function initListViewShortcut ( regexp ) {
87- $ ( document ) . on ( " keypress" , function ( event ) {
97+ document . addEventListener ( ' keypress' , function ( event ) {
8898 // Shortcut: bind ctrl + return
89- selected = getVisible ( document . querySelectorAll ( '.zA[tabindex="0"]' ) )
90- if ( event . ctrlKey && event . keyCode == 13 && selected ) {
99+ var selected = getVisible ( document . querySelectorAll ( '.zA[tabindex="0"]' ) )
100+ if ( event . ctrlKey && event . keyCode == 13 && selected ) {
91101 generateUrlAndGoTo ( selected )
92102 }
93103 } )
@@ -100,12 +110,12 @@ function triggerGitHubLink (backgroundOrNot) {
100110 var link = getVisible ( document . getElementsByClassName ( 'github-link' ) )
101111 chrome . extension . sendMessage ( { url : link . href , active : ! backgroundOrNot } )
102112
103- setTimeout ( function ( ) { window . idled = true } , 100 )
113+ setTimeout ( function ( ) { window . idled = true } , 100 )
104114}
105115
106116// Go to selected email GitHub thread
107117function generateUrlAndGoTo ( selected ) {
108- gotoaction = selected . querySelectorAll ( '.aKS [role="button"]' ) [ 0 ]
118+ var gotoaction = selected . querySelectorAll ( '.aKS [role="button"]' ) [ 0 ]
109119
110120 if ( gotoaction ) {
111121 gotoaction . dispatchEvent ( fakeEvent ( 'mousedown' , true ) )
@@ -124,7 +134,7 @@ function processRightCombinationBasedOnShortcut (shortcut, event) {
124134 trueOrFalse = [ ]
125135
126136 // If a key is in the combination, push the value to trueOrFalse array, and delete it from the combination
127- keys . map ( function ( key ) {
137+ keys . map ( function ( key ) {
128138 index = combination . indexOf ( key )
129139 if ( index >= 0 ) {
130140 if ( key == "shift" ) trueOrFalse . push ( event . shiftKey )
@@ -174,7 +184,7 @@ function notAnInput (element) {
174184}
175185
176186function clearAllIntervals ( ) {
177- intervals . map ( function ( num ) {
187+ intervals . map ( function ( num ) {
178188 clearInterval ( num )
179189 delete intervals [ intervals . indexOf ( num ) ]
180190 } )
@@ -188,7 +198,7 @@ function reject_unwanted_paths (links) {
188198 '\/\/[^\/]*\/.*\/.*\/subscription$' ,
189199 '\/\/[^\/]*\/.*\/.*\/emails\/.*\/confirm_verification\/.*' ]
190200 var regexp = new RegExp ( paths . join ( '|' ) )
191- return $ ( links ) . filter ( function ( ) {
192- if ( ! this . href . match ( regexp ) ) return this
201+ return Array . prototype . filter . call ( links , function ( link ) {
202+ if ( ! link . href . match ( regexp ) ) return this
193203 } )
194204}
0 commit comments