diff --git a/Plugins/NotificationSounds/NotificationSounds.plugin.js b/Plugins/NotificationSounds/NotificationSounds.plugin.js index 2dee0970a5..11fabb44cb 100644 --- a/Plugins/NotificationSounds/NotificationSounds.plugin.js +++ b/Plugins/NotificationSounds/NotificationSounds.plugin.js @@ -3,7 +3,7 @@ class NotificationSounds { getName () {return "NotificationSounds";} - getVersion () {return "3.2.6";} + getVersion () {return "3.2.7";} getAuthor () {return "DevilBro";} @@ -11,7 +11,7 @@ class NotificationSounds { initConstructor () { this.changelog = { - "fixed":[["Mention/DM sound","Mention and DM sounds no longer play when the message occured in the current channel while Discord is focused"]] + "improved":[["Mention/DM sound","You can now choose whether you want mention/dm sound to play or not, when the channel is open and discord is focused. To change it 'Mute when Channel focused' in the plugin settings for the song type"]] }; this.patchModules = { @@ -20,35 +20,35 @@ class NotificationSounds { }; this.types = { - "message1": {implemented:true, name:"New Chatmessage", src:"/assets/dd920c06a01e5bb8b09678581e29d56f.mp3", mute:true}, - "dm": {implemented:true, name:"Direct Message", src:"/assets/84c9fa3d07da865278bd77c97d952db4.mp3", mute:true}, - "mentioned": {implemented:true, name:"Mention Ping", src:"/assets/a5f42064e8120e381528b14fd3188b72.mp3", mute:true}, - "deafen": {implemented:true, name:"Voicechat Deafen", src:"/assets/e4d539271704b87764dc465b1a061abd.mp3", mute:false}, - "mute": {implemented:true, name:"Voicechat Mute", src:"/assets/429d09ee3b86e81a75b5e06d3fb482be.mp3", mute:false}, - "disconnect": {implemented:true, name:"Voicechat Disconnect", src:"/assets/7e125dc075ec6e5ae796e4c3ab83abb3.mp3", mute:false}, - "undeafen": {implemented:true, name:"Voicechat Undeafen", src:"/assets/5a000a0d4dff083d12a1d4fc2c7cbf66.mp3", mute:false}, - "unmute": {implemented:true, name:"Voicechat Unmute", src:"/assets/43805b9dd757ac4f6b9b58c1a8ee5f0d.mp3", mute:false}, - "user_join": {implemented:true, name:"Voicechat User Joined", src:"/assets/5dd43c946894005258d85770f0d10cff.mp3", mute:false}, - "user_leave": {implemented:true, name:"Voicechat User Left", src:"/assets/4fcfeb2cba26459c4750e60f626cebdc.mp3", mute:false}, - "user_moved": {implemented:true, name:"Voicechat User Moved", src:"/assets/e81d11590762728c1b811eadfa5be766.mp3", mute:false}, - "ptt_start": {implemented:true, name:"Push2Talk Start", src:"/assets/8b63833c8d252fedba6b9c4f2517c705.mp3", mute:false}, - "ptt_stop": {implemented:true, name:"Push2Talk Stop", src:"/assets/74ab980d6890a0fa6aa0336182f9f620.mp3", mute:false}, - "call_calling": {implemented:true, name:"Outgoing Call", src:"/assets/c6e92752668dde4eee5923d70441579f.mp3", mute:false}, - "call_ringing": {implemented:true, name:"Incoming Call", src:"/assets/84a1b4e11d634dbfa1e5dd97a96de3ad.mp3", mute:true}, - "call_ringing_beat": {implemented:false, name:"Incoming Call Beat", src:"/assets/b9411af07f154a6fef543e7e442e4da9.mp3", mute:true}, - "ddr-down": {implemented:true, name:"HotKeys Window Down", src:"/assets/71f048f8aa7d4b24bf4268a87cbbb192.mp3", mute:true}, - "ddr-left": {implemented:true, name:"HotKeys Window Left", src:"/assets/1de04408e62b5d52ae3ebbb91e9e1978.mp3", mute:true}, - "ddr-right": {implemented:true, name:"HotKeys Window Right", src:"/assets/2c0433f93db8449e4a82b76dc520cb29.mp3", mute:true}, - "ddr-up": {implemented:true, name:"HotKeys Window Up", src:"/assets/68472713f7a62c7c37e0a6a5d5a1faeb.mp3", mute:true}, - "human_man": {implemented:false, name:"Human Man Voice", src:"/assets/a37dcd6272ae41cf49295d58c9806fe3.mp3", mute:true}, - "mention1": {implemented:false, name:"Mention Ping 1", src:"/assets/fa4d62c3cbc80733bf1f01b9c6f181de.mp3", mute:true}, - "mention2": {implemented:false, name:"Mention Ping 2", src:"/assets/a5f42064e8120e381528b14fd3188b72.mp3", mute:true}, - "mention3": {implemented:false, name:"Mention Ping 3", src:"/assets/84c9fa3d07da865278bd77c97d952db4.mp3", mute:true}, - "message2": {implemented:false, name:"New Chatmessage 2", src:"/assets/15fe810f6cfab609c7fcda61652b9b34.mp3", mute:true}, - "message3": {implemented:false, name:"New Chatmessage 3", src:"/assets/53ce6a92d3c233e8b4ac529d34d374e4.mp3", mute:true}, - "overlayunlock": {implemented:false, name:"Overlay Unlocked", src:"/assets/ad322ffe0a88436296158a80d5d11baa.mp3", mute:true}, - "reconnect": {implemented:false, name:"Voicechat Reconnect", src:"/assets/471cfd0005b112ff857705e894bf41a6.mp3", mute:true}, - "robot_man": {implemented:false, name:"Robot Man Voice", src:"/assets/66598bea6e59eb8acdf32cf2d9d75ba9.mp3", mute:true} + "message1": {implemented:true, name:"New Chatmessage", src:"/assets/dd920c06a01e5bb8b09678581e29d56f.mp3", mute:true, focus:null}, + "dm": {implemented:true, name:"Direct Message", src:"/assets/84c9fa3d07da865278bd77c97d952db4.mp3", mute:true, focus:true}, + "mentioned": {implemented:true, name:"Mention Ping", src:"/assets/a5f42064e8120e381528b14fd3188b72.mp3", mute:true, focus:true}, + "deafen": {implemented:true, name:"Voicechat Deafen", src:"/assets/e4d539271704b87764dc465b1a061abd.mp3", mute:false, focus:null}, + "mute": {implemented:true, name:"Voicechat Mute", src:"/assets/429d09ee3b86e81a75b5e06d3fb482be.mp3", mute:false, focus:null}, + "disconnect": {implemented:true, name:"Voicechat Disconnect", src:"/assets/7e125dc075ec6e5ae796e4c3ab83abb3.mp3", mute:false, focus:null}, + "undeafen": {implemented:true, name:"Voicechat Undeafen", src:"/assets/5a000a0d4dff083d12a1d4fc2c7cbf66.mp3", mute:false, focus:null}, + "unmute": {implemented:true, name:"Voicechat Unmute", src:"/assets/43805b9dd757ac4f6b9b58c1a8ee5f0d.mp3", mute:false, focus:null}, + "user_join": {implemented:true, name:"Voicechat User Joined", src:"/assets/5dd43c946894005258d85770f0d10cff.mp3", mute:false, focus:null}, + "user_leave": {implemented:true, name:"Voicechat User Left", src:"/assets/4fcfeb2cba26459c4750e60f626cebdc.mp3", mute:false, focus:null}, + "user_moved": {implemented:true, name:"Voicechat User Moved", src:"/assets/e81d11590762728c1b811eadfa5be766.mp3", mute:false, focus:null}, + "ptt_start": {implemented:true, name:"Push2Talk Start", src:"/assets/8b63833c8d252fedba6b9c4f2517c705.mp3", mute:false, focus:null}, + "ptt_stop": {implemented:true, name:"Push2Talk Stop", src:"/assets/74ab980d6890a0fa6aa0336182f9f620.mp3", mute:false, focus:null}, + "call_calling": {implemented:true, name:"Outgoing Call", src:"/assets/c6e92752668dde4eee5923d70441579f.mp3", mute:false, focus:null}, + "call_ringing": {implemented:true, name:"Incoming Call", src:"/assets/84a1b4e11d634dbfa1e5dd97a96de3ad.mp3", mute:true, focus:null}, + "call_ringing_beat": {implemented:false, name:"Incoming Call Beat", src:"/assets/b9411af07f154a6fef543e7e442e4da9.mp3", mute:true, focus:null}, + "ddr-down": {implemented:true, name:"HotKeys Window Down", src:"/assets/71f048f8aa7d4b24bf4268a87cbbb192.mp3", mute:true, focus:null}, + "ddr-left": {implemented:true, name:"HotKeys Window Left", src:"/assets/1de04408e62b5d52ae3ebbb91e9e1978.mp3", mute:true, focus:null}, + "ddr-right": {implemented:true, name:"HotKeys Window Right", src:"/assets/2c0433f93db8449e4a82b76dc520cb29.mp3", mute:true, focus:null}, + "ddr-up": {implemented:true, name:"HotKeys Window Up", src:"/assets/68472713f7a62c7c37e0a6a5d5a1faeb.mp3", mute:true, focus:null}, + "human_man": {implemented:false, name:"Human Man Voice", src:"/assets/a37dcd6272ae41cf49295d58c9806fe3.mp3", mute:true, focus:null}, + "mention1": {implemented:false, name:"Mention Ping 1", src:"/assets/fa4d62c3cbc80733bf1f01b9c6f181de.mp3", mute:true, focus:null}, + "mention2": {implemented:false, name:"Mention Ping 2", src:"/assets/a5f42064e8120e381528b14fd3188b72.mp3", mute:true, focus:null}, + "mention3": {implemented:false, name:"Mention Ping 3", src:"/assets/84c9fa3d07da865278bd77c97d952db4.mp3", mute:true, focus:null}, + "message2": {implemented:false, name:"New Chatmessage 2", src:"/assets/15fe810f6cfab609c7fcda61652b9b34.mp3", mute:true, focus:null}, + "message3": {implemented:false, name:"New Chatmessage 3", src:"/assets/53ce6a92d3c233e8b4ac529d34d374e4.mp3", mute:true, focus:null}, + "overlayunlock": {implemented:false, name:"Overlay Unlocked", src:"/assets/ad322ffe0a88436296158a80d5d11baa.mp3", mute:true, focus:null}, + "reconnect": {implemented:false, name:"Voicechat Reconnect", src:"/assets/471cfd0005b112ff857705e894bf41a6.mp3", mute:true, focus:null}, + "robot_man": {implemented:false, name:"Robot Man Voice", src:"/assets/66598bea6e59eb8acdf32cf2d9d75ba9.mp3", mute:true, focus:null} }; this.defaults = { @@ -99,7 +99,7 @@ class NotificationSounds { this.audios = {}; - this.choices = []; + this.choices = {}; this.firedEvents = {}; } @@ -121,13 +121,14 @@ class NotificationSounds { settingshtml += ``; settingshtml += ``; - for (var type in this.types) { - var choice = BDFDB.loadData(type, this, "choices"); - settingshtml += `

${this.types[type].name}:

Mute in DnD:
`; + for (var type in this.choices) { + settingshtml += `

${this.types[type].name}:

`; + if (this.types[type].focus != null) settingshtml += `
Mute when Channel focused:
`; + settingshtml += `
Mute in DnD:
`; for (var key of fields) { - settingshtml += `
${key}:
${choice[key]}
`; + settingshtml += `
${key}:
${this.choices[type][key]}
`; } - settingshtml += `
volume:
`; + settingshtml += `
volume:
`; settingshtml += `
`; } settingshtml += `

Show unimplemented Sounds

`; @@ -164,8 +165,12 @@ class NotificationSounds { }); BDFDB.addEventListener(this, settingspanel, "click", ".mute-checkbox", e => { var type = e.currentTarget.parentElement.getAttribute("type"); - var choice = BDFDB.loadData(type, this, "choices"); - choice.mute = e.currentTarget.checked; + this.choices[type].mute = e.currentTarget.checked; + this.saveChoice(type, choice, false); + }); + BDFDB.addEventListener(this, settingspanel, "click", ".mutefocus-checkbox", e => { + var type = e.currentTarget.parentElement.getAttribute("type"); + this.choices[type].focus = e.currentTarget.checked; this.saveChoice(type, choice, false); }); BDFDB.addEventListener(this, settingspanel, "click", "#input-unimplemented", e => { @@ -208,12 +213,11 @@ class NotificationSounds { let message = e.methodArguments[1]; let guildid = message.guild_id ? message.guild_id : null; if (!this.ChannelSettingsUtils.isGuildOrCategoryOrChannelMuted(guildid, message.channel_id) && message.author.id != BDFDB.myData.id) { - if (document.hasFocus() && this.LastChannelStore.getChannelId() == message.channel_id) return null; - else if (!guildid) { + if (!guildid && !(this.choices.dm.focus && document.hasFocus() && this.LastChannelStore.getChannelId() == message.channel_id)) { this.fireEvent("dm"); this.playAudio("dm"); } - else if (message.mentions) { + else if (message.mentions && !(this.choices.mentioned.focus && document.hasFocus() && this.LastChannelStore.getChannelId() == message.channel_id)) { for (let mention of message.mentions) if (mention.id == BDFDB.myData.id) { this.fireEvent("mentioned"); this.playAudio("mentioned"); @@ -276,18 +280,17 @@ class NotificationSounds { selectWrap.appendChild(selectMenu); BDFDB.addChildEventListener(selectMenu, "mousedown", BDFDB.dotCN.selectoption, e2 => { - var choice = BDFDB.loadData(type, this, "choices"); var selection = e2.currentTarget.textContent; selectWrap.setAttribute("value", selection); selectControl.querySelector(BDFDB.dotCN.title).innerText = selection; - choice[option] = selection; + this.choices[type][option] = selection; if (option == "category") { - choice.song = Object.keys(this.audios[selection])[0]; - songSelect.outerHTML = `
${choice.song}
`; + this.choices[type].song = Object.keys(this.audios[selection])[0]; + songSelect.outerHTML = `
${this.choices[type].song}
`; } - choice.src = this.audios[choice.category][choice.song]; - choice.src = choice.src ? choice.src : this.types[type].src; - this.saveChoice(type, choice, true); + this.choices[type].src = this.audios[this.choices[type].category][this.choices[type].song]; + this.choices[type].src = this.choices[type].src ? this.choices[type].src : this.types[type].src; + this.saveChoice(type, true); }); var removeMenu = e2 => { @@ -302,11 +305,10 @@ class NotificationSounds { } createDropdownMenu ({type, option, category, song} = data) { - var choice = BDFDB.loadData(type, this, "choices"); var eles = option == "song" ? this.audios[category] : this.audios; var menuhtml = `
`; for (var ele in eles) { - var isSelected = choice[option] == ele ? ` ${BDFDB.disCN.selectselected}` : ``; + var isSelected = this.choices[type][option] == ele ? ` ${BDFDB.disCN.selectselected}` : ``; menuhtml += `
${ele}
` } menuhtml += `
`; @@ -320,7 +322,6 @@ class NotificationSounds { var input = slider.querySelector(".volumeInput"); var bar = slider.querySelector(BDFDB.dotCN.sliderbarfill); var type = slider.getAttribute("type"); - var choice = this.choices[type]; BDFDB.appendLocalStyle("disableTextSelection", `*{user-select: none !important;}`); @@ -329,15 +330,15 @@ class NotificationSounds { var sHalfW = BDFDB.getRects(grabber).width/2; var sMinX = BDFDB.getRects(track).left; var sMaxX = sMinX + BDFDB.getRects(track).width; - var bubble = BDFDB.htmlToElement(`${Math.floor(choice.volume)}%`); + var bubble = BDFDB.htmlToElement(`${Math.floor(this.choices[type].volume)}%`); grabber.appendChild(bubble); var mouseup = () => { document.removeEventListener("mouseup", mouseup); document.removeEventListener("mousemove", mousemove); BDFDB.removeEles(bubble); BDFDB.removeLocalStyle("disableTextSelection"); - choice.volume = volume; - this.saveChoice(type, choice, true); + this.choices[type].volume = volume; + this.saveChoice(type, true); }; var mousemove = e2 => { sY = e2.clientX > sMaxX ? sMaxX - sHalfW : (e2.clientX < sMinX ? sMinX - sHalfW : e2.clientX - sHalfW); @@ -409,29 +410,21 @@ class NotificationSounds { loadChoices () { for (var type in this.types) { - var choice = BDFDB.loadData(type, this, "choices"); - choice = choice ? choice : {}; - - var songFound = false; - for (var category in this.audios) { - if (choice.category == category) { - for (var song in this.audios[category]) { - if (choice.song == song) { - songFound = true; - break; - } - } - } + var choice = BDFDB.loadData(type, this, "choices") || {}, songFound = false; + for (var category in this.audios) if (choice.category == category) for (var song in this.audios[category]) if (choice.song == song) { + songFound = true; + break; } - if (!songFound) choice = {category:"---",song:"---",volume:100,src:this.types[type].src,mute:this.types[type].mute}; - if (typeof choice.mute == "undefined") choice.mute = this.types[type].mute; - this.saveChoice(type, choice, false); + if (!songFound) choice = {category:"---",song:"---",volume:100,src:this.types[type].src,mute:this.types[type].mute,focus:this.types[type].focus}; + if (typeof choice.focus == "undefined") choice.focus = this.types[type].focus; + this.choices[type] = choice; + this.saveChoice(type, false); } } - saveChoice (type, choice, play) { - BDFDB.saveData(type, choice, this, "choices"); - this.choices[type] = choice; + saveChoice (type, play) { + if (!this.choices[type]) return; + BDFDB.saveData(type, this.choices[type], this, "choices"); if (play) this.playAudio(type, this.settingsaudio); }