Skip to content

Commit

Permalink
Initialize mute shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
muan committed May 30, 2016
1 parent 10ffd43 commit 90897df
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions chrome/src/inject/inject.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Retriving user options
chrome.extension.sendMessage({}, function (settings) {
initOnHashChangeAction(settings['Domains'])
initShortcuts(settings['Shortcut'], settings['BackgroundShortcut'])
initShortcuts(settings['Shortcut'], settings['BackgroundShortcut'], settings['MuteShortcut'])

initListViewShortcut()
initForInbox()
})
Expand Down Expand Up @@ -51,9 +52,10 @@ function initOnHashChangeAction(domains) {
url = github_links[github_links.length-2].href
muteLink = document.createElement('button')
muteLink.type = 'button'
muteLink.className = 'ithub-mute-button T-I J-J5-Ji lS T-I-ax7 ar7'
muteLink.className = 'github-mute-button T-I J-J5-Ji lS T-I-ax7 ar7'
muteLink.innerText = 'Mute thread'
muteLink.addEventListener('click', function () {
muteLink.innerHTML = '⋯'
fetch(muteURL, {mode: 'no-cors'}).then(function () {
muteLink.innerText = 'Muted!'
muteLink.disabled = 'disabled'
Expand Down Expand Up @@ -93,7 +95,7 @@ function initOnHashChangeAction(domains) {
}
}

function initShortcuts(shortcut, backgroundShortcut) {
function initShortcuts(shortcut, backgroundShortcut, muteShortcut) {
document.addEventListener('keydown', function (event) {
// Shortcut: bind user's combination, if a button exist and event not in a textarea
if (document.querySelector('.gE')) {
Expand All @@ -112,6 +114,11 @@ function initShortcuts(shortcut, backgroundShortcut) {
if (processRightCombinationBasedOnShortcut(backgroundShortcut, event) && window.idled && getVisible(document.getElementsByClassName('github-link')) && notAnInput(event.target)) {
triggerGitHubLink(true)
}

// Mute Shortcut: bind user's combination, if a button exist and event not in a textarea
if (processRightCombinationBasedOnShortcut(muteShortcut, event) && window.idled && getVisible(document.getElementsByClassName('github-mute-button')) && notAnInput(event.target)) {
getVisible(document.getElementsByClassName('github-mute-button')).click()
}
})
}

Expand Down

0 comments on commit 90897df

Please sign in to comment.