`;
for (var type in this.types) {
var choice = BDFDB.loadData(type, this, "choices");
var unimplemented = this.types[type].implemented ? "" : " unimplemented";
settingshtml += `
${this.types[type].name}:
`;
for (var key of fields) {
settingshtml += `
${key}:
${choice[key]}
`;
}
settingshtml += `
volume:
`;
settingshtml += `
`;
}
settingshtml += `
Show unimplemented Sounds
`;
settingshtml += `
Remove all added songs.
`;
settingshtml += `
`;
var settingspanel = $(settingshtml)[0];
BDFDB.initElements(settingspanel);
$(settingspanel)
.on("click", BDFDB.dotCN.selectcontrol, (e) => {this.openDropdownMenu(settingspanel, e);})
.on("click", ".btn-addsong", (e) => {this.saveAudio(settingspanel);})
.on("keyup", ".songInput", (e) => {if (e.which == 13) this.saveAudio(settingspanel);})
.on("click", ".reset-button", () => {this.resetAll(settingspanel);})
.on("click", "#input-unimplemented", (e) => {
$(settingspanel).find(".unimplemented").toggle(e.currentTarget.checked);
})
.on("mousedown", BDFDB.dotCN.slidergrabber, (e) => {this.dragSlider(settingspanel,e);})
.find(".unimplemented").hide();
return settingspanel;
}
//legacy
load () {}
start () {
var libraryScript = null;
if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) {
libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
if (libraryScript) libraryScript.remove();
libraryScript = document.createElement("script");
libraryScript.setAttribute("type", "text/javascript");
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
document.head.appendChild(libraryScript);
}
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize();
else libraryScript.addEventListener("load", () => {this.initialize();});
}
initialize () {
if (typeof BDFDB === "object") {
BDFDB.loadMessage(this);
this.ChannelSettingsModule = BDFDB.WebModules.findByProperties(["isChannelMuted"]);
this.patchCancels.push(BDFDB.WebModules.monkeyPatch(BDFDB.WebModules.findByProperties(["receiveMessage"]), "receiveMessage", {before: (e) => {
if (this.dontPlayAudio()) return;
let message = e.methodArguments[1];
if (message.author.id != BDFDB.myData.id) {
if (!message.guild_id) {
if (!this.ChannelSettingsModule.isChannelMuted(null, message.channel_id)) {
this.fireEvent("dm");
this.playAudio("dm");
}
}
else if (message.mentions) {
for (let mention of message.mentions) if (mention.id == BDFDB.myData.id) {
this.fireEvent("mentioned");
this.playAudio("mentioned");
}
}
}
}}));
this.patchCancels.push(BDFDB.WebModules.monkeyPatch(BDFDB.WebModules.findByProperties(["playSound"]), "playSound", {instead: (e) => {
if (this.dontPlayAudio()) return;
setImmediate(() => {
var type = e.methodArguments[0];
if (type == "message1") {
if (this.firedEvents["dm"]) {
this.firedEvents["dm"] = false;
}
else if (this.firedEvents["mentioned"]) {
this.firedEvents["mentioned"] = false;
}
else this.playAudio(type);
}
else this.playAudio(type);
});
}}));
var incomingCallAudio = new Audio();
this.incomingCallOwnerInstance = BDFDB.getOwnerInstance({"node":document.querySelector(BDFDB.dotCN.callcontainer), "props":["startRinging","stopRinging"], "up":true});
this.oldStartRining = this.incomingCallOwnerInstance.startRinging;
this.oldStopRining = this.incomingCallOwnerInstance.stopRinging;
this.incomingCallOwnerInstance.startRinging = () => {
incomingCallAudio.pause();
if (this.dontPlayAudio()) return;
incomingCallAudio.loop = true;
incomingCallAudio.src = this.choices["call_ringing"].src;
incomingCallAudio.volume = this.choices["call_ringing"].volume/100;
incomingCallAudio.play();
};
this.incomingCallOwnerInstance.stopRinging = () => {incomingCallAudio.pause();};
this.loadAudios();
this.loadChoices();
var observer = null;
observer = new MutationObserver((changes, _) => {
changes.forEach(
(change, i) => {
if (change.addedNodes) {
change.addedNodes.forEach((node) => {
if (node && node.tagName && node.classList.contains(BDFDB.disCN.callcurrentcontainer)) {
if (!this.hasPatchedOutgoing) {
var outgoingCallAudio = new Audio();
let play = () => {
if (this.dontPlayAudio()) return;
outgoingCallAudio.loop = true;
outgoingCallAudio.src = this.choices["call_calling"].src;
outgoingCallAudio.volume = this.choices["call_calling"].volume/100;
outgoingCallAudio.play();
};
let stop = () => {outgoingCallAudio.pause();}
var outgoingCallOwnerInstance = BDFDB.getOwnerInstance({"node":node, "props":["startRinging"], "up":true});
outgoingCallOwnerInstance.stopRinging();
outgoingCallOwnerInstance.startRinging = play;
outgoingCallOwnerInstance.stopRinging = stop;
let CallingWrap = outgoingCallOwnerInstance._reactInternalFiber.type;
this.patchCancels.push(BDFDB.WebModules.monkeyPatch(CallingWrap.prototype, "startRinging", {instead: play}));
this.patchCancels.push(BDFDB.WebModules.monkeyPatch(CallingWrap.prototype, "stopRinging", {instead: stop}));
this.hasPatchedOutgoing = true;
}
}
});
}
}
);
});
BDFDB.addObserver(this, BDFDB.dotCNS.chat, {name:"chatObserver",instance:observer}, {childList:true});
}
else {
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
}
}
stop () {
if (typeof BDFDB === "object") {
if (typeof this.patchCancels === "object") for (let p of this.patchCancels) p();
this.incomingCallOwnerInstance.startRinging = this.oldStartRining;
this.incomingCallOwnerInstance.stopRinging = this.oldStopRining;
BDFDB.unloadMessage(this);
}
}
onSwitch () {
if (typeof BDFDB === "object") {
if (!this.hasPatchedOutgoing) BDFDB.addObserver(this, BDFDB.dotCNS.chat, {name:"chatObserver"}, {childList:true});
}
}
// begin of own functions
resetAll (settingspanel) {
if (confirm("Are you sure you want to delete all added songs?")) {
BDFDB.removeAllData(this, "choices");
BDFDB.removeAllData(this, "audios");
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;
});
}
}
openDropdownMenu (settingspanel, e) {
var selectControl = e.currentTarget;
var selectWrap = selectControl.parentElement;
if (selectWrap.classList.contains(BDFDB.disCN.selectisopen)) return;
selectWrap.classList.add(BDFDB.disCN.selectisopen);
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"]`);
var category = categorySelect.getAttribute("value");
var song = songSelect.getAttribute("value");
var selectMenu = this.createDropdownMenu({type, option, category, song});
selectWrap.appendChild(selectMenu);
$(selectMenu).on("mousedown." + this.getName(), 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;
if (option == "category") {
choice.song = Object.keys(this.audios[selection])[0];
songSelect.outerHTML = `