2018-05-14 12:42:48 +00:00
|
|
|
exports = {
|
|
|
|
manifest: {
|
|
|
|
author: "Cynosphere, BlockBuilder57",
|
|
|
|
name: "Settings API",
|
2018-05-21 17:02:05 +00:00
|
|
|
description: "Hijack the settings menu in any way you feel.",
|
|
|
|
replacements: [
|
2018-05-22 17:30:58 +00:00
|
|
|
{
|
|
|
|
signature:/section:"logout",onClick:function\(\){(.)\.default\.push\(function\((.)\){return (.)\.createElement\((.)\.default,(.)\((.+),(.)\),(.)\((.)\.default,{size:(.)\.default\.Sizes\.MEDIUM,color:(.)\.default\.Colors\.PRIMARY},void 0,((.)\.default\.Messages\.USER_SETTINGS_CONFIRM_LOGOUT)\)\)}\)}/,
|
|
|
|
payload:'section:"logout",onClick:window.__fancyDialog=function(data=$6,txt=$12){$1.default.push(function($2){return $3.createElement($4.default,$5(data,$7),$8($9.default,{size:$10.default.Sizes.MEDIUM,color:$11.default.Colors.PRIMARY},void 0,txt))})}'
|
|
|
|
},
|
2018-05-21 21:58:29 +00:00
|
|
|
{signature:'/function (.)\\(\\){return\\[{(.+)}]}/',payload:'window.$settingsapi={sections:[{$2}]};function $1(){return window.$settingsapi.sections;}'}
|
2018-05-21 17:02:05 +00:00
|
|
|
]
|
2018-05-14 12:42:48 +00:00
|
|
|
},
|
|
|
|
start: function(){
|
|
|
|
var buttons = $api.util.findFuncExports('button-', 'colorBlack');
|
|
|
|
var checkboxes = $api.util.findFuncExports('checkboxEnabled');
|
|
|
|
var misc = $api.util.findFuncExports('statusRed-', 'inputDefault');
|
|
|
|
var misc2 = $api.util.findFuncExports('multiInputField');
|
2018-05-22 19:43:14 +00:00
|
|
|
var misc3 = $api.util.findFuncExports('formText-','formText');
|
2018-05-14 12:42:48 +00:00
|
|
|
var headers = $api.util.findFuncExports('h5-', 'h5');
|
2018-05-22 19:43:14 +00:00
|
|
|
var dividers = wc.findFunc('divider-')[0].exports;
|
2018-05-14 12:42:48 +00:00
|
|
|
|
|
|
|
var panels = wc.findFunc('flexChild-')[0].exports;
|
|
|
|
var panels2 = $api.util.findFuncExports('errorMessage-', 'inputWrapper');
|
|
|
|
|
|
|
|
let sections = window.$settingsapi.sections;
|
2018-05-22 17:30:58 +00:00
|
|
|
let dialog = window.__fancyDialog;
|
|
|
|
|
|
|
|
delete window.__fancyDialog;
|
2018-05-14 12:42:48 +00:00
|
|
|
|
|
|
|
window.$settingsapi = {
|
|
|
|
sections: sections,
|
|
|
|
ourSections: [],
|
|
|
|
_callbacks: {},
|
|
|
|
_panels: {},
|
2018-05-22 02:27:12 +00:00
|
|
|
addSection: function(name,label,color=null,callback,pos=null){
|
2018-05-14 12:42:48 +00:00
|
|
|
let data = {};
|
|
|
|
|
|
|
|
data.section = name || `SAPI_${Math.floor(Math.random()*10000)}`;
|
|
|
|
data.label = label;
|
2018-05-21 17:02:05 +00:00
|
|
|
data.color = color;
|
2018-05-14 12:42:48 +00:00
|
|
|
data.element = $api.util.findConstructor('FormSection', 'FormSection').FormSection;
|
|
|
|
|
|
|
|
$settingsapi.ourSections.push(data);
|
2018-05-22 01:01:15 +00:00
|
|
|
$settingsapi.sections.splice(pos ? pos : $settingsapi.sections.length-4,0,data);
|
2018-05-14 12:42:48 +00:00
|
|
|
$settingsapi._callbacks[name] = callback;
|
|
|
|
},
|
2018-05-22 19:43:14 +00:00
|
|
|
addDivider: function(){
|
2018-05-21 17:02:05 +00:00
|
|
|
$settingsapi.ourSections.push({section:"DIVIDER"});
|
2018-05-22 19:43:14 +00:00
|
|
|
$settingsapi.sections.splice($settingsapi.sections.length-4,0,{section:"DIVIDER"});
|
2018-05-21 17:02:05 +00:00
|
|
|
},
|
2018-05-22 19:43:14 +00:00
|
|
|
addHeader: function(label){
|
2018-05-21 17:02:05 +00:00
|
|
|
$settingsapi.ourSections.push({section:"HEADER",label:label});
|
2018-05-22 19:43:14 +00:00
|
|
|
$settingsapi.sections.splice($settingsapi.sections.length-4,0,{section:"HEADER",label:label});
|
2018-05-21 17:02:05 +00:00
|
|
|
},
|
2018-05-22 17:30:58 +00:00
|
|
|
fancyDialog: dialog,
|
2018-05-14 12:42:48 +00:00
|
|
|
//All of these allow us to use Discord's elements.
|
|
|
|
elements: {
|
|
|
|
createVerticalPanel: function() {
|
|
|
|
return createElement("div")
|
|
|
|
.withClass(panels2.vertical, 'epButtonPanel')
|
|
|
|
},
|
|
|
|
createHorizontalPanel: function() {
|
|
|
|
return createElement("div")
|
|
|
|
.withClass(panels.horizontal, 'epButtonPanel')
|
|
|
|
},
|
|
|
|
createButton: function(name) {
|
|
|
|
return createElement('button')
|
|
|
|
.withContents(name)
|
|
|
|
.withClass(
|
|
|
|
buttons.button,
|
|
|
|
buttons.lookFilled,
|
|
|
|
buttons.colorBrand,
|
|
|
|
buttons.sizeSmall,
|
|
|
|
buttons.grow,
|
|
|
|
'epMargin'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
createWarnButton: function(name) {
|
|
|
|
return createElement('button')
|
|
|
|
.withContents(name)
|
|
|
|
.withClass(
|
|
|
|
buttons.button,
|
|
|
|
buttons.lookOutlined,
|
|
|
|
buttons.colorYellow,
|
|
|
|
buttons.sizeSmall,
|
|
|
|
buttons.grow,
|
|
|
|
'epMargin'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
createDangerButton: function(name) {
|
|
|
|
return createElement('button')
|
|
|
|
.withContents(name)
|
|
|
|
.withClass(
|
|
|
|
buttons.button,
|
|
|
|
buttons.lookOutlined,
|
|
|
|
buttons.colorRed,
|
|
|
|
buttons.sizeSmall,
|
|
|
|
buttons.grow,
|
|
|
|
'epMargin'
|
|
|
|
);
|
|
|
|
},
|
|
|
|
createH2: function(text) {
|
|
|
|
return createElement("h2")
|
|
|
|
.withClass(
|
|
|
|
headers.h2,
|
|
|
|
headers.title,
|
|
|
|
headers.size16,
|
|
|
|
headers.height20,
|
|
|
|
headers.weightSemiBold,
|
|
|
|
headers.defaultColor,
|
|
|
|
'epMargin'
|
|
|
|
)
|
|
|
|
.withText(text);
|
|
|
|
},
|
|
|
|
createH5: function(text) {
|
|
|
|
return createElement("h5")
|
|
|
|
.withClass(
|
|
|
|
headers.h5,
|
|
|
|
headers.title,
|
|
|
|
headers.size12,
|
|
|
|
headers.height16,
|
|
|
|
headers.weightSemiBold
|
|
|
|
)
|
|
|
|
.withText(text);
|
|
|
|
},
|
2018-05-21 17:02:05 +00:00
|
|
|
createInput: function(v, p) {
|
2018-05-14 12:42:48 +00:00
|
|
|
return createElement("input")
|
|
|
|
.withClass(
|
|
|
|
misc.inputDefault,
|
|
|
|
misc.input,
|
|
|
|
misc.size16,
|
|
|
|
'epMargin'
|
|
|
|
)
|
2018-05-21 17:02:05 +00:00
|
|
|
.modify(x => x.value = v ? v : "")
|
|
|
|
.modify(x => x.placeholder = p ? p : "")
|
2018-05-14 12:42:48 +00:00
|
|
|
},
|
|
|
|
updateSwitch: function(s, w) {
|
|
|
|
if (s.checked) {
|
|
|
|
w.classList.remove(checkboxes.valueUnchecked.split(' ')[0]);
|
|
|
|
w.classList.add(checkboxes.valueChecked.split(' ')[0])
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
w.classList.remove(checkboxes.valueChecked.split(' ')[0]);
|
|
|
|
w.classList.add(checkboxes.valueUnchecked.split(' ')[0])
|
|
|
|
}
|
|
|
|
},
|
|
|
|
createSwitch: function(c, i) {
|
|
|
|
if (c === undefined) c = () => { };
|
|
|
|
if (i === undefined) i = false;
|
|
|
|
var s, w = createElement('div')
|
|
|
|
.withClass(
|
|
|
|
checkboxes.switch,
|
|
|
|
checkboxes.switchEnabled,
|
|
|
|
checkboxes.size,
|
|
|
|
checkboxes.sizeDefault,
|
|
|
|
checkboxes.themeDefault
|
|
|
|
)
|
|
|
|
.withChildren(
|
|
|
|
s = createElement("input")
|
|
|
|
.withClass(
|
|
|
|
checkboxes.checkbox,
|
|
|
|
checkboxes.checkboxEnabled
|
|
|
|
)
|
|
|
|
.modify(x => x.type = 'checkbox')
|
|
|
|
.modify(x => x.checked = i)
|
|
|
|
.modify(x => x.onchange = () => {
|
2018-05-21 17:02:05 +00:00
|
|
|
$settingsapi.elements.updateSwitch(s, w);
|
2018-05-14 12:42:48 +00:00
|
|
|
c(s.checked);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
$settingsapi.elements.updateSwitch(s, w);
|
|
|
|
return w;
|
2018-05-21 17:02:05 +00:00
|
|
|
},
|
|
|
|
internal:{
|
|
|
|
panels:panels,
|
|
|
|
panels2:panels2,
|
|
|
|
buttons:buttons,
|
|
|
|
checkboxes:checkboxes,
|
|
|
|
misc:misc,
|
|
|
|
misc2:misc2,
|
2018-05-22 19:43:14 +00:00
|
|
|
misc3:misc3,
|
|
|
|
headers:headers,
|
|
|
|
dividers:dividers
|
2018-05-14 12:42:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Example settings tab
|
2018-05-22 19:43:14 +00:00
|
|
|
/*$settingsapi.addDivider();
|
2018-05-21 17:02:05 +00:00
|
|
|
$settingsapi.addHeader("Element Testing");
|
|
|
|
$settingsapi.addSection("TESTING","Element Test Page",null,function(pnl){
|
|
|
|
let em = $settingsapi.elements;
|
|
|
|
em.createH2("Hello World! Heading 2").appendTo(pnl);
|
|
|
|
em.createH5("Hello World! Heading 5").appendTo(pnl);
|
|
|
|
em.createButton("Button!").appendTo(pnl);
|
|
|
|
em.createWarnButton("Warning Button!").appendTo(pnl);
|
|
|
|
em.createDangerButton("Danger Button!").appendTo(pnl);
|
|
|
|
em.createInput("","Input Box!").appendTo(pnl);
|
|
|
|
em.createSwitch().appendTo(pnl);
|
|
|
|
|
|
|
|
let v = em.createVerticalPanel().appendTo(pnl);
|
|
|
|
let h = em.createHorizontalPanel().appendTo(pnl);
|
|
|
|
|
|
|
|
em.createH2("Vertical Panel!").appendTo(v);
|
|
|
|
em.createButton("Beep Boop").appendTo(v);
|
2018-05-14 12:42:48 +00:00
|
|
|
|
2018-05-21 17:02:05 +00:00
|
|
|
em.createH2("Horizontal Panel!").appendTo(h);
|
|
|
|
em.createButton("Boop Beep").appendTo(h);
|
2018-05-22 01:01:15 +00:00
|
|
|
});*/
|
2018-05-21 17:02:05 +00:00
|
|
|
|
|
|
|
function setupSettings(e){
|
|
|
|
for(let i in $settingsapi._panels){
|
|
|
|
$settingsapi._panels[i].remove();
|
|
|
|
}
|
2018-05-14 12:42:48 +00:00
|
|
|
|
|
|
|
for(let i in $settingsapi.ourSections){
|
|
|
|
let data = $settingsapi.ourSections[i];
|
|
|
|
if(e.section == data.section){
|
|
|
|
var pane = $(".content-column.default");
|
|
|
|
if (!pane) return;
|
|
|
|
|
|
|
|
$settingsapi._panels[data.section] = createElement('div')
|
|
|
|
.withClass('flex-vertical')
|
|
|
|
.appendTo(pane);
|
|
|
|
|
|
|
|
$settingsapi._callbacks[data.section]($settingsapi._panels[data.section]);
|
|
|
|
}
|
|
|
|
}
|
2018-05-21 17:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$api.events.hook("USER_SETTINGS_MODAL_SET_SECTION",setupSettings);
|
2018-05-22 02:26:39 +00:00
|
|
|
$api.events.hook("USER_SETTINGS_MODAL_INIT",e=>setTimeout(_=>setupSettings(e),1));
|
2018-05-14 12:42:48 +00:00
|
|
|
}
|
2018-05-22 01:01:15 +00:00
|
|
|
}
|