BetterDiscordAddons/Plugins/NotificationSounds/NotificationSounds.plugin.js

508 lines
32 KiB
JavaScript
Raw Normal View History

2019-09-20 22:32:52 +02:00
//META{"name":"NotificationSounds","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/NotificationSounds","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/NotificationSounds/NotificationSounds.plugin.js"}*//
2018-10-11 10:21:26 +02:00
class NotificationSounds {
2019-01-17 23:48:29 +01:00
getName () {return "NotificationSounds";}
2020-01-09 13:06:41 +01:00
getVersion () {return "3.3.6";}
2019-01-17 23:48:29 +01:00
getAuthor () {return "DevilBro";}
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
getDescription () {return "Allows you to replace the native sounds of Discord with your own";}
2019-01-26 22:45:19 +01:00
2019-09-04 12:34:02 +02:00
constructor () {
2019-02-08 19:21:01 +01:00
this.changelog = {
2020-01-09 13:06:41 +01:00
"fixed":[["DMs & Mentioned","Notificationsounds for DMs and Mentions work again"]]
2019-02-08 19:21:01 +01:00
};
2019-09-04 12:34:02 +02:00
2019-11-14 17:56:26 +01:00
this.patchedModules = {
after: {
"IncomingCalls":"componentDidMount",
"StandardSidebarView":"componentWillUnmount"
}
};
2019-09-04 12:34:02 +02:00
}
initConstructor () {
2019-01-26 22:45:19 +01:00
2019-03-04 17:10:59 +01:00
/* NEVER CHANGE THE SRC LINKS IN THE PLUGIN FILE, TO ADD NEW SONGS ADD THEM IN THE SETTINGS GUI IN THE PLUGINS PAGE */
2018-10-11 10:21:26 +02:00
this.types = {
2019-02-11 13:11:38 +01:00
"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},
2020-01-09 13:06:41 +01:00
"mentioned": {implemented:true, name:"Mentioned", src:"/assets/a5f42064e8120e381528b14fd3188b72.mp3", mute:true, focus:true},
2019-02-11 13:11:38 +01:00
"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},
2020-01-09 13:06:41 +01:00
"reconnect": {implemented:false, name:"Voicechat Reconnect", src:"/assets/471cfd0005b112ff857705e894bf41a6.mp3", mute:true, focus:null},
2019-02-11 13:11:38 +01:00
"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},
2020-01-09 13:06:41 +01:00
"stream_started": {implemented:true, name:"Stream Started", src:"/assets/9ca817f41727edc1b2f1bc4f1911107c.mp3", mute:false, focus:null},
"stream_ended": {implemented:true, name:"Stream Ended", src:"/assets/4e30f98aa537854f79f49a76af822bbc.mp3", mute:false, focus:null},
"stream_user_joined": {implemented:true, name:"Stream User Joined", src:"/assets/5827bbf9a67c61cbb0e02ffbf434b654.mp3", mute:false, focus:null},
"stream_user_left": {implemented:true, name:"Stream User Left", src:"/assets/7cdcdcbc426cc43583365a671c24b740.mp3", mute:false, focus:null},
"ddr-down": {implemented:true, name:"HotKeys Window Down", src:"/assets/71f048f8aa7d4b24bf4268a87cbbb192.mp3", mute:false, focus:null},
"ddr-left": {implemented:true, name:"HotKeys Window Left", src:"/assets/1de04408e62b5d52ae3ebbb91e9e1978.mp3", mute:false, focus:null},
"ddr-right": {implemented:true, name:"HotKeys Window Right", src:"/assets/2c0433f93db8449e4a82b76dc520cb29.mp3", mute:false, focus:null},
"ddr-up": {implemented:true, name:"HotKeys Window Up", src:"/assets/68472713f7a62c7c37e0a6a5d5a1faeb.mp3", mute:false, focus:null},
"mention1": {implemented:false, name:"Mention Ping", src:"/assets/fa4d62c3cbc80733bf1f01b9c6f181de.mp3", mute:true, focus:null},
2019-02-11 13:11:38 +01:00
"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},
2020-01-09 13:06:41 +01:00
"human_man": {implemented:false, name:"Human Man Voice", src:"/assets/a37dcd6272ae41cf49295d58c9806fe3.mp3", mute:true, focus:null},
"robot_man": {implemented:false, name:"Robot Man Voice", src:"/assets/66598bea6e59eb8acdf32cf2d9d75ba9.mp3", mute:true, focus:null},
"discodo": {implemented:false, name:"Unknown", src:"/assets/ae7d16bb2eea76b9b9977db0fad66658.mp3", mute:true, focus:null},
"overlayunlock": {implemented:false, name:"Overlay Unlocked", src:"/assets/ad322ffe0a88436296158a80d5d11baa.mp3", mute:true, focus:null}
2018-10-11 10:21:26 +02:00
};
2019-01-26 22:45:19 +01:00
2019-03-04 17:10:59 +01:00
/* NEVER CHANGE THE SRC LINKS IN THE PLUGIN FILE, TO ADD NEW SONGS ADD THEM IN THE SETTINGS GUI IN THE PLUGINS PAGE */
2018-10-11 10:21:26 +02:00
this.defaults = {
"---": {
"---": null
},
"Default": {
"Communication Channel": "https://notificationsounds.com/soundfiles/63538fe6ef330c13a05a3ed7e599d5f7/file-sounds-917-communication-channel.wav",
"Isn't it": "https://notificationsounds.com/soundfiles/ba2fd310dcaa8781a9a652a31baf3c68/file-sounds-969-isnt-it.wav",
"Job Done": "https://notificationsounds.com/soundfiles/5b69b9cb83065d403869739ae7f0995e/file-sounds-937-job-done.wav",
"Served": "https://notificationsounds.com/soundfiles/b337e84de8752b27eda3a12363109e80/file-sounds-913-served.wav",
"Solemn": "https://notificationsounds.com/soundfiles/53fde96fcc4b4ce72d7739202324cd49/file-sounds-882-solemn.wav",
"System Fault": "https://notificationsounds.com/soundfiles/ebd9629fc3ae5e9f6611e2ee05a31cef/file-sounds-990-system-fault.wav",
"You wouldn't believe": "https://notificationsounds.com/soundfiles/087408522c31eeb1f982bc0eaf81d35f/file-sounds-949-you-wouldnt-believe.wav"
},
2020-01-09 13:06:41 +01:00
"Discord": {}
2018-10-11 10:21:26 +02:00
};
2020-01-09 13:06:41 +01:00
for (let id in this.types) if (id != "dm" && id != "mentioned") this.defaults.Discord[this.types[id].name] = this.types[id].src;
this.defaults.Discord = BDFDB.ObjectUtils.sort(this.defaults.Discord);
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
this.orderTypes = {"category":true, "song":true};
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.settingsaudio = new Audio();
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.audios = {};
2019-01-26 22:45:19 +01:00
2019-02-11 13:11:38 +01:00
this.choices = {};
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.firedEvents = {};
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
getSettingsPanel () {
2019-01-22 11:28:32 +01:00
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
2019-01-26 22:45:19 +01:00
2019-10-09 14:18:28 +02:00
var settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.titlesize18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
2019-01-26 22:45:19 +01:00
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="add-new-song-settings"><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 0 0 auto;">Add New Song:</h3></div>`;
2019-10-08 11:51:41 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">`;
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCN.flexchild}" style="flex: 1 1 50%;"><h5 class="${BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin + BDFDB.disCN.marginbottom4}">Categoryname:</h5><div class="${BDFDB.disCNS.inputwrapper + BDFDB.disCNS.vertical + BDFDB.disCNS.flex2 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;"><input type="text" placeholder="Category" class="${BDFDB.disCNS.inputdefault + BDFDB.disCNS.input + BDFDB.disCN.titlesize16} songInput" id="input-category"></div></div>`;
settingshtml += `<div class="${BDFDB.disCN.flexchild}" style="flex: 1 1 50%;"><h5 class="${BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin + BDFDB.disCN.marginbottom4}">Songname:</h5><div class="${BDFDB.disCNS.inputwrapper + BDFDB.disCNS.vertical + BDFDB.disCNS.flex2 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;"><input type="text" placeholder="Name" class="${BDFDB.disCNS.inputdefault + BDFDB.disCNS.input + BDFDB.disCN.titlesize16} songInput" id="input-song"></div></div>`;
2018-10-11 10:21:26 +02:00
settingshtml += `</div>`;
2019-10-08 11:51:41 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">`;
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCN.flexchild}" style="flex: 1 1 auto;"><h5 class="${BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin + BDFDB.disCN.marginbottom4}">File:</h5><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCN.nowrap}" style="flex: 1 1 auto;"><div class="${BDFDB.disCNS.inputwrapper + BDFDB.disCNS.vertical + BDFDB.disCNS.flex2 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;"><input type="text" placeholder="Url or Filepath" class="${BDFDB.disCNS.inputdefault + BDFDB.disCNS.input + BDFDB.disCN.titlesize16} songInput" id="input-url"></div><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} file-navigator" id="input-file" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}"></div><input type="file" accept="audio/*,video/*" style="display:none!important;"></button><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorbrand + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} btn-add btn-addsong" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}"></div></button></div></div>`;
2018-10-11 10:21:26 +02:00
settingshtml += `</div>`;
settingshtml += `</div>`;
2019-01-26 22:45:19 +01:00
2019-02-11 13:11:38 +01:00
for (var type in this.choices) {
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${type}-song-settings${this.types[type].implemented ? '"' : ' unimplemented" style="display: none !important;"'}><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.types[type].name}:</h3>`;
if (this.types[type].focus != null) settingshtml += `<h5 class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin}" style="flex: 0 0 auto;">Mute when Channel focused:</h5><div type="${type}" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} mutefocus-checkbox"${this.choices[type].focus ? " checked" : ""}></div>`;
settingshtml += `<h5 class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin}" style="flex: 0 0 auto;">Mute in DnD:</h5><div type="${type}" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} mutednd-checkbox"${this.choices[type].mute ? " checked" : ""}></div></div><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;">`;
2019-02-16 12:33:52 +01:00
for (var key of ["category","song"]) {
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCN.flexchild}" style="flex: 1 1 33%;"><h5 class="${BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin + BDFDB.disCN.marginbottom4}">${key}:</h5>${BDFDB.createSelectMenu(this.createSelectChoice(this.choices[type][key]), this.choices[type][key], type + " " + key)}</div>`;
2018-10-11 10:21:26 +02:00
}
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCN.flexchild}" style="flex: 1 1 33%;"><h5 class="${BDFDB.disCNS.h5 + BDFDB.disCNS.title + BDFDB.disCNS.titlesize12 + BDFDB.disCNS.height16 + BDFDB.disCNS.weightsemibold + BDFDB.disCNS.h5defaultmargin + BDFDB.disCN.marginbottom4}">volume:</h5><div type="${type}" class="${BDFDB.disCN.slider}"><input type="number" class="${type}-volume ${BDFDB.disCN.sliderinput} volumeInput" value="${this.choices[type].volume}" readonly=""><div class="${BDFDB.disCN.sliderbar}"><div class="${BDFDB.disCN.sliderbarfill}" style="width: ${this.choices[type].volume}%;"></div></div><div class="${BDFDB.disCN.slidertrack}"><div class="${BDFDB.disCN.slidergrabber}" style="left: ${this.choices[type].volume}%;"></div></div></div></div>`;
2018-10-11 10:21:26 +02:00
settingshtml += `</div></div>`;
}
2019-10-09 14:18:28 +02:00
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Show unimplemented Sounds</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner}" id="input-unimplemented"></div></div>`;
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom20}" style="flex: 0 0 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.titlesize16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">Remove all added songs.</h3><button type="button" class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.button + BDFDB.disCNS.buttonlookfilled + BDFDB.disCNS.buttoncolorred + BDFDB.disCNS.buttonsizemedium + BDFDB.disCN.buttongrow} reset-button" style="flex: 0 0 auto;"><div class="${BDFDB.disCN.buttoncontents}">Reset</div></button></div>`;
2018-10-11 10:21:26 +02:00
settingshtml += `</div></div>`;
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
let settingspanel = BDFDB.DOMUtils.create(settingshtml);
2018-10-11 10:21:26 +02:00
2019-01-17 23:48:29 +01:00
BDFDB.initElements(settingspanel, this);
2018-10-11 10:21:26 +02:00
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".btn-addsong", e => {this.saveAudio(settingspanel);});
BDFDB.ListenerUtils.add(this, settingspanel, "keyup", ".songInput", e => {if (e.which == 13) this.saveAudio(settingspanel);});
2020-01-14 00:06:07 +01:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".reset-button", _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to delete all added songs?", _ => {
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.remove(this, "choices");
BDFDB.DataUtils.remove(this, "audios");
2019-01-17 23:48:29 +01:00
this.loadAudios();
this.loadChoices();
settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach(wrap => {
wrap.setAttribute("value", "---");
wrap.querySelector(BDFDB.dotCN.title).innerText = "---";
});
settingspanel.querySelectorAll(BDFDB.dotCN.slidergrabber).forEach(grabber => {
grabber.style.left = "100%";
});
settingspanel.querySelectorAll(BDFDB.dotCN.sliderbarfill).forEach(bar => {
bar.style.width = "100%";
});
settingspanel.querySelectorAll(".volumeInput").forEach(input => {
input.value = 100;
});
2019-01-17 23:48:29 +01:00
});
});
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".mutednd-checkbox", e => {
2019-01-17 23:48:29 +01:00
var type = e.currentTarget.parentElement.getAttribute("type");
2019-02-11 13:11:38 +01:00
this.choices[type].mute = e.currentTarget.checked;
2019-02-13 13:35:30 +01:00
this.saveChoice(type, false);
2019-02-11 13:11:38 +01:00
});
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", ".mutefocus-checkbox", e => {
2019-02-11 13:11:38 +01:00
var type = e.currentTarget.parentElement.getAttribute("type");
this.choices[type].focus = e.currentTarget.checked;
2019-02-13 13:35:30 +01:00
this.saveChoice(type, false);
2019-01-17 23:48:29 +01:00
});
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "click", "#input-unimplemented", e => {
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.toggle(settingspanel.querySelectorAll(".unimplemented"), e.currentTarget.checked);
2019-01-17 23:48:29 +01:00
});
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.add(this, settingspanel, "mousedown", BDFDB.dotCN.slidergrabber, e => {this.dragSlider(settingspanel,e);});
BDFDB.ListenerUtils.add(this, settingspanel, "click", BDFDB.dotCN.selectcontrol, e => {
2019-10-23 11:10:01 +02:00
let type = BDFDB.DOMUtils.getParent(BDFDB.dotCN.select, e.currentTarget).getAttribute("type").split(" ");
2019-04-27 18:45:01 +02:00
let songSelect = settingspanel.querySelector(`${BDFDB.dotCN.select}[type="${type[0]} song"]`);
let categorySelect = settingspanel.querySelector(`${BDFDB.dotCN.select}[type="${type[0]} category"]`);
let menuaudios = type[1] == "song" ? this.audios[categorySelect.getAttribute("value")] : this.audios;
2019-09-24 12:48:53 +02:00
BDFDB.openDropdownMenu(e, this.saveSelectChoice.bind(this), this.createSelectChoice.bind(this), menuaudios);
2019-04-27 18:45:01 +02:00
});
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
return settingspanel;
}
//legacy
load () {}
start () {
2019-02-04 09:13:15 +01:00
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
2019-05-26 13:55:26 +02:00
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
2018-10-11 10:21:26 +02:00
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
2019-05-26 13:55:26 +02:00
libraryScript.setAttribute("id", "BDFDBLibraryScript");
2018-10-11 10:21:26 +02:00
libraryScript.setAttribute("type", "text/javascript");
2019-10-18 10:56:41 +02:00
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
2019-01-17 23:48:29 +01:00
libraryScript.setAttribute("date", performance.now());
2020-01-14 00:06:07 +01:00
libraryScript.addEventListener("load", _ => {this.initialize();});
2018-10-11 10:21:26 +02:00
document.head.appendChild(libraryScript);
}
2019-01-17 23:48:29 +01:00
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
2020-01-14 00:06:07 +01:00
this.startTimeout = setTimeout(_ => {
2019-11-01 10:27:07 +01:00
try {return this.initialize();}
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
}, 30000);
2018-10-11 10:21:26 +02:00
}
initialize () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-01-22 11:05:54 +01:00
if (this.started) return;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.init(this);
2019-01-26 22:45:19 +01:00
2020-01-09 13:06:41 +01:00
BDFDB.ModuleUtils.patch(this, BDFDB.LibraryModules.DispatchApiUtils, "dirtyDispatch", {before: e => {
if (BDFDB.ObjectUtils.is(e.methodArguments[0]) && e.methodArguments[0].type == BDFDB.DiscordConstants.ActionTypes.MESSAGE_CREATE && e.methodArguments[0].message) {
let message = e.methodArguments[0].message;
let guildId = message.guild_id || null;
if (!BDFDB.LibraryModules.MutedUtils.isGuildOrCategoryOrChannelMuted(guildId, message.channel_id) && message.author.id != BDFDB.UserUtils.me.id) {
if (!guildId && !(this.choices.dm.focus && document.hasFocus() && BDFDB.LibraryModules.LastChannelStore.getChannelId() == message.channel_id)) {
this.fireEvent("dm");
this.playAudio("dm");
}
else if (message.mentions && !(this.choices.mentioned.focus && document.hasFocus() && BDFDB.LibraryModules.LastChannelStore.getChannelId() == message.channel_id)) for (let mention of message.mentions) if (mention.id == BDFDB.UserUtils.me.id) {
2018-10-11 10:21:26 +02:00
this.fireEvent("mentioned");
this.playAudio("mentioned");
break;
2018-10-11 10:21:26 +02:00
}
}
}
2018-12-20 22:42:59 +01:00
}});
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.patch(this, BDFDB.LibraryModules.SoundUtils, "playSound", {instead: e => {
2019-08-19 11:34:12 +02:00
let type = e.methodArguments[0];
2020-01-14 00:06:07 +01:00
if (this.choices[type]) BDFDB.TimeUtils.timeout(_ => {
2018-10-11 10:21:26 +02:00
if (type == "message1") {
if (this.firedEvents["dm"]) this.firedEvents["dm"] = false;
else if (this.firedEvents["mentioned"]) this.firedEvents["mentioned"] = false;
2018-10-11 10:21:26 +02:00
else this.playAudio(type);
}
else this.playAudio(type);
});
2019-08-19 11:32:22 +02:00
else e.callOriginalMethod();
2018-12-20 22:42:59 +01:00
}});
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.patch(this, BDFDB.LibraryModules.SoundUtils, "createSound", {after: e => {
2019-04-11 14:24:08 +02:00
let type = e.methodArguments[0];
let audio = new Audio();
audio.src = this.choices[type].src;
audio.volume = this.choices[type].volume/100;
2020-01-14 00:06:07 +01:00
e.returnValue.play = _ => {
2019-04-11 14:24:08 +02:00
if (!audio.paused || this.dontPlayAudio(type)) return;
audio.loop = false;
audio.play();
};
2020-01-14 00:06:07 +01:00
e.returnValue.loop = _ => {
2019-04-11 14:24:08 +02:00
if (!audio.paused || this.dontPlayAudio(type)) return;
audio.loop = true;
audio.play();
};
2020-01-14 00:06:07 +01:00
e.returnValue.stop = _ => {audio.pause();}
2019-04-11 14:24:08 +02:00
}});
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
this.loadAudios();
this.loadChoices();
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.forceAllUpdates(this);
2018-10-11 10:21:26 +02:00
}
2019-11-01 10:14:50 +01:00
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
2018-10-11 10:21:26 +02:00
}
stop () {
2019-01-17 23:48:29 +01:00
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
2019-10-22 11:37:23 +02:00
this.stopping = true;
2019-10-22 18:55:25 +02:00
BDFDB.PluginUtils.clear(this);
2019-03-04 17:10:59 +01:00
this.settingsaudio.pause();
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
// begin of own functions
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
openDropdownMenu (settingspanel, e) {
2019-01-17 23:48:29 +01:00
let selectControl = e.currentTarget;
let selectWrap = selectControl.parentElement;
2019-10-23 11:10:01 +02:00
let plugincard = BDFDB.DOMUtils.getParent("li", selectWrap);
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
if (!plugincard || BDFDB.DOMUtils.containsClass(selectWrap, BDFDB.disCN.selectisopen)) return;
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.addClass(selectWrap, BDFDB.disCN.selectisopen);
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
var type = selectWrap.getAttribute("type");
var option = selectWrap.getAttribute("option");
var categorySelect = settingspanel.querySelector(`${BDFDB.dotCN.select}[type="${type}"][option="category"]`);
var songSelect = settingspanel.querySelector(`${BDFDB.dotCN.select}[type="${type}"][option="song"]`);
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
var category = categorySelect.getAttribute("value");
var song = songSelect.getAttribute("value");
2019-01-26 22:45:19 +01:00
2019-02-16 12:33:52 +01:00
var selectMenu = this.createDropdownMenu(type, option, category, song);
2018-10-11 10:21:26 +02:00
selectWrap.appendChild(selectMenu);
2019-01-26 22:45:19 +01:00
2019-10-22 18:55:25 +02:00
BDFDB.ListenerUtils.addToChildren(selectMenu, "mousedown", BDFDB.dotCN.selectoption, e2 => {
2018-10-11 10:21:26 +02:00
var selection = e2.currentTarget.textContent;
selectWrap.setAttribute("value", selection);
2019-04-27 18:45:01 +02:00
selectWrap.querySelector(BDFDB.dotCN.title).innerText = selection;
2019-02-11 13:11:38 +01:00
this.choices[type][option] = selection;
2018-10-11 10:21:26 +02:00
if (option == "category") {
2019-02-11 13:11:38 +01:00
this.choices[type].song = Object.keys(this.audios[selection])[0];
2019-10-08 11:51:41 +02:00
songSelect.outerHTML = `<div type="${type}" option="song" value="${this.choices[type].song}" class="${BDFDB.disCNS.select + BDFDB.disCNS.selectsingle + BDFDB.disCN.selecthasvalue}"><div class="${BDFDB.disCN.selectcontrol}"><div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignbaseline + BDFDB.disCNS.nowrap + BDFDB.disCN.selectvalue}" style="flex: 1 1 auto;"><div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCN.weightnormal}" style="padding:0;">${this.choices[type].song}</div></div><span class="${BDFDB.disCN.selectarrowzone}"><span class="${BDFDB.disCN.selectarrow}"></span></span></div></div>`;
2018-10-11 10:21:26 +02:00
}
2019-02-11 13:11:38 +01:00
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);
2018-10-11 10:21:26 +02:00
});
2019-01-26 22:45:19 +01:00
2019-01-17 23:48:29 +01:00
var removeMenu = e2 => {
if (e2.target.parentElement != selectMenu) {
document.removeEventListener("mousedown", removeMenu);
selectMenu.remove();
2020-01-14 00:06:07 +01:00
BDFDB.TimeUtils.timeout(_ => {BDFDB.DOMUtils.removeClass(selectWrap, BDFDB.disCN.selectisopen);},100);
2019-01-17 23:48:29 +01:00
}
};
document.addEventListener("mousedown", removeMenu);
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-02-16 12:33:52 +01:00
createDropdownMenu (type, option, category, song) {
2018-10-11 10:21:26 +02:00
var eles = option == "song" ? this.audios[category] : this.audios;
var menuhtml = `<div class="${BDFDB.disCN.selectmenuouter}"><div class="${BDFDB.disCN.selectmenu}">`;
for (var ele in eles) {
2019-02-11 13:11:38 +01:00
var isSelected = this.choices[type][option] == ele ? ` ${BDFDB.disCN.selectselected}` : ``;
2019-10-08 11:51:41 +02:00
menuhtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.horizontal + BDFDB.disCNS.justifystart + BDFDB.disCNS.alignbaseline + BDFDB.disCNS.nowrap + BDFDB.disCN.selectoption + isSelected}" style="flex: 1 1 auto;"><div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCN.weightnormal}">${ele}</div></div>`
2018-10-11 10:21:26 +02:00
}
menuhtml += `</div></div>`;
2019-10-23 11:10:01 +02:00
return BDFDB.DOMUtils.create(menuhtml);
2018-10-11 10:21:26 +02:00
}
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
saveSelectChoice (selectWrap, type, choice) {
if (type && choice) {
selectWrap.querySelector(BDFDB.dotCN.title).innerText = choice;
type = type.split(" ");
this.choices[type[0]][type[1]] = choice;
if (type[1] == "category") {
this.choices[type[0]].song = Object.keys(this.audios[choice])[0];
2019-10-23 11:10:01 +02:00
var settingspanel = BDFDB.DOMUtils.getParent(".BDFDB-settings", selectWrap), songSelect = settingspanel ? settingspanel.querySelector(`${BDFDB.dotCN.select}[type="${type[0]} song"]`) : null;
2019-04-27 18:45:01 +02:00
if (songSelect) songSelect.outerHTML = BDFDB.createSelectMenu(this.createSelectChoice(this.choices[type[0]].song), this.choices[type[0]].song, type[0] + " song");
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
}
this.choices[type[0]].src = this.audios[this.choices[type[0]].category][this.choices[type[0]].song];
this.choices[type[0]].src = this.choices[type[0]].src ? this.choices[type[0]].src : this.types[type[0]].src;
this.saveChoice(type[0], true);
}
}
2019-09-04 12:34:02 +02:00
2019-04-27 18:45:01 +02:00
createSelectChoice (key) {
2019-09-11 12:14:43 +02:00
return `<div class="${BDFDB.disCNS.title + BDFDB.disCNS.medium + BDFDB.disCNS.primary + BDFDB.disCNS.weightnormal + BDFDB.disCN.cursorpointer}" style="padding: 0;">${key}</div>`;
2019-04-27 18:45:01 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
dragSlider (settingspanel, e) {
2019-01-29 17:06:35 +01:00
var grabber = e.currentTarget;
2018-10-11 10:21:26 +02:00
var track = grabber.parentNode;
var slider = track.parentNode;
2019-04-11 13:23:00 +02:00
var input = slider.querySelector(BDFDB.dotCN.sliderinput);
2018-10-11 10:21:26 +02:00
var bar = slider.querySelector(BDFDB.dotCN.sliderbarfill);
2019-01-29 17:06:35 +01:00
var type = slider.getAttribute("type");
2019-01-26 22:45:19 +01:00
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.appendLocalStyle("disableTextSelection", `*{user-select: none !important;}`);
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
var volume = 0;
var sY = 0;
2019-10-23 11:10:01 +02:00
var sHalfW = BDFDB.DOMUtils.getRects(grabber).width/2;
var sMinX = BDFDB.DOMUtils.getRects(track).left;
var sMaxX = sMinX + BDFDB.DOMUtils.getRects(track).width;
var bubble = BDFDB.DOMUtils.create(`<span class="${BDFDB.disCN.sliderbubble}">${Math.floor(this.choices[type].volume)}%</span>`);
2019-01-29 17:06:35 +01:00
grabber.appendChild(bubble);
2020-01-14 00:06:07 +01:00
var mouseup = _ => {
2019-01-17 23:48:29 +01:00
document.removeEventListener("mouseup", mouseup);
document.removeEventListener("mousemove", mousemove);
2019-10-23 11:10:01 +02:00
BDFDB.DOMUtils.remove(bubble);
BDFDB.DOMUtils.removeLocalStyle("disableTextSelection");
2019-02-11 13:11:38 +01:00
this.choices[type].volume = volume;
this.saveChoice(type, true);
2019-01-17 23:48:29 +01:00
};
var mousemove = e2 => {
sY = e2.clientX > sMaxX ? sMaxX - sHalfW : (e2.clientX < sMinX ? sMinX - sHalfW : e2.clientX - sHalfW);
2019-10-23 11:10:01 +02:00
volume = BDFDB.NumberUtils.mapRange([sMinX - sHalfW, sMaxX - sHalfW], [0, 100], sY);
2019-01-17 23:48:29 +01:00
grabber.style.setProperty("left", volume + "%");
bar.style.setProperty("width", volume + "%");
input.value = volume;
2019-01-29 17:06:35 +01:00
bubble.innerText = Math.floor(volume) + "%";
2019-01-17 23:48:29 +01:00
};
document.addEventListener("mouseup", mouseup);
document.addEventListener("mousemove", mousemove);
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
loadAudios () {
2019-10-22 19:49:57 +02:00
this.audios = BDFDB.DataUtils.load(this, "audios");
2019-10-22 18:55:25 +02:00
if (BDFDB.ObjectUtils.isEmpty(this.audios)) this.audios = this.defaults;
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(this.audios, this, "audios");
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
saveAudio (settingspanel) {
var valid = true;
var inputs = settingspanel.querySelectorAll(".songInput");
inputs.forEach((input) => {
if (!input.value || input.value.length == 0 || input.value.trim().length == 0) valid = false;
});
if (valid) {
var successSavedAudio;
var category = settingspanel.querySelector("#input-category").value;
var song = settingspanel.querySelector("#input-song").value;
var url = settingspanel.querySelector("#input-url").value;
if (url.indexOf("http") == 0) {
2019-09-11 12:14:43 +02:00
BDFDB.LibraryRequires.request(url, (error, response, result) => {
2018-10-11 10:21:26 +02:00
if (response) {
var type = response.headers["content-type"];
if (type && (type.indexOf("octet-stream") > -1 || type.indexOf("audio") > -1 || type.indexOf("video") > -1)) {
successSavedAudio();
return;
}
}
2019-10-22 18:55:25 +02:00
BDFDB.NotificationUtils.toast("Use a valid direct link to a video or audio source. They usually end on something like .mp3, .mp4 or .wav.", {type:"danger"});
2018-10-11 10:21:26 +02:00
});
}
else {
2019-09-11 12:14:43 +02:00
BDFDB.LibraryRequires.fs.readFile(url, (error, response) => {
2018-10-11 10:21:26 +02:00
if (error) {
2019-10-22 18:55:25 +02:00
BDFDB.NotificationUtils.toast("Could not fetch file. Please make sure the file exists.", {type:"danger"});
2018-10-11 10:21:26 +02:00
}
else {
url = `data:audio/mpeg;base64,${response.toString("base64")}`;
successSavedAudio();
}
});
}
2019-01-26 22:45:19 +01:00
2020-01-14 00:06:07 +01:00
successSavedAudio = _ => {
2019-10-22 18:55:25 +02:00
BDFDB.NotificationUtils.toast(`Song ${song} was added to category ${category}.`, {type:"success"});
2018-10-11 10:21:26 +02:00
if (!this.audios[category]) this.audios[category] = {};
this.audios[category][song] = url;
2019-10-22 19:49:57 +02:00
BDFDB.DataUtils.save(this.audios, this, "audios");
2018-10-11 10:21:26 +02:00
inputs.forEach((input) => {
input.value = "";
});
};
}
2019-10-22 18:55:25 +02:00
else BDFDB.NotificationUtils.toast("Fill out all fields to add a new song.", {type:"danger"});
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
loadChoices () {
for (var type in this.types) {
2019-10-22 20:16:05 +02:00
var choice = BDFDB.DataUtils.load(this, "choices", type) || {}, songFound = false;
2019-02-11 13:11:38 +01:00
for (var category in this.audios) if (choice.category == category) for (var song in this.audios[category]) if (choice.song == song) {
songFound = true;
break;
2018-10-11 10:21:26 +02:00
}
2019-02-11 13:11:38 +01:00
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);
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2019-02-11 13:11:38 +01:00
saveChoice (type, play) {
if (!this.choices[type]) return;
2019-10-22 20:16:05 +02:00
BDFDB.DataUtils.save(this.choices[type], this, "choices", type);
2019-03-04 17:10:59 +01:00
if (play) {
this.SettingsUpdated = true;
this.playAudio(type, this.settingsaudio);
}
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
playAudio (type, audio) {
if (!audio) {
if (this.dontPlayAudio(type)) return;
2019-10-22 19:49:57 +02:00
audio = new Audio();
}
else audio.pause();
2018-10-11 10:21:26 +02:00
audio.src = this.choices[type].src;
audio.volume = this.choices[type].volume/100;
audio.play();
}
2019-01-26 22:45:19 +01:00
dontPlayAudio (type) {
2019-10-22 18:55:25 +02:00
let status = BDFDB.UserUtils.getStatus();
return this.choices[type].mute && (status == "dnd" || status == "streaming");
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2018-10-11 10:21:26 +02:00
fireEvent (type) {
this.firedEvents[type] = true;
2020-01-14 00:06:07 +01:00
BDFDB.TimeUtils.timeout(_ => {this.firedEvents[type] = false;},3000);
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processIncomingCalls (instance, wrapper, returnvalue) {
let audio = new Audio();
2020-01-14 00:06:07 +01:00
let play = _ => {
2019-04-11 14:24:08 +02:00
if (!audio.paused || this.dontPlayAudio("call_ringing")) return;
audio.loop = true;
2019-04-11 14:24:08 +02:00
audio.src = this.choices["call_ringing"].src;
audio.volume = this.choices["call_ringing"].volume/100;
audio.play();
};
2020-01-14 00:06:07 +01:00
let stop = _ => {audio.pause();}
2019-10-22 18:55:25 +02:00
BDFDB.ModuleUtils.patch(this, instance, "startRinging", {instead: play});
BDFDB.ModuleUtils.patch(this, instance, "stopRinging", {instead: stop});
BDFDB.ModuleUtils.patch(this, instance._reactInternalFiber.type.prototype, "startRinging", {instead: play});
BDFDB.ModuleUtils.patch(this, instance._reactInternalFiber.type.prototype, "stopRinging", {instead: stop});
}
2019-01-26 22:45:19 +01:00
2019-09-11 12:14:43 +02:00
processStandardSidebarView (instance, wrapper, returnvalue) {
2019-03-04 17:10:59 +01:00
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.settingsaudio.pause();
}
}
2018-10-11 10:21:26 +02:00
}