@@ -7,6 +7,14 @@ chrome.extension.sendMessage({}, function (settings) {
77 initForInbox ( )
88} )
99
10+ chrome . runtime . onMessage . addListener ( function ( req ) {
11+ var element = req [ 'muteURL' ] ? document . querySelector ( '[href="' + req [ 'muteURL' ] + '"]' ) : null
12+
13+ if ( element ) {
14+ element . innerText = "Muted!"
15+ }
16+ } )
17+
1018function initForInbox ( ) {
1119 window . idled = true
1220}
@@ -38,7 +46,7 @@ function initOnHashChangeAction(domains) {
3846 var github_links = reject_unwanted_paths ( mail_body . querySelectorAll ( selectors ) )
3947
4048 // Avoid multple buttons
41- Array . prototype . forEach . call ( document . querySelectorAll ( '.github-link, .github-mute-button ' ) , function ( ele ) {
49+ Array . prototype . forEach . call ( document . querySelectorAll ( '.github-link, .github-mute' ) , function ( ele ) {
4250 ele . remove ( )
4351 } )
4452
@@ -50,16 +58,15 @@ function initOnHashChangeAction(domains) {
5058 if ( url . match ( 'notifications/unsubscribe' ) ) {
5159 var muteURL = url
5260 url = github_links [ github_links . length - 2 ] . href
53- muteLink = document . createElement ( 'button' )
54- muteLink . type = 'button'
55- muteLink . className = 'github-mute-button T-I J-J5-Ji lS T-I-ax7 ar7'
61+ muteLink = document . createElement ( 'a' )
62+ muteLink . className = 'github-mute T-I J-J5-Ji lS T-I-ax7 ar7'
5663 muteLink . innerText = 'Mute thread'
57- muteLink . addEventListener ( 'click' , function ( ) {
64+ muteLink . href = muteURL
65+
66+ muteLink . addEventListener ( 'click' , function ( evt ) {
67+ evt . preventDefault ( )
68+ chrome . extension . sendMessage ( { url : muteURL , active : false } )
5869 muteLink . innerHTML = '⋯'
59- fetch ( muteURL , { mode : 'no-cors' } ) . then ( function ( ) {
60- muteLink . innerText = 'Muted!'
61- muteLink . disabled = 'disabled'
62- } )
6370 } )
6471 }
6572
@@ -116,8 +123,8 @@ function initShortcuts(shortcut, backgroundShortcut, muteShortcut) {
116123 }
117124
118125 // Mute Shortcut: bind user's combination, if a button exist and event not in a textarea
119- if ( processRightCombinationBasedOnShortcut ( muteShortcut , event ) && window . idled && getVisible ( document . getElementsByClassName ( 'github-mute-button ' ) ) && notAnInput ( event . target ) ) {
120- getVisible ( document . getElementsByClassName ( 'github-mute-button ' ) ) . click ( )
126+ if ( processRightCombinationBasedOnShortcut ( muteShortcut , event ) && window . idled && getVisible ( document . getElementsByClassName ( 'github-mute' ) ) && notAnInput ( event . target ) ) {
127+ getVisible ( document . getElementsByClassName ( 'github-mute' ) ) . click ( )
121128 }
122129 } )
123130}
0 commit comments