This commit is contained in:
Mirco Wittrien 2020-11-23 17:52:58 +01:00
parent 6242f38b47
commit c73f1cc061
3 changed files with 52 additions and 93 deletions

View File

@ -16,7 +16,7 @@ module.exports = (_ => {
"info": {
"name": "BDFDB",
"author": "DevilBro",
"version": "1.1.6",
"version": "1.1.7",
"description": "Give other plugins utility functions"
},
"rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js",
@ -798,26 +798,14 @@ module.exports = (_ => {
BDFDB.PluginUtils.createSettingsPanel = function (addon, props) {
addon = addon == BDFDB && InternalBDFDB || addon;
if (!BDFDB.ObjectUtils.is(addon)) return;
if (isBeta && BDFDB.ObjectUtils.is(props)) {
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.SettingsPanel, Object.assign({
className: BDFDB.DOMUtils.formatClassName(addon.name && `${addon.name}-settings`, BDFDB.disCN.settingspanel),
key: `${addon.name}-settingsPanel`,
addon: addon
}, props));
}
else {
let children = BDFDB.ReactUtils.isValidElement(props) || BDFDB.ArrayUtils.is(props) ? props : (props && typeof props.children == "function" && props.children());
if (!children || (!BDFDB.ReactUtils.isValidElement(children) && !BDFDB.ArrayUtils.is(children))) return;
let settingsPanel = BDFDB.DOMUtils.create(`<div class="${addon.name}-settings ${BDFDB.disCN.settingspanel}"></div>`);
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.SettingsPanel, {
key: `${addon.name}-settingsPanel`,
addon: addon,
title: !isBeta && addon.name,
collapseStates: props && props.collapseStates,
children: children
}), settingsPanel);
return settingsPanel;
}
let settingsProps = props;
if (settingsProps && !BDFDB.ObjectUtils.is(settingsProps) && (BDFDB.ReactUtils.isValidElement(settingsProps) || BDFDB.ArrayUtils.is(settingsProps))) settingsProps = {
children: settingsProps
};
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.SettingsPanel, Object.assign({
addon: addon,
collapseStates: settingsProps && settingsProps.collapseStates
}, settingsProps));
};
BDFDB.PluginUtils.refreshSettingsPanel = function (plugin, settingsPanel, ...args) {
if (BDFDB.ObjectUtils.is(plugin)) {
@ -6332,21 +6320,7 @@ module.exports = (_ => {
componentWillUnmount() {
if (BDFDB.ObjectUtils.is(this.props.addon) && typeof this.props.addon.onSettingsClosed == "function") this.props.addon.onSettingsClosed();
}
render() {
let headerItems = [
this.props.title && BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.FormComponents.FormTitle, {
className: BDFDB.disCN.settingspaneltitle,
tag: InternalComponents.LibraryComponents.FormComponents.FormTitle.Tags.H2,
children: this.props.title
}),
this.props.controls && BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, {
className: BDFDB.disCN.settingspanelheadercontrols,
align: InternalComponents.LibraryComponents.Flex.Align.CENTER,
grow: 0,
children: this.props.controls
})
].flat(10).filter(n => n);
render() {
let panelItems = [
typeof this.props.children == "function" ? (_ => {
return this.props.children(this.props.collapseStates);
@ -6355,25 +6329,13 @@ module.exports = (_ => {
if (this.props.addon && this.props.addon.name) this.key = `${this.props.addon.name}-settingsPanel`;
return BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, {
className: this.props.className,
className: BDFDB.DOMUtils.formatClassName(this.props.addon && this.props.addon.name && `${this.props.addon.name}-settings`, BDFDB.disCN.settingspanel),
direction: InternalComponents.LibraryComponents.Flex.Direction.VERTICAL,
children: headerItems.length ? ([
[
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, {
className: BDFDB.disCN.settingspanelheader,
align: InternalComponents.LibraryComponents.Flex.Align.CENTER,
children: headerItems
}),
panelItems.length && BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.FormComponents.FormDivider, {
className: BDFDB.disCNS.margintop4 + BDFDB.disCN.marginbottom8
})
],
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, {
className: BDFDB.disCN.settingspanelinner,
direction: InternalComponents.LibraryComponents.Flex.Direction.VERTICAL,
children: panelItems
})
].flat(10).filter(n => n)) : panelItems
children: BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Flex, {
className: BDFDB.disCN.settingspanelinner,
direction: InternalComponents.LibraryComponents.Flex.Direction.VERTICAL,
children: panelItems
})
});
}
};
@ -7234,6 +7196,27 @@ module.exports = (_ => {
}));
if (footerControls) for (let control of controls) footerControls.insertBefore(control, footerControls.firstElementChild);
else for (let control of controls) checkbox.parentElement.insertBefore(control, checkbox.parentElement.firstElementChild);
if (!isBeta && typeof plugin.getSettingsPanel == "function") {
let footer = card.querySelector("." + BDFDB.disCN._repofooter.split(" ").join(",."));
if (footer) {
BDFDB.DOMUtils.remove(footer.querySelectorAll(BDFDB.dotCN._reposettingsbutton));
let settingsButton = document.createElement("button");
settingsButton.className = BDFDB.DOMUtils.formatClassName(BDFDB.disCN._reposettingsbutton);
settingsButton.innerText = "Settings";
footer.appendChild(settingsButton);
settingsButton.addEventListener("click", _ => {
BDFDB.ModalUtils.open(plugin, {
header: `${plugin.name} ${BDFDB.LanguageUtils.LanguageStrings.SETTINGS}`,
subheader: "",
className: BDFDB.disCN._repomodal,
size: "MEDIUM",
children: plugin.getSettingsPanel,
buttons: [{contents: BDFDB.LanguageUtils.LanguageStrings.DONE, color: "BRAND", close: true}]
});
});
}
}
}
};
const cardObserver = (new MutationObserver(changes => {changes.forEach(change => {if (change.addedNodes) {change.addedNodes.forEach(node => {

View File

@ -618,7 +618,7 @@
"bdaLink": "bd-link bda-link",
"bdaLinks": "bd-links bd-addon-links bda-links",
"bdaName": "bd-name name bda-name",
"bdaSettingsButton": "bd-button bd-button-addon-settings bd-settings-button bda-settings-button",
"bdaSettingsButton": "bd-button bda-settings-button",
"bdaSlist": "bda-slist bd-addon-list",
"bdaVersion": "bd-version version bda-version",
"bdGuild": "bd-guild",

View File

@ -14,7 +14,7 @@ module.exports = (_ => {
"info": {
"name": "ThemeSettings",
"author": "DevilBro",
"version": "1.2.6",
"version": "1.2.7",
"description": "Allow you to change Theme Variables within BetterDiscord. Adds a Settings button (similar to Plugins) to customizable Themes in your Themes Page"
},
"changeLog": {
@ -83,6 +83,16 @@ module.exports = (_ => {
if (addon && !addon.plugin && !addon.instance && addon.css) {
let vars = this.getThemeVars(addon.css);
if (vars.length) {
let open = _ => {
BDFDB.ModalUtils.open(this, {
header: `${addon.name} ${BDFDB.LanguageUtils.LanguageStrings.SETTINGS}`,
subheader: "",
className: BDFDB.disCN._repomodal,
size: "MEDIUM",
children: this.createThemeVarInputs(addon, vars),
buttons: [{contents: "Update", color: "GREEN", click: modal => {this.updateTheme(modal, addon);}}]
});
};
if (isBeta) {
let controls = card.querySelector("." + BDFDB.disCN._repofooter.split(" ")[0] + " " + BDFDB.dotCN._repocontrols);
let settingsButton = document.createElement("button");
@ -92,16 +102,7 @@ module.exports = (_ => {
<path d="M15.95 10.78c.03-.25.05-.51.05-.78s-.02-.53-.06-.78l1.69-1.32c.15-.12.19-.34.1-.51l-1.6-2.77c-.1-.18-.31-.24-.49-.18l-1.99.8c-.42-.32-.86-.58-1.35-.78L12 2.34c-.03-.2-.2-.34-.4-.34H8.4c-.2 0-.36.14-.39.34l-.3 2.12c-.49.2-.94.47-1.35.78l-1.99-.8c-.18-.07-.39 0-.49.18l-1.6 2.77c-.1.18-.06.39.1.51l1.69 1.32c-.04.25-.07.52-.07.78s.02.53.06.78L2.37 12.1c-.15.12-.19.34-.1.51l1.6 2.77c.1.18.31.24.49.18l1.99-.8c.42.32.86.58 1.35.78l.3 2.12c.04.2.2.34.4.34h3.2c.2 0 .37-.14.39-.34l.3-2.12c.49-.2.94-.47 1.35-.78l1.99.8c.18.07.39 0 .49-.18l1.6-2.77c.1-.18.06-.39-.1-.51l-1.67-1.32zM10 13c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"></path>
</svg>`));
controls.insertBefore(settingsButton, controls.firstElementChild);
settingsButton.addEventListener("click", _ => {
BDFDB.ModalUtils.open(this, {
header: `${addon.name} Settings`,
subheader: "",
className: BDFDB.disCN._repomodal,
size: "MEDIUM",
children: this.createThemeVarInputs(addon, vars),
buttons: [{contents: "Update", color: "GREEN", click: modal => {this.updateTheme(modal, addon);}}]
});
});
settingsButton.addEventListener("click", open);
}
else {
let footer = card.querySelector("." + BDFDB.disCN._repofooter.split(" ").join(",."));
@ -117,32 +118,7 @@ module.exports = (_ => {
settingsButton.className = BDFDB.DOMUtils.formatClassName(BDFDB.disCN._reposettingsbutton, "theme-settings-button");
settingsButton.innerText = "Settings";
footer.appendChild(settingsButton);
settingsButton.addEventListener("click", _ => {
BDFDB.DOMUtils.addClass(card, BDFDB.disCN._reposettingsopen);
BDFDB.DOMUtils.removeClass(card, BDFDB.disCN._reposettingsclosed);
let children = [];
while (card.childElementCount) {
children.push(card.firstChild);
card.firstChild.remove();
}
let closeButton = BDFDB.DOMUtils.create(`<div style="float: right; cursor: pointer;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 12 12" style="width: 18px; height: 18px;"><g class="background" fill="none" fill-rule="evenodd"><path d="M0 0h12v12H0"></path><path class="fill" fill="#dcddde" d="M9.5 3.205L8.795 2.5 6 5.295 3.205 2.5l-.705.705L5.295 6 2.5 8.795l.705.705L6 6.705 8.795 9.5l.705-.705L6.705 6"></path></g></svg></div>`);
card.appendChild(closeButton);
closeButton.addEventListener("click", _ => {
BDFDB.DOMUtils.removeClass(card, BDFDB.disCN._reposettingsopen);
BDFDB.DOMUtils.addClass(card, BDFDB.disCN._reposettingsclosed);
while (card.childElementCount) card.firstChild.remove();
while (children.length) card.appendChild(children.shift());
});
card.appendChild(this.createThemeVarInputs(addon, vars, [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.GREEN,
label: "Update all variables",
onClick: _ => {this.updateTheme(card, addon);},
children: "Update"
})
]));
});
settingsButton.addEventListener("click", open);
}
}
}
@ -232,7 +208,7 @@ module.exports = (_ => {
}
};
return BDFDB.PluginUtils.createSettingsPanel(theme, isBeta ? props : props.children());
return BDFDB.PluginUtils.createSettingsPanel(theme, props);
}
};
})(window.BDFDB_Global.PluginUtils.buildPlugin(config));