Skip to content

Commit 7b67788

Browse files
committed
Add a mute thread button
1 parent a3d11ef commit 7b67788

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

chrome/src/inject/inject.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,30 @@ function initOnHashChangeAction(domains) {
3737
var github_links = reject_unwanted_paths(mail_body.querySelectorAll(selectors))
3838

3939
// Avoid multple buttons
40-
Array.prototype.forEach.call(document.querySelectorAll('.github-link'), function (ele) {
40+
Array.prototype.forEach.call(document.querySelectorAll('.github-link, .github-mute-button'), function (ele) {
4141
ele.remove()
4242
})
4343

4444
if (github_links.length ) {
4545
var url = github_links[github_links.length-1].href
46+
var muteLink
4647

4748
// skip notification unsubscribe links:
4849
if (url.match('notifications/unsubscribe')) {
50+
var muteURL = url
4951
url = github_links[github_links.length-2].href
52+
muteLink = document.createElement('button')
53+
muteLink.type = 'button'
54+
muteLink.className = 'ithub-mute-button T-I J-J5-Ji lS T-I-ax7 ar7'
55+
muteLink.innerText = 'Mute thread'
56+
muteLink.addEventListener('click', function () {
57+
fetch(muteURL, {mode: 'no-cors'}).then(function () {
58+
muteLink.innerText = 'Muted!'
59+
muteLink.disabled = 'disabled'
60+
})
61+
})
5062
}
63+
5164
// Go to thread instead of .diff link (pull request notifications)
5265
url = url.match(/\.diff/) ? url.slice(0, url.length-5) : url
5366
var link = document.createElement('a')
@@ -57,6 +70,11 @@ function initOnHashChangeAction(domains) {
5770
link.innerText = 'Visit Thread on GitHub'
5871

5972
document.querySelector('.iH > div').appendChild(link)
73+
74+
if (muteLink) {
75+
document.querySelector('.iH > div').appendChild(muteLink)
76+
}
77+
6078
window.idled = true
6179

6280
document.getElementsByClassName('github-link')[0].addEventListener("DOMNodeRemovedFromDocument", function (ev) {

0 commit comments

Comments
 (0)