EditServers and RepoControls now use patching instead of observing
This commit is contained in:
parent
a4054b3061
commit
512b8bbe33
|
@ -122,10 +122,10 @@ class EditChannels {
|
|||
$(settingspanel)
|
||||
.on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);})
|
||||
.on("click", ".reset-button", () => {
|
||||
if (confirm("Are you sure you want to reset all channels?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to reset all channels?", () => {
|
||||
BDFDB.removeAllData(this, "channels");
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
}
|
||||
});
|
||||
});
|
||||
return settingspanel;
|
||||
}
|
||||
|
@ -226,12 +226,7 @@ class EditChannels {
|
|||
}
|
||||
|
||||
showChannelSettings (info) {
|
||||
var channelObj = BDFDB.getDivOfChannel(info.id);
|
||||
|
||||
var data = BDFDB.loadData(info.id, this, "channels");
|
||||
|
||||
var name = data ? data.name : null;
|
||||
var color = data ? data.color : null;
|
||||
var {name,color} = BDFDB.loadData(info.id, this, "channels") || {}
|
||||
|
||||
var channelSettingsModal = $(this.channelSettingsModalMarkup);
|
||||
channelSettingsModal.find(BDFDB.dotCN.modalguildname).text(info.name);
|
||||
|
|
|
@ -4,7 +4,11 @@ class EditServers {
|
|||
initConstructor () {
|
||||
this.labels = {};
|
||||
|
||||
this.serverDragged = false;
|
||||
this.patchModules = {
|
||||
"GuildIcon":"componentDidMount",
|
||||
"GuildHeader":["componentDidMount","componentDidUpdate"],
|
||||
"Clickable":"componentDidMount"
|
||||
};
|
||||
|
||||
this.serverContextEntryMarkup =
|
||||
`<div class="${BDFDB.disCN.contextmenuitemgroup}">
|
||||
|
@ -116,7 +120,7 @@ class EditServers {
|
|||
|
||||
getDescription () {return "Allows you to change the icon, name and color of servers.";}
|
||||
|
||||
getVersion () {return "1.8.8";}
|
||||
getVersion () {return "1.8.9";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
|
@ -131,7 +135,12 @@ class EditServers {
|
|||
BDFDB.initElements(settingspanel);
|
||||
|
||||
$(settingspanel)
|
||||
.on("click", ".reset-button", () => {this.resetAll();});
|
||||
.on("click", ".reset-button", () => {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to reset all servers?", () => {
|
||||
BDFDB.removeAllData(this, "servers");
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
});
|
||||
});
|
||||
return settingspanel;
|
||||
}
|
||||
|
||||
|
@ -157,45 +166,9 @@ class EditServers {
|
|||
if (typeof BDFDB === "object") {
|
||||
BDFDB.loadMessage(this);
|
||||
|
||||
var observer = null;
|
||||
|
||||
observer = new MutationObserver((changes, _) => {
|
||||
changes.forEach(
|
||||
(change, i) => {
|
||||
if (change.addedNodes) {
|
||||
change.addedNodes.forEach((node) => {
|
||||
if (node.nodeType == 1 && node.className.includes(BDFDB.disCN.contextmenu)) {
|
||||
this.onContextMenu(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
BDFDB.addObserver(this, BDFDB.dotCN.appmount, {name:"serverContextObserver",instance:observer}, {childList: true});
|
||||
|
||||
observer = new MutationObserver((changes, _) => {
|
||||
changes.forEach(
|
||||
(change, i) => {
|
||||
var addedNodes = change.addedNodes;
|
||||
if (change.attributeName == "class" && change.oldValue && change.oldValue.indexOf(BDFDB.disCN.guildplaceholder) > -1) addedNodes = [change.target];
|
||||
if (change.attributeName == "draggable" && change.oldValue && change.oldValue == "false") addedNodes = [change.target.parentElement];
|
||||
if (addedNodes) {
|
||||
addedNodes.forEach((node) => {
|
||||
if (node && node.classList && node.classList.contains(BDFDB.disCN.guild) && !node.querySelector(BDFDB.dotCN.guildserror)) {
|
||||
var id = BDFDB.getIdOfServer(node);
|
||||
if (id) this.loadServer(BDFDB.getDivOfServer(id));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
BDFDB.addObserver(this, BDFDB.dotCN.guilds, {name:"serverListObserver",instance:observer}, {childList: true, subtree:true, attributes:true, attributeFilte: ["class", "draggable"], attributeOldValue: true});
|
||||
this.GuildUtils = BDFDB.WebModules.findByProperties("getGuilds","getGuild");
|
||||
|
||||
setTimeout(() => {
|
||||
this.loadAllServers();
|
||||
},3000);
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
}
|
||||
else {
|
||||
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
|
||||
|
@ -204,7 +177,10 @@ class EditServers {
|
|||
|
||||
stop () {
|
||||
if (typeof BDFDB === "object") {
|
||||
document.querySelectorAll("[custom-editservers]").forEach(serverDiv => {this.resetServer(BDFDB.getIdOfServer(serverDiv));});
|
||||
let data = BDFDB.loadAllData(this, "servers");
|
||||
BDFDB.removeAllData(this, "servers");
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
BDFDB.saveAllData(data, this, "servers");
|
||||
|
||||
BDFDB.unloadMessage(this);
|
||||
}
|
||||
|
@ -213,14 +189,6 @@ class EditServers {
|
|||
|
||||
// begin of own functions
|
||||
|
||||
resetAll () {
|
||||
if (confirm("Are you sure you want to reset all servers?")) {
|
||||
BDFDB.removeAllData(this, "servers");
|
||||
|
||||
document.querySelectorAll("[custom-editservers]").forEach(serverDiv => {this.resetServer(BDFDB.getIdOfServer(serverDiv));});
|
||||
}
|
||||
}
|
||||
|
||||
changeLanguageStrings () {
|
||||
this.serverContextEntryMarkup = this.serverContextEntryMarkup.replace("REPLACE_context_localserversettings_text", this.labels.context_localserversettings_text);
|
||||
|
||||
|
@ -242,60 +210,40 @@ class EditServers {
|
|||
this.serverSettingsModalMarkup = this.serverSettingsModalMarkup.replace("REPLACE_btn_save_text", this.labels.btn_save_text);
|
||||
}
|
||||
|
||||
onContextMenu (context) {
|
||||
if (!context || !context.tagName || !context.parentElement || context.querySelector(".localserversettings-item")) return;
|
||||
var info = BDFDB.getKeyInformation({"node":context, "key":"guild"});
|
||||
if (info && BDFDB.getKeyInformation({"node":context, "key":"displayName", "value":"GuildLeaveGroup"})) {
|
||||
$(context).append(this.serverContextEntryMarkup)
|
||||
onGuildContextMenu (instance, menu) {
|
||||
if (instance.props && instance.props.target && instance.props.guild && !menu.querySelector(".localserversettings-item")) {
|
||||
$(this.serverContextEntryMarkup).appendTo(menu)
|
||||
.on("mouseenter", ".localserversettings-item", (e) => {
|
||||
this.createContextSubMenu(info, e, context);
|
||||
});
|
||||
|
||||
BDFDB.updateContextPosition(context);
|
||||
}
|
||||
}
|
||||
|
||||
createContextSubMenu (info, e, context) {
|
||||
var id = info.id;
|
||||
|
||||
var serverContextSubMenu = $(this.serverContextSubMenuMarkup);
|
||||
|
||||
serverContextSubMenu
|
||||
.on("click", ".serversettings-item", () => {
|
||||
$(context).hide();
|
||||
this.showServerSettings(info);
|
||||
});
|
||||
|
||||
if (BDFDB.loadData(id, this, "servers")) {
|
||||
serverContextSubMenu
|
||||
.find(".resetsettings-item")
|
||||
.removeClass(BDFDB.disCN.contextmenuitemdisabled)
|
||||
.on("click", () => {
|
||||
$(context).hide();
|
||||
this.removeServerData(info.id);
|
||||
var serverContextSubMenu = $(this.serverContextSubMenuMarkup);
|
||||
serverContextSubMenu
|
||||
.on("click", ".serversettings-item", () => {
|
||||
instance._reactInternalFiber.return.memoizedProps.closeContextMenu();
|
||||
this.showServerSettings(instance.props.guild);
|
||||
});
|
||||
|
||||
if (BDFDB.loadData(instance.props.guild.id, this, "servers")) {
|
||||
serverContextSubMenu
|
||||
.find(".resetsettings-item")
|
||||
.removeClass(BDFDB.disCN.contextmenuitemdisabled)
|
||||
.on("click", () => {
|
||||
instance._reactInternalFiber.return.memoizedProps.closeContextMenu();
|
||||
BDFDB.removeData(instance.props.guild.id, this, "servers");
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
});
|
||||
}
|
||||
BDFDB.appendSubMenu(e.currentTarget, serverContextSubMenu);
|
||||
});
|
||||
}
|
||||
|
||||
BDFDB.appendSubMenu(e.currentTarget, serverContextSubMenu);
|
||||
}
|
||||
|
||||
showServerSettings (info) {
|
||||
var data = BDFDB.loadData(info.id, this, "servers");
|
||||
|
||||
var name = data ? data.name : null;
|
||||
var shortName = data ? data.shortName : null;
|
||||
var url = data ? data.url : null;
|
||||
var removeIcon = data ? data.removeIcon : false;
|
||||
var color1 = data ? data.color1 : null;
|
||||
var color2 = data ? data.color2 : null;
|
||||
var color3 = data ? data.color3 : null;
|
||||
var color4 = data ? data.color4 : null;
|
||||
var {name,shortName,url,removeIcon,color1,color2,color3,color4} = BDFDB.loadData(info.id, this, "servers") || {};
|
||||
|
||||
var serverSettingsModal = $(this.serverSettingsModalMarkup);
|
||||
serverSettingsModal.find(BDFDB.dotCN.modalguildname).text(info.name);
|
||||
serverSettingsModal.find("#input-servername").val(name);
|
||||
serverSettingsModal.find("#input-servername").attr("placeholder", info.name);
|
||||
serverSettingsModal.find("#input-servershortname").val(shortName ? shortName : (info.icon ? "" : info.acronym));
|
||||
serverSettingsModal.find("#input-servershortname").val(shortName || (info.icon ? "" : info.acronym));
|
||||
serverSettingsModal.find("#input-servershortname").attr("placeholder", info.acronym);
|
||||
serverSettingsModal.find("#input-serverurl").val(url);
|
||||
serverSettingsModal.find("#input-serverurl").attr("placeholder", info.icon ? "https://cdn.discordapp.com/icons/" + info.id + "/" + info.icon + ".png" : null);
|
||||
|
@ -308,45 +256,39 @@ class EditServers {
|
|||
BDFDB.setColorSwatches(serverSettingsModal, color4);
|
||||
BDFDB.appendModal(serverSettingsModal);
|
||||
serverSettingsModal
|
||||
.on("click", "#input-removeicon", (event) => {
|
||||
serverSettingsModal.find("#input-serverurl").prop("disabled", event.target.checked);
|
||||
.on("click", "#input-removeicon", (e) => {
|
||||
serverSettingsModal.find("#input-serverurl").prop("disabled", e.currentTarget.checked);
|
||||
})
|
||||
.on("change keyup paste", "#input-serverurl", (event) => {
|
||||
this.checkUrl(serverSettingsModal, event);
|
||||
.on("change keyup paste", "#input-serverurl", (e) => {
|
||||
this.checkUrl(e.currentTarget);
|
||||
})
|
||||
.on("mouseenter", "#input-serverurl", (event) => {
|
||||
$(event.target).addClass("hovering");
|
||||
this.createNoticeTooltip(event);
|
||||
.on("mouseenter", "#input-serverurl", (e) => {
|
||||
e.currentTarget.classList.add("hovering");
|
||||
this.createNoticeTooltip(e.currentTarget);
|
||||
})
|
||||
.on("mouseleave", "#input-serverurl", (event) => {
|
||||
$(BDFDB.dotCN.tooltips).find(".notice-tooltip").remove();
|
||||
$(event.target).removeClass("hovering");
|
||||
.on("mouseleave", "#input-serverurl", (e) => {
|
||||
e.currentTarget.classList.remove("hovering");
|
||||
BDFDB.removeEles(BDFDB.dotCNS.tooltips + ".notice-tooltip");
|
||||
})
|
||||
.on("click", ".btn-save", (event) => {
|
||||
event.preventDefault();
|
||||
.on("click", ".btn-save", (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
name = null;
|
||||
if (serverSettingsModal.find("#input-servername").val()) {
|
||||
if (serverSettingsModal.find("#input-servername").val().trim().length > 0) {
|
||||
name = serverSettingsModal.find("#input-servername").val().trim();
|
||||
}
|
||||
if (serverSettingsModal.find("#input-servername").val() && serverSettingsModal.find("#input-servername").val().trim().length > 0) {
|
||||
name = serverSettingsModal.find("#input-servername").val().trim();
|
||||
}
|
||||
|
||||
shortName = null;
|
||||
if (serverSettingsModal.find("#input-servershortname").val()) {
|
||||
if (serverSettingsModal.find("#input-servershortname").val().trim().length > 0) {
|
||||
shortName = serverSettingsModal.find("#input-servershortname").val().trim();
|
||||
shortName = shortName == info.acronym ? null : shortName;
|
||||
}
|
||||
if (serverSettingsModal.find("#input-servershortname").val() && serverSettingsModal.find("#input-servershortname").val().trim().length > 0) {
|
||||
shortName = serverSettingsModal.find("#input-servershortname").val().trim();
|
||||
shortName = shortName == info.acronym ? null : shortName;
|
||||
}
|
||||
|
||||
removeIcon = serverSettingsModal.find("#input-removeicon").prop("checked");
|
||||
if (serverSettingsModal.find("#input-serverurl:not('.invalid')").length > 0) {
|
||||
url = null;
|
||||
if (!removeIcon && serverSettingsModal.find("#input-serverurl").val()) {
|
||||
if (serverSettingsModal.find("#input-serverurl").val().trim().length > 0) {
|
||||
url = serverSettingsModal.find("#input-serverurl").val().trim();
|
||||
}
|
||||
if (!removeIcon && serverSettingsModal.find("#input-serverurl").val() && serverSettingsModal.find("#input-serverurl").val().trim().length > 0) {
|
||||
url = serverSettingsModal.find("#input-serverurl").val().trim();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,83 +298,46 @@ class EditServers {
|
|||
color4 = BDFDB.getSwatchColor(serverSettingsModal, 4);
|
||||
|
||||
if (name == null && shortName == null && url == null && !removeIcon && color1 == null && color2 == null && color3 == null && color4 == null) {
|
||||
this.removeServerData(info.id);
|
||||
BDFDB.removeData(info.id, this, "servers");
|
||||
}
|
||||
else {
|
||||
BDFDB.saveData(info.id, {name,shortName,url,removeIcon,color1,color2,color3,color4}, this, "servers");
|
||||
this.loadServer(BDFDB.getDivOfServer(info.id));
|
||||
}
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
});
|
||||
serverSettingsModal.find("#input-servername").focus();
|
||||
}
|
||||
|
||||
checkUrl (modal, e) {
|
||||
if (!e.target.value) {
|
||||
$(e.target)
|
||||
.removeClass("valid")
|
||||
.removeClass("invalid");
|
||||
if ($(e.target).hasClass("hovering")) $(BDFDB.dotCN.tooltips).find(".notice-tooltip").remove();
|
||||
checkUrl (input) {
|
||||
BDFDB.removeEles(BDFDB.dotCNS.tooltips + ".notice-tooltip");
|
||||
if (!input.value) {
|
||||
input.classList.remove("valid");
|
||||
input.classList.remove("invalid");
|
||||
}
|
||||
else {
|
||||
let request = require("request");
|
||||
request(e.target.value, (error, response, result) => {
|
||||
require("request")(input.value, (error, response, result) => {
|
||||
if (response && response.headers["content-type"] && response.headers["content-type"].indexOf("image") != -1) {
|
||||
$(e.target)
|
||||
.removeClass("invalid")
|
||||
.addClass("valid");
|
||||
input.classList.add("valid");
|
||||
input.classList.remove("invalid");
|
||||
}
|
||||
else {
|
||||
$(e.target)
|
||||
.removeClass("valid")
|
||||
.addClass("invalid");
|
||||
input.classList.remove("valid");
|
||||
input.classList.add("invalid");
|
||||
}
|
||||
if ($(e.target).hasClass("hovering")) this.createNoticeTooltip(e);
|
||||
if (input.classList.contains("hovering")) this.createNoticeTooltip(input);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
createNoticeTooltip (e) {
|
||||
$(BDFDB.dotCN.tooltips).find(".notice-tooltip").remove();
|
||||
|
||||
var input = e.currentTarget;
|
||||
createNoticeTooltip (input) {
|
||||
var disabled = input.disabled;
|
||||
var valid = input.classList.contains("valid");
|
||||
var invalid = input.classList.contains("invalid");
|
||||
if (disabled || valid || invalid) {
|
||||
var text = disabled ? this.labels.modal_ignoreurl_text : valid ? this.labels.modal_validurl_text : this.labels.modal_invalidurl_text;
|
||||
var bgColor = disabled ? "#282524" : valid ? "#297828" : "#8C2528";
|
||||
var customTooltipCSS = `
|
||||
body .notice-tooltip {
|
||||
background-color: ${bgColor} !important;
|
||||
}
|
||||
body .notice-tooltip:after {
|
||||
border-right-color: ${bgColor} !important;
|
||||
}`;
|
||||
BDFDB.createTooltip(text, input, {type:"right",selector:"notice-tooltip",css:customTooltipCSS});
|
||||
BDFDB.createTooltip(disabled ? this.labels.modal_ignoreurl_text : valid ? this.labels.modal_validurl_text : this.labels.modal_invalidurl_text, input, {type:"right",selector:"notice-tooltip",color: disabled ? "black" : invalid ? "red" : "green"});
|
||||
}
|
||||
}
|
||||
|
||||
removeServerData (id) {
|
||||
this.resetServer(id);
|
||||
|
||||
BDFDB.removeData(id, this, "servers");
|
||||
}
|
||||
|
||||
resetServer (id) {
|
||||
let serverObj = BDFDB.getDivOfServer(id);
|
||||
if (typeof serverObj !== "object" || !serverObj) return;
|
||||
$(serverObj.div)
|
||||
.off("mouseenter." + this.getName())
|
||||
.removeAttr("custom-editservers")
|
||||
.find(BDFDB.dotCN.avataricon)
|
||||
.text(serverObj.icon ? "" : serverObj.data.acronym)
|
||||
.toggleClass(BDFDB.disCN.avatarnoicon, !serverObj.icon)
|
||||
.css("font-size", !serverObj.icon ? "10px" : "")
|
||||
.css("background-image", serverObj.icon ? "url('https://cdn.discordapp.com/icons/" + serverObj.id + "/" + serverObj.icon + ".png')" : "")
|
||||
.css("background-color", "")
|
||||
.css("color", "");
|
||||
}
|
||||
|
||||
loadServer (serverObj) {
|
||||
if (typeof serverObj !== "object" || !serverObj) return;
|
||||
var data = BDFDB.loadData(serverObj.id, this, "servers");
|
||||
|
@ -458,33 +363,120 @@ class EditServers {
|
|||
}
|
||||
}
|
||||
|
||||
loadAllServers () {
|
||||
var serverObjs = BDFDB.readServerList();
|
||||
for (var i = 0; i < serverObjs.length; i++) {
|
||||
this.loadServer(serverObjs[i]);
|
||||
processGuildIcon (instance, wrapper) {
|
||||
if (instance.props && instance.props.guild) {
|
||||
let icon = wrapper.classList && wrapper.classList.contains(BDFDB.disCN.avataricon) ? wrapper : wrapper.querySelector(BDFDB.dotCN.avataricon);
|
||||
if (!icon) return;
|
||||
this.changeGuildIcon(instance.props.guild, icon);
|
||||
if (BDFDB.getParentEle(BDFDB.dotCN.guild, icon)) this.changeTooltip(instance.props.guild, wrapper, "right");
|
||||
else if (BDFDB.getParentEle(BDFDB.dotCN.friendscolumn, icon)) this.changeTooltip(instance.props.guild, icon.parentElement, "top");
|
||||
}
|
||||
}
|
||||
|
||||
createServerToolTip (serverObj) {
|
||||
var data = BDFDB.loadData(serverObj.id, this, "servers");
|
||||
if (data) {
|
||||
var text = data.name ? data.name : serverObj.name;
|
||||
processGuildHeader (instance, wrapper) {
|
||||
if (instance.props && instance.props.guild) {
|
||||
this.changeGuildName(instance.props.guild, wrapper.querySelector(BDFDB.dotCN.guildheadername));
|
||||
}
|
||||
}
|
||||
|
||||
processClickable (instance, wrapper) {
|
||||
if (!wrapper || !instance.props || !instance.props.className) return;
|
||||
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.userprofilelistrow) > -1) {
|
||||
let fiber = instance._reactInternalFiber;
|
||||
if (fiber.return && fiber.return.type && fiber.return.type.displayName == "GuildRow" && fiber.return.memoizedProps && fiber.return.memoizedProps.guild) {
|
||||
this.changeGuildName(fiber.return.memoizedProps.guild, wrapper.querySelector(BDFDB.dotCN.userprofilelistname));
|
||||
}
|
||||
}
|
||||
else if (instance.props.tag == "div" && instance.props.className.indexOf(BDFDB.disCN.quickswitchresult) > -1) {
|
||||
let fiber = instance._reactInternalFiber;
|
||||
if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.result && fiber.return.memoizedProps.result.type == "GUILD") {
|
||||
this.changeGuildName(fiber.return.memoizedProps.result.record, wrapper.querySelector(BDFDB.dotCN.quickswitchresultmatch));
|
||||
}
|
||||
else if (fiber.return && fiber.return.memoizedProps && fiber.return.memoizedProps.result && fiber.return.memoizedProps.result.type.indexOf("_CHANNEL") != -1 && fiber.return.memoizedProps.result.record && fiber.return.memoizedProps.result.record.guild_id) {
|
||||
this.changeGuildName(this.GuildUtils.getGuild(fiber.return.memoizedProps.result.record.guild_id), wrapper.querySelector(BDFDB.dotCN.quickswitchresultmisccontainer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changeGuildName (info, guildname) {
|
||||
if (!info || !guildname || !guildname.parentElement) return;
|
||||
if (guildname.EditServersChangeObserver && typeof guildname.EditServersChangeObserver.disconnect == "function") guildname.EditServersChangeObserver.disconnect();
|
||||
let data = BDFDB.loadData(info.id, this, "servers") || {};
|
||||
guildname.style.setProperty("color", BDFDB.colorCONVERT(data.color2, "RGB"), "important");
|
||||
BDFDB.setInnerText(guildname, data.name || info.name);
|
||||
if (!BDFDB.isObjectEmpty(data)) {
|
||||
guildname.EditServersChangeObserver = new MutationObserver((changes, _) => {
|
||||
guildname.EditServersChangeObserver.disconnect();
|
||||
this.changeName(info, guildname);
|
||||
});
|
||||
guildname.EditServersChangeObserver.observe(guildname, {attributes:true});
|
||||
}
|
||||
}
|
||||
|
||||
changeGuildIcon (info, icon) {
|
||||
if (!info || !icon || !icon.parentElement) return;
|
||||
if (icon.EditServersChangeObserver && typeof icon.EditServersChangeObserver.disconnect == "function") icon.EditServersChangeObserver.disconnect();
|
||||
let data = BDFDB.loadData(info.id, this, "servers") || {};
|
||||
let url = data.url || BDFDB.getGuildIcon(info.id);
|
||||
if (icon.tagName == "IMG") icon.setAttribute("src", data.removeIcon || data.shortName ? null : url);
|
||||
else {
|
||||
BDFDB.setInnerText(icon, data.url ? "" : (data.shortName || (info.icon && !data.removeIcon ? "" : info.acronym)));
|
||||
icon.style.setProperty("background-image", data.removeIcon || data.shortName ? null : (url ? `url(${url})` : null), "important");
|
||||
icon.style.setProperty("background-color", BDFDB.colorCONVERT(data.color1, "RGB"), "important");
|
||||
icon.style.setProperty("color", BDFDB.colorCONVERT(data.color2, "RGB", "important"));
|
||||
icon.style.setProperty("font-size", this.getFontSize(icon));
|
||||
let hasicon = icon.style.getPropertyValue("background-image");
|
||||
for (let noiconclass of this.getNoIconClasses(icon)) {
|
||||
if (hasicon) icon.classList.remove(noiconclass);
|
||||
else icon.classList.add(noiconclass);
|
||||
}
|
||||
if (data.url && !data.removeIcon) {
|
||||
icon.style.setProperty("background-position", "center");
|
||||
icon.style.setProperty("background-size", "cover");
|
||||
}
|
||||
else {
|
||||
icon.style.removeProperty("background-position");
|
||||
icon.style.removeProperty("background-size");
|
||||
}
|
||||
}
|
||||
if (!BDFDB.isObjectEmpty(data)) {
|
||||
icon.EditServersChangeObserver = new MutationObserver((changes, _) => {
|
||||
changes.forEach(
|
||||
(change, i) => {
|
||||
icon.EditServersChangeObserver.disconnect();
|
||||
this.changeGuildIcon(info, icon);
|
||||
}
|
||||
);
|
||||
});
|
||||
icon.EditServersChangeObserver.observe(icon, {attributes:true});
|
||||
}
|
||||
}
|
||||
|
||||
changeTooltip (info, wrapper, type) {
|
||||
if (!info || !wrapper || !wrapper.parentElement) return;
|
||||
let data = BDFDB.loadData(info.id, this, "servers") || {};
|
||||
$(wrapper).off("mouseenter." + this.getName());
|
||||
if (data.name || data.color3 || data.color4) $(wrapper).on("mouseenter." + this.getName(), () => {
|
||||
var bgColor = data.color3 ? BDFDB.colorCONVERT(data.color3, "RGB") : "";
|
||||
var fontColor = data.color4 ? BDFDB.colorCONVERT(data.color4, "RGB") : "";
|
||||
var customTooltipCSS = `
|
||||
body ${BDFDB.dotCN.tooltip}:not(.guild-custom-tooltip) {
|
||||
display: none !important;
|
||||
}
|
||||
body .guild-custom-tooltip {
|
||||
color: ${fontColor} !important;
|
||||
background-color: ${bgColor} !important;
|
||||
}
|
||||
body .guild-custom-tooltip:after {
|
||||
border-right-color: ${bgColor} !important;
|
||||
}`;
|
||||
|
||||
BDFDB.createTooltip(text, serverObj.div, {type:"right",selector:"guild-custom-tooltip",css:customTooltipCSS});
|
||||
}
|
||||
BDFDB.createTooltip(data.name || info.name, wrapper, {type,selector:"EditServers-tooltip",style:`color: ${fontColor} !important; background-color: ${bgColor} !important; border-color: ${bgColor} !important;`,css:`body ${BDFDB.dotCN.tooltip}:not(.EditServers-tooltip) {display: none !important;}`});
|
||||
});
|
||||
}
|
||||
|
||||
getFontSize (icon) {
|
||||
if (icon.style.getPropertyValue("background-image")) return null;
|
||||
else if (icon.classList.contains(BDFDB.disCN.avatariconsizexlarge)) return "12px";
|
||||
else if (icon.classList.contains(BDFDB.disCN.avatariconsizelarge)) return "10px";
|
||||
else if (icon.classList.contains(BDFDB.disCN.avatariconsizemedium)) return "8px";
|
||||
else if (icon.classList.contains(BDFDB.disCN.avatariconsizesmall)) return "4.8px";
|
||||
else if (icon.classList.contains(BDFDB.disCN.avatariconsizemini)) return "4px";
|
||||
else return "10px";
|
||||
}
|
||||
|
||||
getNoIconClasses (icon) {
|
||||
let noiconclasses = [BDFDB.disCN.avatarnoicon];
|
||||
if (icon.classList.contains(BDFDB.disCN.userprofilelistavatar)) noiconclasses.push(BDFDB.disCN.userprofilelistguildavatarwithouticon);
|
||||
return noiconclasses;
|
||||
}
|
||||
|
||||
setLabelsByLanguage () {
|
||||
|
|
|
@ -195,10 +195,10 @@ class EditUsers {
|
|||
$(settingspanel)
|
||||
.on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);})
|
||||
.on("click", ".reset-button", () => {
|
||||
if (confirm("Are you sure you want to reset all users?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to reset all users?", () => {
|
||||
BDFDB.removeAllData(this, "users");
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
}
|
||||
});
|
||||
});
|
||||
return settingspanel;
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ class MessageUtilities {
|
|||
}
|
||||
|
||||
resetAll (settingspanel) {
|
||||
if (confirm("Are you sure you want to delete all key bindings?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to delete all key bindings?", () => {
|
||||
BDFDB.removeAllData(this, "bindings");
|
||||
let bindings = BDFDB.getAllData(this, "bindings");
|
||||
settingspanel.querySelectorAll(BDFDB.dotCN.select).forEach((wrap) => {
|
||||
|
@ -164,7 +164,7 @@ class MessageUtilities {
|
|||
wrap.setAttribute("value", bindings[action][option]);
|
||||
wrap.querySelector("input").setAttribute("value", this.keyboardMap[bindings[action][option]]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openDropdownMenu (settingspanel, e) {
|
||||
|
|
|
@ -140,7 +140,7 @@ class NotificationSounds {
|
|||
.on("click", ".btn-addsong", (e) => {this.saveAudio(settingspanel);})
|
||||
.on("keyup", ".songInput", (e) => {if (e.which == 13) this.saveAudio(settingspanel);})
|
||||
.on("click", ".reset-button", () => {
|
||||
if (confirm("Are you sure you want to delete all added songs?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to delete all added songs?", () => {
|
||||
BDFDB.removeAllData(this, "choices");
|
||||
BDFDB.removeAllData(this, "audios");
|
||||
this.loadAudios();
|
||||
|
@ -158,7 +158,7 @@ class NotificationSounds {
|
|||
settingspanel.querySelectorAll(".volumeInput").forEach((input) => {
|
||||
input.value = 100;
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.on("click", ".mute-checkbox", (e) => {
|
||||
var checkbox = e.currentTarget;
|
||||
|
|
|
@ -7,7 +7,7 @@ class PersonalPins {
|
|||
this.patchModules = {
|
||||
"HeaderBar":["componentDidMount","componentDidUpdate"],
|
||||
"Message":"componentDidMount",
|
||||
"MessageOptionPopout":"componentDidMount"
|
||||
"MessageOptionPopout":"componentDidMount"
|
||||
};
|
||||
|
||||
this.notesButton =
|
||||
|
@ -167,7 +167,11 @@ class PersonalPins {
|
|||
BDFDB.initElements(settingspanel);
|
||||
|
||||
$(settingspanel)
|
||||
.on("click", ".reset-button", () => {if (confirm("Are you sure you want to delete all pinned notes?")) BDFDB.removeAllData(this, "pins");});
|
||||
.on("click", ".reset-button", () => {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to delete all pinned notes?", () => {
|
||||
BDFDB.removeAllData(this, "pins");
|
||||
});
|
||||
});
|
||||
return settingspanel;
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class PluginRepo {
|
|||
</li>`;
|
||||
|
||||
this.pluginRepoModalMarkup =
|
||||
`<span class="${this.getName()}-modal DevilBro-modal">
|
||||
`<span class="${this.getName()}-modal Repo-modal DevilBro-modal">
|
||||
<div class="${BDFDB.disCN.backdrop}"></div>
|
||||
<div class="${BDFDB.disCN.modal}">
|
||||
<div class="${BDFDB.disCN.modalinner}">
|
||||
|
@ -190,7 +190,7 @@ class PluginRepo {
|
|||
50% {opacity: 0.9;}
|
||||
to {opacity: 0.1;}
|
||||
}
|
||||
.${this.getName()}-modal ${BDFDB.dotCN.modalinner} {
|
||||
.${this.getName()}-modal.Repo-modal ${BDFDB.dotCN.modalinner} {
|
||||
min-height: 100%;
|
||||
min-width: 800px;
|
||||
width: 50%;
|
||||
|
@ -422,10 +422,10 @@ class PluginRepo {
|
|||
}
|
||||
|
||||
removeAllFromOwnList () {
|
||||
if (confirm("Are you sure you want to remove all added Plugins from your own list?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to remove all added Plugins from your own list?", () => {
|
||||
BDFDB.saveData("ownlist", [], this, "ownlist");
|
||||
BDFDB.removeEles(this.getName() + "-settings " + BDFDB.dotCN.hovercard);
|
||||
}
|
||||
BDFDB.removeEles("." + this.getName() + "-settings " + BDFDB.dotCN.hovercard);
|
||||
});
|
||||
}
|
||||
|
||||
checkIfPluginsPage (container) {
|
||||
|
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
class RepoControls {
|
||||
initConstructor () {
|
||||
this.patchModules = {
|
||||
"V2C_List":"componentDidMount",
|
||||
"V2C_PluginCard": ["componentDidMount","componentDidUpdate"],
|
||||
"V2C_ThemeCard":"componentDidMount"
|
||||
};
|
||||
|
||||
this.sortings = {
|
||||
sort: {
|
||||
name: "Name",
|
||||
|
@ -74,31 +80,20 @@ class RepoControls {
|
|||
</div>`;
|
||||
|
||||
this.deleteButtonMarkup =
|
||||
`<svg class="trashIcon" version="1.1" xmlns="http://www.w3.org/2000/svg" width="20px" height="20px">
|
||||
<g fill="white">
|
||||
<path d="M 18.012, 0.648 H 12.98 C 12.944, 0.284, 12.637, 0, 12.264, 0 H 8.136 c -0.373, 0 -0.68, 0.284 -0.716, 0.648 H 2.389 c -0.398, 0 -0.72, 0.322 -0.72, 0.72 v 1.368 c 0, 0.398, 0.322, 0.72, 0.72, 0.72 h 15.623 c 0.398, 0, 0.72 -0.322, 0.72 -0.72 V 1.368 C 18.731, 0.97, 18.409, 0.648, 18.012, 0.648 z"/><path d="M 3.178, 4.839 v 14.841 c 0, 0.397, 0.322, 0.72, 0.72, 0.72 h 12.604 c 0.398, 0, 0.72 -0.322, 0.72 -0.72 V 4.839 H 3.178 z M 8.449, 15.978 c 0, 0.438 -0.355, 0.794 -0.794, 0.794 c -0.438, 0 -0.794 -0.355 -0.794 -0.794 V 8.109 c 0 -0.438, 0.355 -0.794, 0.794 -0.794 c 0.438, 0, 0.794, 0.355, 0.794, 0.794 V 15.978 z M 13.538, 15.978 c 0, 0.438 -0.355, 0.794 -0.794, 0.794 s -0.794 -0.355 -0.794 -0.794 V 8.109 c 0 -0.438, 0.355 -0.794, 0.794 -0.794 c 0.438, 0, 0.794, 0.355, 0.794, 0.794 V 15.978 z"/>
|
||||
</g>
|
||||
`<svg class="trashIcon" fill="currentColor" version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24" transform="translate(2,1.5)">
|
||||
<path d="M 18.012, 0.648 H 12.98 C 12.944, 0.284, 12.637, 0, 12.264, 0 H 8.136 c -0.373, 0 -0.68, 0.284 -0.716, 0.648 H 2.389 c -0.398, 0 -0.72, 0.322 -0.72, 0.72 v 1.368 c 0, 0.398, 0.322, 0.72, 0.72, 0.72 h 15.623 c 0.398, 0, 0.72 -0.322, 0.72 -0.72 V 1.368 C 18.731, 0.97, 18.409, 0.648, 18.012, 0.648 z"/>
|
||||
<path d="M 3.178, 4.839 v 14.841 c 0, 0.397, 0.322, 0.72, 0.72, 0.72 h 12.604 c 0.398, 0, 0.72 -0.322, 0.72 -0.72 V 4.839 H 3.178 z M 8.449, 15.978 c 0, 0.438 -0.355, 0.794 -0.794, 0.794 c -0.438, 0 -0.794 -0.355 -0.794 -0.794 V 8.109 c 0 -0.438, 0.355 -0.794, 0.794 -0.794 c 0.438, 0, 0.794, 0.355, 0.794, 0.794 V 15.978 z M 13.538, 15.978 c 0, 0.438 -0.355, 0.794 -0.794, 0.794 s -0.794 -0.355 -0.794 -0.794 V 8.109 c 0 -0.438, 0.355 -0.794, 0.794 -0.794 c 0.438, 0, 0.794, 0.355, 0.794, 0.794 V 15.978 z"/>
|
||||
</svg>`;
|
||||
|
||||
this.css = `
|
||||
#bd-settingspane-container .bda-description {
|
||||
display: block;
|
||||
}
|
||||
#bd-settingspane-container .bda-header {
|
||||
position: relative;
|
||||
}
|
||||
#bd-settingspane-container .trashIcon {
|
||||
display: none;
|
||||
}
|
||||
#bd-settingspane-container .bda-header .trashIcon {
|
||||
margin-right: 5px;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
position: absolute;
|
||||
right: 50px;
|
||||
top: 2px;
|
||||
vertical-align: top;
|
||||
color: #72767d;
|
||||
}
|
||||
#bd-settingspane-container .bda-header .bd-reload ~ .trashIcon {
|
||||
right: 78px;
|
||||
${BDFDB.dotCN.themedark} #bd-settingspane-container .trashIcon {
|
||||
color: #dcddde;
|
||||
}`;
|
||||
|
||||
this.defaults = {
|
||||
|
@ -117,20 +112,20 @@ class RepoControls {
|
|||
|
||||
getDescription () {return "Lets you sort and filter your list of downloaded Themes and Plugins.";}
|
||||
|
||||
getVersion () {return "1.2.1";}
|
||||
getVersion () {return "1.2.2";}
|
||||
|
||||
getAuthor () {return "DevilBro";}
|
||||
|
||||
getSettingsPanel () {
|
||||
if (!this.started || typeof BDFDB !== "object") return;
|
||||
var settings = BDFDB.getAllData(this, "settings");
|
||||
var settingshtml = `<div class="${this.getName()}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.getName()}</div><div class="DevilBro-settings-inner">`;
|
||||
let settings = BDFDB.getAllData(this, "settings");
|
||||
let settingshtml = `<div class="${this.getName()}-settings DevilBro-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.getName()}</div><div class="DevilBro-settings-inner">`;
|
||||
for (let key in settings) {
|
||||
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.settings[key].description}</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" value="${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner}"${settings[key] ? " checked" : ""}></div></div>`;
|
||||
}
|
||||
settingshtml += `</div></div>`;
|
||||
|
||||
var settingspanel = $(settingshtml)[0];
|
||||
let settingspanel = $(settingshtml)[0];
|
||||
|
||||
BDFDB.initElements(settingspanel);
|
||||
|
||||
|
@ -144,7 +139,7 @@ class RepoControls {
|
|||
load () {}
|
||||
|
||||
start () {
|
||||
var libraryScript = null;
|
||||
let 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();
|
||||
|
@ -164,51 +159,9 @@ class RepoControls {
|
|||
|
||||
this.fs = require("fs");
|
||||
this.path = require("path");
|
||||
this.dirs = {themes: BDFDB.getThemesFolder(), plugins: BDFDB.getPluginsFolder()};
|
||||
this.dirs = {theme: BDFDB.getThemesFolder(), plugin: BDFDB.getPluginsFolder()};
|
||||
|
||||
var observer = null;
|
||||
observer = new MutationObserver((changes, _) => {
|
||||
changes.forEach(
|
||||
(change, j) => {
|
||||
if (change.addedNodes) {
|
||||
change.addedNodes.forEach((node) => {
|
||||
if (this.getSettingsPageType(node)) {
|
||||
this.addControls(node.querySelector(".bda-slist"));
|
||||
if (node.tagName && node.querySelector(".ui-switch")) {
|
||||
var entry = this.getEntry($(".repo-controls"), $("li").has(node)[0]);
|
||||
if (entry) {
|
||||
if (BDFDB.getData("addDeleteButton", this, "settings")) this.addDeleteButton(entry);
|
||||
this.changeTextToHTML(entry.div);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
BDFDB.addObserver(this, BDFDB.dotCN.layer + "[layer-id='user-settings']", {name:"innerSettingsWindowObserver",instance:observer}, {childList:true,subtree:true});
|
||||
|
||||
observer = new MutationObserver((changes, _) => {
|
||||
changes.forEach(
|
||||
(change, i) => {
|
||||
if (change.addedNodes) {
|
||||
change.addedNodes.forEach((node) => {
|
||||
setImmediate(() => {
|
||||
if (node.tagName && node.getAttribute("layer-id") == "user-settings") {
|
||||
BDFDB.addObserver(this, node, {name:"innerSettingsWindowObserver"}, {childList:true,subtree:true});
|
||||
if (this.getSettingsPageType(node)) this.addControls(node.querySelector(".bda-slist"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
BDFDB.addObserver(this, BDFDB.dotCN.layers, {name:"settingsWindowObserver",instance:observer}, {childList:true});
|
||||
|
||||
var settingswindow = document.querySelector(BDFDB.dotCN.layer + "[layer-id='user-settings']");
|
||||
if (settingswindow && this.getSettingsPageType(settingswindow)) this.addControls(settingswindow.querySelector(".bda-slist"));
|
||||
BDFDB.WebModules.forceAllUpdates(this);
|
||||
}
|
||||
else {
|
||||
console.error(this.getName() + ": Fatal Error: Could not load BD functions!");
|
||||
|
@ -218,8 +171,17 @@ class RepoControls {
|
|||
|
||||
stop () {
|
||||
if (typeof BDFDB === "object") {
|
||||
$(".repo-controls, #bd-settingspane-container .trashIcon").remove();
|
||||
$(".repocontrols-added").removeClass(".repocontrols-added");
|
||||
BDFDB.removeEles(".repo-controls","#bd-settingspane-container .trashIcon");
|
||||
BDFDB.removeClasses("repocontrols-added");
|
||||
|
||||
for (let list of document.querySelectorAll(BDFDB.dotCNS._repolist)) {
|
||||
list.style.removeProperty("display");
|
||||
list.style.removeProperty("flex-direction");
|
||||
for (let li of list.querySelectorAll("li")) {
|
||||
li.style.removeProperty("display");
|
||||
li.style.removeProperty("order");
|
||||
}
|
||||
}
|
||||
|
||||
BDFDB.unloadMessage(this);
|
||||
}
|
||||
|
@ -229,53 +191,92 @@ class RepoControls {
|
|||
// begin of own functions
|
||||
|
||||
updateSettings (settingspanel) {
|
||||
var settings = {};
|
||||
for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
|
||||
let settings = {};
|
||||
for (let input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) {
|
||||
settings[input.value] = input.checked;
|
||||
}
|
||||
BDFDB.saveAllData(settings, this, "settings");
|
||||
}
|
||||
|
||||
getSettingsPageType (container) {
|
||||
if (typeof container === "undefined") container = document.querySelector(BDFDB.dotCN.layer + "[layer-id='user-settings']");
|
||||
if (container && container.tagName) {
|
||||
var folderbutton = container.querySelector(".bd-pfbtn");
|
||||
if (folderbutton) {
|
||||
var buttonbar = folderbutton.parentElement;
|
||||
if (buttonbar && buttonbar.tagName) {
|
||||
var header = buttonbar.querySelector("h2");
|
||||
if (header) {
|
||||
var headerText = BDFDB.getInnerText(header).toLowerCase();
|
||||
if (headerText === "plugins" || headerText === "themes") return headerText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
processV2CList (instance, container) {
|
||||
if (instance._reactInternalFiber.key) this.addControls(instance._reactInternalFiber.key.split("-")[0], container);
|
||||
}
|
||||
|
||||
addControls (container) {
|
||||
if (!container || document.querySelector(".repo-controls")) return;
|
||||
processV2CPluginCard (instance, wrapper) {
|
||||
if (wrapper.querySelector(BDFDB.dotCN._reponame)) {
|
||||
if (instance.props && BDFDB.getData("addDeleteButton", this, "settings")) this.addDeleteButton("plugin", wrapper);
|
||||
this.changeTextToHTML(wrapper, "");
|
||||
}
|
||||
}
|
||||
|
||||
processV2CThemeCard (instance, wrapper) {
|
||||
if (wrapper.querySelector(BDFDB.dotCN._reponame)) {
|
||||
if (instance.props && BDFDB.getData("addDeleteButton", this, "settings")) this.addDeleteButton("theme", wrapper);
|
||||
this.changeTextToHTML(wrapper, "");
|
||||
}
|
||||
}
|
||||
|
||||
addDeleteButton (type, wrapper) {
|
||||
if (!type || !wrapper || wrapper.querySelector(".trashIcon")) return;
|
||||
let name = wrapper.getAttribute("data-name");
|
||||
if (!name) return;
|
||||
let path = global[`bd${type}s`] && global[`bd${type}s`][name] ? this.path.join(this.dirs[type], global[`bd${type}s`][name].filename) : null;
|
||||
if (!path) return;
|
||||
let button = $(this.deleteButtonMarkup)[0];
|
||||
button.addEventListener("click", () => {
|
||||
let deleteFile = () => {
|
||||
this.fs.unlink(path, (error) => {
|
||||
if (error) BDFDB.showToast(`Unable to delete ${type} "${name}".`, {type:"danger"});
|
||||
else BDFDB.showToast(`Successfully deleted ${type} "${name}".`, {type:"success"});
|
||||
});
|
||||
};
|
||||
if (!BDFDB.getData("confirmDelete", this, "settings")) deleteFile();
|
||||
else BDFDB.openConfirmModal(this, `Are you sure you want to delete the ${type} "${name}"?`, () => {
|
||||
deleteFile();
|
||||
});
|
||||
});
|
||||
button.addEventListener("mouseenter", (e) => {
|
||||
BDFDB.createTooltip(`Delete ${type[0].toUpperCase() + type.slice(1)}`, e.currentTarget, {type:"top",selector:"repocontrols-trashicon-tooltip"});
|
||||
});
|
||||
let controls = wrapper.querySelector(BDFDB.dotCN._repocontrols);
|
||||
if (controls) controls.insertBefore(button, controls.firstElementChild);
|
||||
}
|
||||
|
||||
changeTextToHTML (wrapper, searchstring) {
|
||||
if (!wrapper || !wrapper.tagName) return;
|
||||
if (typeof searchstring === "undefined") searchstring = document.querySelector(".repo-controls " + BDFDB.dotCN.searchbarinput).value;
|
||||
wrapper.querySelectorAll(BDFDB.dotCNC._reponame + BDFDB.dotCNC._repoversion + BDFDB.dotCNC._repoauthor + BDFDB.dotCN._repodescription).forEach(ele => {
|
||||
if (ele.classList.contains(BDFDB.disCN._repodescription)) ele.style.display = "block";
|
||||
ele.innerHTML = BDFDB.highlightText(ele.innerText, searchstring);
|
||||
});
|
||||
}
|
||||
|
||||
addControls (type, container) {
|
||||
if (!type || !container) return;
|
||||
BDFDB.removeEles(".repo-controls");
|
||||
|
||||
var sortings = BDFDB.getAllData(this, "sortings");
|
||||
container.style.setProperty("display","flex","important");
|
||||
container.style.setProperty("flex-direction","column","important");
|
||||
|
||||
var repoControls = $(this.repoControlsMarkup);
|
||||
let sortings = BDFDB.getAllData(this, "sortings");
|
||||
|
||||
let repoControls = $(this.repoControlsMarkup);
|
||||
BDFDB.initElements(repoControls);
|
||||
repoControls.find(".sort-filter " + BDFDB.dotCN.quickselectvalue).attr("option", sortings.sort).text(this.sortings.sort[sortings.sort]);
|
||||
repoControls.find(".order-filter " + BDFDB.dotCN.quickselectvalue).attr("option", sortings.order).text(this.sortings.order[sortings.order]);
|
||||
repoControls
|
||||
.on("keyup." + this.getName(), BDFDB.dotCN.searchbarinput, () => {
|
||||
clearTimeout(repoControls.searchTimeout);
|
||||
repoControls.searchTimeout = setTimeout(() => {this.addEntries(container, repoControls);},1000);
|
||||
repoControls.searchTimeout = setTimeout(() => {this.sortEntries(container, repoControls);},1000);
|
||||
})
|
||||
.on("click." + this.getName(), BDFDB.dotCN.searchbarclear + BDFDB.dotCN.searchbarvisible, () => {
|
||||
this.addEntries(container, repoControls);
|
||||
this.sortEntries(container, repoControls);
|
||||
})
|
||||
.on("click." + this.getName(), ".btn-enableall", (e) => {
|
||||
this.toggleAll(container, true);
|
||||
this.toggleAll(type, container, true);
|
||||
})
|
||||
.on("click." + this.getName(), ".btn-disableall", (e) => {
|
||||
this.toggleAll(container, false);
|
||||
this.toggleAll(type, container, false);
|
||||
})
|
||||
.on("click." + this.getName(), ".sort-filter", (e) => {
|
||||
this.openSortPopout(e, this.sortPopoutMarkup, container, repoControls);
|
||||
|
@ -285,149 +286,96 @@ class RepoControls {
|
|||
})
|
||||
.insertBefore(container);
|
||||
|
||||
$(container).addClass("repocontrols-added").on("click." + this.getName(), "div[style='float: right; cursor: pointer;']", (e) => {
|
||||
setImmediate(() => {
|
||||
var entry = this.getEntry(repoControls, $("li").has(e.currentTarget)[0]);
|
||||
if (entry) {
|
||||
if (BDFDB.getData("addDeleteButton", this, "settings")) this.addDeleteButton(entry);
|
||||
this.changeTextToHTML(entry.div);
|
||||
}
|
||||
});
|
||||
});
|
||||
container.classList.add("repocontrols-added");
|
||||
|
||||
container.entries = [];
|
||||
for (let li of container.querySelectorAll("li")) {
|
||||
container.entries.push(this.getEntry(repoControls, li));
|
||||
container.entries = {};
|
||||
for (let li of container.children) {
|
||||
let name = li.querySelector(BDFDB.dotCN._reponame).textContent;
|
||||
let version = li.querySelector(BDFDB.dotCN._repoversion).textContent;
|
||||
let author = li.querySelector(BDFDB.dotCN._repoauthor).textContent;
|
||||
let description = li.querySelector(BDFDB.dotCN._repodescription).textContent;
|
||||
let enabled = li.querySelector(BDFDB.dotCN._repocheckbox).checked;
|
||||
let path = global[`bd${type}s`] && global[`bd${type}s`][name] ? this.path.join(this.dirs[type], global[`bd${type}s`][name].filename) : null;
|
||||
let stats = path ? this.fs.statSync(path) : null;
|
||||
container.entries[name] = {
|
||||
search: (name + " " + version + " " + author + " " + description).toUpperCase(),
|
||||
origName: name,
|
||||
name: (name).toUpperCase(),
|
||||
version: (version).toUpperCase(),
|
||||
author: (author).toUpperCase(),
|
||||
description: (description).toUpperCase(),
|
||||
type: type,
|
||||
path: path,
|
||||
adddate: stats ? stats.atime.getTime() : null,
|
||||
moddate: stats ? stats.mtime.getTime() : null,
|
||||
enabled: enabled ? 0 : 1
|
||||
};
|
||||
}
|
||||
|
||||
this.addEntries(container, repoControls);
|
||||
this.sortEntries(container, repoControls);
|
||||
}
|
||||
|
||||
getEntry (repoControls, li) {
|
||||
if (!repoControls || !li || !li.tagName || !li.querySelector(".bda-name")) return null;
|
||||
let name = li.querySelector(".bda-name").textContent;
|
||||
let version = li.querySelector(".bda-version").textContent;
|
||||
let author = li.querySelector(".bda-author").textContent;
|
||||
let description = li.querySelector(".bda-description").textContent;
|
||||
let enabled = li.querySelector(".ui-switch-checkbox").checked;
|
||||
let type = this.getSettingsPageType();
|
||||
let path = type && global[`bd${type}`] && global[`bd${type}`][name] ? this.path.join(this.dirs[type], global[`bd${type}`][name].filename) : null;
|
||||
let stats = path ? this.fs.statSync(path) : null;
|
||||
return {
|
||||
div: li,
|
||||
search: (name + " " + version + " " + author + " " + description).toUpperCase(),
|
||||
origName: name,
|
||||
name: (name).toUpperCase(),
|
||||
version: (version).toUpperCase(),
|
||||
author: (author).toUpperCase(),
|
||||
description: (description).toUpperCase(),
|
||||
type: type,
|
||||
path: path,
|
||||
adddate: stats ? stats.atime.getTime() : null,
|
||||
moddate: stats ? stats.mtime.getTime() : null,
|
||||
enabled: enabled ? 0 : 1
|
||||
};
|
||||
}
|
||||
|
||||
addEntries (container, repoControls) {
|
||||
$(container).find(".trashIcon, li").remove();
|
||||
sortEntries (container, repoControls) {
|
||||
let searchstring = repoControls.find(BDFDB.dotCN.searchbarinput).val().replace(/[<|>]/g, "").toUpperCase();
|
||||
|
||||
var searchstring = repoControls.find(BDFDB.dotCN.searchbarinput).val().replace(/[<|>]/g, "").toUpperCase();
|
||||
|
||||
var entries = container.entries;
|
||||
var sortings = BDFDB.getAllData(this, "sortings");
|
||||
entries = entries.filter((entry) => {return entry.search.indexOf(searchstring) > -1 ? entry : null;});
|
||||
BDFDB.sortArrayByKey(entries, sortings.sort);
|
||||
if (sortings.order == "desc") entries.reverse();
|
||||
|
||||
var settings = BDFDB.getAllData(this, "settings");
|
||||
for (let entry of entries) {
|
||||
container.appendChild(entry.div);
|
||||
if (settings.addDeleteButton) this.addDeleteButton(entry);
|
||||
this.changeTextToHTML(entry.div, searchstring);
|
||||
$(entry.div).find(".ui-switch-checkbox")
|
||||
.off("change." + this.getName())
|
||||
.on("change." + this.getName(), (e) => {
|
||||
entry.enabled = e.checked ? 0 : 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
addDeleteButton (entry) {
|
||||
if (!entry || !entry.div || !entry.div.tagName || entry.div.querySelector(".trashIcon")) return;
|
||||
$(this.deleteButtonMarkup)
|
||||
.on("click." + this.getName(), () => {
|
||||
var container = document.querySelector(".bda-slist");
|
||||
let type = entry.type ? entry.type.slice(0, -1) : "file";
|
||||
if (container && (!BDFDB.getData("confirmDelete", this, "settings") || confirm(`Are you sure you want to delete this ${type}?`))) {
|
||||
this.fs.unlink(entry.path, (error) => {
|
||||
if (error) {
|
||||
BDFDB.showToast(`Unable to delete ${type} "${entry.origName}". Filename might not be the same as ${type}name.`, {type:"danger"});
|
||||
}
|
||||
else {
|
||||
BDFDB.showToast(`Successfully deleted ${type} "${entry.origName}".`, {type:"success"});
|
||||
BDFDB.removeFromArray(container.entries, entry);
|
||||
entry.div.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.on("mouseenter." + this.getName(), (e) => {
|
||||
BDFDB.createTooltip("Delete File", e.currentTarget, {type:"top",selector:"repocontrols-trashicon-tooltip"});
|
||||
})
|
||||
.insertAfter(entry.div.querySelector(".ui-switch-wrapper"));
|
||||
}
|
||||
|
||||
toggleAll (container, enable) {
|
||||
if (confirm(`Are you sure you want to ${enable ? "enable" : "disable"} everything?`)) {
|
||||
for (let header of container.querySelectorAll(".bda-header")) {
|
||||
if (header.querySelector(".bda-name").textContent.toLowerCase().indexOf(this.getName().toLowerCase()) != 0) {
|
||||
let switchwrap = header.querySelector(".ui-switch-wrapper");
|
||||
if (switchwrap) {
|
||||
let switchinner = switchwrap.querySelector(".ui-switch");
|
||||
let switchinput = switchwrap.querySelector(".ui-switch-checkbox");
|
||||
if (switchinner && switchinput) {
|
||||
if (switchinner.classList.contains("checked") && !enable) {
|
||||
switchinput.click();
|
||||
}
|
||||
else if (!switchinner.classList.contains("checked") && enable) {
|
||||
switchinput.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let sortings = BDFDB.getAllData(this, "sortings");
|
||||
let entries = BDFDB.filterObject(container.entries, entry => {return entry.search.indexOf(searchstring) > -1 ? entry : null;});
|
||||
entries = BDFDB.sortObject(entries, sortings.sort);
|
||||
if (sortings.order == "desc") entries = BDFDB.reverseObject(entries);
|
||||
let entrypositions = Object.keys(entries);
|
||||
for (let li of container.children) {
|
||||
let name = li.getAttribute("data-name");
|
||||
let pos = entrypositions.indexOf(name);
|
||||
if (pos > -1) {
|
||||
li.style.removeProperty("display");
|
||||
li.style.setProperty("order", pos, "important");
|
||||
$(li)
|
||||
.find(BDFDB.dotCN._repocheckbox)
|
||||
.off("change." + this.getName())
|
||||
.on("change." + this.getName(), (e) => {
|
||||
entries[name].enabled = e.checked ? 0 : 1
|
||||
});
|
||||
}
|
||||
else {
|
||||
li.style.setProperty("display", "none", "important");
|
||||
li.style.removeProperty("order");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
changeTextToHTML (container, searchstring) {
|
||||
if (!container || !container.tagName) return;
|
||||
if (typeof searchstring === "undefined") {
|
||||
var searchinput = document.querySelector(".repo-controls " + BDFDB.dotCN.searchbarinput);
|
||||
searchstring = searchinput ? searchinput.value : "";
|
||||
}
|
||||
container.querySelectorAll(".bda-name, .bda-version, .bda-author, .bda-description").forEach(ele => {
|
||||
if (ele.classList.contains("bda-description")) ele.style.display = "block";
|
||||
ele.innerHTML = BDFDB.highlightText(ele.innerText, searchstring);
|
||||
toggleAll (type, container, enable) {
|
||||
BDFDB.openConfirmModal(this, `Are you sure you want to ${enable ? "enable" : "disable"} all ${type[0].toUpperCase() + type.slice(1)}s?`, () => {
|
||||
for (let header of container.querySelectorAll(BDFDB.dotCN._repoheader)) {
|
||||
if (header.querySelector(BDFDB.dotCN._reponame).textContent.toLowerCase().indexOf(this.getName().toLowerCase()) != 0) {
|
||||
let switchwrap = header.querySelector(BDFDB.dotCN._repocheckboxwrap);
|
||||
if (switchwrap) {
|
||||
let switchinner = switchwrap.querySelector(BDFDB.dotCN._repocheckboxinner);
|
||||
let switchinput = switchwrap.querySelector(BDFDB.dotCN._repocheckbox);
|
||||
if (switchinner && switchinput) {
|
||||
if (switchinner.classList.contains("checked") && !enable) switchinput.click();
|
||||
else if (!switchinner.classList.contains("checked") && enable) switchinput.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openSortPopout (e, markup, container, repoControls) {
|
||||
var wrapper = e.currentTarget;
|
||||
let wrapper = e.currentTarget;
|
||||
if (wrapper.classList.contains("popout-open")) return;
|
||||
wrapper.classList.add("popout-open");
|
||||
var value = $(wrapper).find(BDFDB.dotCN.quickselectvalue);
|
||||
var popout = $(markup);
|
||||
let value = $(wrapper).find(BDFDB.dotCN.quickselectvalue);
|
||||
let popout = $(markup);
|
||||
$(BDFDB.dotCN.popouts).append(popout)
|
||||
.off("click", BDFDB.dotCN.contextmenuitem)
|
||||
.on("click", BDFDB.dotCN.contextmenuitem, (e2) => {
|
||||
var option = $(e2.currentTarget).attr("option");
|
||||
let option = $(e2.currentTarget).attr("option");
|
||||
value.text($(e2.currentTarget).text());
|
||||
value.attr("option", option);
|
||||
$(document).off("mousedown.sortpopout" + this.getName());
|
||||
popout.remove();
|
||||
BDFDB.saveData(popout.attr("option"), option, this, "sortings");
|
||||
this.addEntries(container, repoControls);
|
||||
this.sortEntries(container, repoControls);
|
||||
setTimeout(() => {wrapper.classList.remove("popout-open");},300);
|
||||
});
|
||||
|
||||
|
|
|
@ -327,15 +327,15 @@ class ServerFolders {
|
|||
$(settingspanel)
|
||||
.on("click", BDFDB.dotCN.switchinner, () => {this.updateSettings(settingspanel);})
|
||||
.on("click", ".reset-button", () => {
|
||||
if (confirm("Are you sure you want to delete all folders?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to delete all folders?", () => {
|
||||
BDFDB.removeAllData(this, "folders");
|
||||
this.resetAllElements();
|
||||
}
|
||||
});
|
||||
})
|
||||
.on("click", ".removecustom-button", () => {
|
||||
if (confirm("Are you sure you want to remove all custom icons?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to remove all custom icons?", () => {
|
||||
BDFDB.removeAllData(this, "customicons");
|
||||
}
|
||||
});
|
||||
});
|
||||
return settingspanel;
|
||||
}
|
||||
|
|
|
@ -95,12 +95,13 @@ class ServerHider {
|
|||
|
||||
$(settingspanel)
|
||||
.on("click", ".reset-button", () => {
|
||||
if (confirm("Are you sure you want to reset all servers?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to reset all servers?", () => {
|
||||
BDFDB.removeAllData(this, "servers");
|
||||
BDFDB.readServerList().forEach(serverObj => {
|
||||
if (!serverObj.div.getAttribute("folder")) $(serverObj.div).show();
|
||||
BDFDB.readServerList().forEach(info => {
|
||||
if (!info.div.getAttribute("folder")) info.div.style.removeProperty("display");
|
||||
});
|
||||
}});
|
||||
});
|
||||
});
|
||||
return settingspanel;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class ThemeRepo {
|
|||
</li>`;
|
||||
|
||||
this.themeRepoModalMarkup =
|
||||
`<span class="${this.getName()}-modal DevilBro-modal">
|
||||
`<span class="${this.getName()}-modal Repo-modal DevilBro-modal">
|
||||
<div class="${BDFDB.disCN.backdrop}"></div>
|
||||
<div class="${BDFDB.disCN.modal}">
|
||||
<div class="${BDFDB.disCN.modalinner}">
|
||||
|
@ -236,7 +236,7 @@ class ThemeRepo {
|
|||
opacity: 0 !important;
|
||||
visibility: hidden !important;
|
||||
}
|
||||
.${this.getName()}-modal ${BDFDB.dotCN.modalinner} {
|
||||
.${this.getName()}-modal.Repo-modal ${BDFDB.dotCN.modalinner} {
|
||||
min-height: 100%;
|
||||
min-width: 800px;
|
||||
width: 50%;
|
||||
|
@ -467,10 +467,10 @@ class ThemeRepo {
|
|||
}
|
||||
|
||||
removeAllFromOwnList () {
|
||||
if (confirm("Are you sure you want to remove all added Themes from your own list?")) {
|
||||
BDFDB.openConfirmModal(this, "Are you sure you want to remove all added Themes from your own list?", () => {
|
||||
BDFDB.saveData("ownlist", [], this, "ownlist");
|
||||
BDFDB.removeEles(this.getName() + "-settings " + BDFDB.dotCN.hovercard);
|
||||
}
|
||||
BDFDB.removeEles("." + this.getName() + "-settings " + BDFDB.dotCN.hovercard);
|
||||
});
|
||||
}
|
||||
|
||||
checkIfThemesPage (container) {
|
||||
|
@ -519,7 +519,7 @@ class ThemeRepo {
|
|||
themeRepoModal.find("#input-hideupdated").prop("checked", hiddenSettings.updated || showOnlyOutdated);
|
||||
themeRepoModal.find("#input-hideoutdated").prop("checked", hiddenSettings.outdated && !showOnlyOutdated);
|
||||
themeRepoModal.find("#input-hidedownloadable").prop("checked", hiddenSettings.downloadable || showOnlyOutdated);
|
||||
if (!BDFDB.isRestartNoMoreEnabled()) BDFDB.removeEles("." + this.getName() + "-modal #RNMoption");
|
||||
if (!BDFDB.isRestartNoMoreEnabled()) BDFDB.removeEles(".themerepo-modal #RNMoption");
|
||||
else themeRepoModal.find("#input-rnmstart").prop("checked", BDFDB.loadData("RNMstart", this, "settings"));
|
||||
themeRepoModal
|
||||
.on("keyup." + this.getName(), BDFDB.dotCN.searchbarinput, () => {
|
||||
|
|
Loading…
Reference in New Issue