@@ -35,25 +35,27 @@ function initOnHashChangeAction(domains) {
3535
3636 // Find GitHub link and append it to tool bar on hashchange
3737 window . onhashchange = function ( ) {
38+ if ( window . location . hash . match ( / c o m p o s e = n e w / ) ) return
3839 fetchAndAppendGitHubLink ( )
3940 }
4041
4142 function fetchAndAppendGitHubLink ( ) {
4243 // In case previous intervals got interrupted
4344 clearAllIntervals ( )
45+ var counter = 0
4446
4547 var retryForActiveMailBody = setInterval ( function ( ) {
48+ counter ++
4649 var mail_body = Array . prototype . filter . call ( document . querySelectorAll ( '.nH.hx' ) , function ( ) { return this . clientHeight != 0 } ) [ 0 ]
4750
48- if ( mail_body ) {
51+ if ( mail_body ) {
4952 var github_links = reject_unwanted_paths ( mail_body . querySelectorAll ( selectors ) )
50-
5153 // Avoid multple buttons
52- Array . prototype . forEach . call ( document . querySelectorAll ( '.github-link, .github-mute' ) , function ( ele ) {
54+ Array . prototype . forEach . call ( document . querySelectorAll ( '.github-container, .github- link, .github-mute' ) , function ( ele ) {
5355 ele . remove ( )
5456 } )
5557
56- if ( github_links . length ) {
58+ if ( github_links . length ) {
5759 var url = github_links [ github_links . length - 1 ] . href
5860 var muteLink
5961
@@ -75,15 +77,15 @@ function initOnHashChangeAction(domains) {
7577
7678 // Go to thread instead of diffs or file views
7779 if ( url . match ( / ^ ( .+ \/ ( i s s u e | p u l l ) \/ \d + ) / ) ) url = url . match ( / ^ ( .+ \/ ( i s s u e | p u l l ) \/ \d + ) / ) [ 1 ]
78- var link = document . createElement ( 'a' )
80+ const link = document . createElement ( 'a' )
7981 link . href = url
8082 link . className = 'github-link T-I J-J5-Ji lS T-I-ax7 ar7'
8183 link . target = '_blank'
8284 link . innerText = 'View on GitHub'
8385
8486 // Fix Safari margin
8587 const container = document . createElement ( 'div' )
86- container . className = 'G-Ni G-aE'
88+ container . className = 'G-Ni G-aE github-container '
8789
8890 container . appendChild ( link )
8991 if ( muteLink ) container . appendChild ( muteLink )
@@ -93,15 +95,16 @@ function initOnHashChangeAction(domains) {
9395
9496 document . getElementsByClassName ( 'github-link' ) [ 0 ] . addEventListener ( "DOMNodeRemovedFromDocument" , function ( ev ) {
9597 fetchAndAppendGitHubLink ( )
96- } , false )
98+ } )
99+ clearAllIntervals ( )
100+ } else if ( counter === 5 ) {
101+ clearAllIntervals ( )
97102 }
98-
99- clearInterval ( retryForActiveMailBody )
100- } else if ( ! document . querySelector ( '.nH.hx' ) ) {
103+ } else if ( ! document . querySelector ( '.nH.hx' ) ) {
101104 // Not in a mail view
102- clearInterval ( retryForActiveMailBody )
105+ clearAllIntervals ( )
103106 }
104- } , 100 )
107+ } , 200 )
105108
106109 intervals . push ( retryForActiveMailBody )
107110 }
@@ -225,10 +228,10 @@ function notAnInput (element) {
225228}
226229
227230function clearAllIntervals ( ) {
228- intervals . map ( function ( num ) {
229- clearInterval ( num )
230- delete intervals [ intervals . indexOf ( num ) ]
231- } )
231+ for ( const interval of intervals ) {
232+ clearInterval ( interval )
233+ delete intervals [ intervals . indexOf ( interval ) ]
234+ }
232235}
233236
234237// Reject unsubscribe, subscription and verification management paths
0 commit comments