Update 0BDFDB.plugin.js

This commit is contained in:
Mirco Wittrien 2021-04-16 19:25:19 +02:00
parent 20ef1355bc
commit 59f9fd2b99
1 changed files with 44 additions and 25 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 1.5.5
* @version 1.5.6
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -22,10 +22,18 @@ module.exports = (_ => {
"info": {
"name": "BDFDB",
"author": "DevilBro",
"version": "1.5.5",
"version": "1.5.6",
"description": "Required Library for DevilBro's Plugins"
},
"rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`
"rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`,
"changeLog": {
"fixed": {
"Break on old BD": "Fixed Library not initializing on the outdated BD version"
},
"added": {
"Date Input Timezone": "Added option to change timezone for date format inputs"
}
}
};
const DiscordObjects = {};
@ -272,7 +280,7 @@ module.exports = (_ => {
};
BDFDB.ObjectUtils.extract = function (obj, ...keys) {
let newObj = {};
if (BDFDB.ObjectUtils.is(obj)) for (let key of keys.flat(10).filter(n => n)) if (obj[key]) newObj[key] = obj[key];
if (BDFDB.ObjectUtils.is(obj)) for (let key of keys.flat(10).filter(n => n)) if (obj[key] != null) newObj[key] = obj[key];
return newObj;
};
BDFDB.ObjectUtils.exclude = function (obj, ...keys) {
@ -2091,14 +2099,14 @@ module.exports = (_ => {
if (!module.BDFDB_patches || !module.BDFDB_patches[methodName]) return (methodName == "render" || methodName == "default") && data.returnValue === undefined ? null : data.returnValue;
let hasInsteadPatches = BDFDB.ObjectUtils.toArray(module.BDFDB_patches[methodName].instead).some(priorityObj => !BDFDB.ObjectUtils.isEmpty(priorityObj));
if (hasInsteadPatches) for (let priority in module.BDFDB_patches[methodName].instead) for (let id in BDFDB.ObjectUtils.sort(module.BDFDB_patches[methodName].instead[priority])) {
if (hasInsteadPatches) for (let priority in module.BDFDB_patches[methodName].instead) for (let id in BDFDB.ObjectUtils.sort(module.BDFDB_patches[methodName].instead[priority])) if (module.BDFDB_patches) {
let tempReturn = BDFDB.TimeUtils.suppress(module.BDFDB_patches[methodName].instead[priority][id], `"instead" callback of ${methodName} in ${name}`, {name: module.BDFDB_patches[methodName].instead[priority][id].pluginName, version: module.BDFDB_patches[methodName].instead[priority][id].pluginVersion})(data);
if (tempReturn !== undefined) data.returnValue = tempReturn;
}
if ((!hasInsteadPatches || callInstead) && !stopCall) BDFDB.TimeUtils.suppress(data.callOriginalMethod, `originalMethod of ${methodName} in ${name}`, {name: "Discord"})();
if (!module.BDFDB_patches || !module.BDFDB_patches[methodName]) return methodName == "render" && data.returnValue === undefined ? null : data.returnValue;
for (let priority in module.BDFDB_patches[methodName].after) for (let id in BDFDB.ObjectUtils.sort(module.BDFDB_patches[methodName].after[priority])) {
for (let priority in module.BDFDB_patches[methodName].after) for (let id in BDFDB.ObjectUtils.sort(module.BDFDB_patches[methodName].after[priority])) if (module.BDFDB_patches) {
let tempReturn = BDFDB.TimeUtils.suppress(module.BDFDB_patches[methodName].after[priority][id], `"after" callback of ${methodName} in ${name}`, {name: module.BDFDB_patches[methodName].after[priority][id].pluginName, version: module.BDFDB_patches[methodName].after[priority][id].pluginVersion})(data);
if (tempReturn !== undefined) data.returnValue = tempReturn;
}
@ -5640,10 +5648,11 @@ module.exports = (_ => {
});
}
handleChange() {
if (typeof this.props.onChange == "function") this.props.onChange(BDFDB.ObjectUtils.extract(this.props, "formatString", "dateString", "timeString"));
if (typeof this.props.onChange == "function") this.props.onChange(BDFDB.ObjectUtils.extract(this.props, "formatString", "dateString", "timeString", "timeOffset"));
}
render() {
let input = this, preview;
const defaultOffset = ((new Date()).getTimezoneOffset() * (-1/60));
return BDFDB.ReactUtils.createElement("div", BDFDB.ObjectUtils.exclude(Object.assign({}, this.props, {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.dateinputwrapper, this.props.className),
children: [
@ -5666,6 +5675,17 @@ module.exports = (_ => {
BDFDB.ReactUtils.forceUpdate(preview);
}
}),
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.Select, {
className: BDFDB.disCN.dateinputoffset,
value: this.props.timeOffset != null ? this.props.timeOffset : defaultOffset,
options: [-12.0, -11.0, -10.0, -9.5, -9.0, -8.0, -7.0, -6.0, -5.0, -4.0, -3.5, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 5.75, 6.0, 6.5, 7.0, 8.0, 8.75, 9.0, 9.5, 10.0, 10.5, 11.0, 12.0, 12.75, 13.0, 14.0].map(offset => ({label: offset< 0 ? offset : `+${offset}`, value: offset})),
searchable: true,
onChange: value => {
this.props.timeOffset = value == defaultOffset ? undefined : value;
this.handleChange.apply(this, []);
BDFDB.ReactUtils.forceUpdate(preview);
}
}),
this.renderFormatButton({
name: BDFDB.LanguageUtils.LanguageStrings.DATE,
svgName: InternalComponents.LibraryComponents.SvgIcon.Names.CALENDAR,
@ -5731,11 +5751,7 @@ module.exports = (_ => {
children: typeof input.props.prefix == "function" ? input.props.prefix(input) : input.props.prefix,
}),
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TextScroller, {
children: InternalComponents.LibraryComponents.DateInput.format({
formatString: input.props.formatString,
dateString: input.props.dateString,
timeString: input.props.timeString
}, new Date((new Date()) - (1000*60*60*24*2)))
children: InternalComponents.LibraryComponents.DateInput.format(input.props, new Date((new Date()) - (1000*60*60*24*2)))
}),
input.props.suffix && BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.dateinputpreviewsuffix,
@ -5748,7 +5764,7 @@ module.exports = (_ => {
]
})
]
}), "onChange", "label", "formatString", "dateString", "timeString", "noPreview", "prefix", "suffix"));
}), "onChange", "label", "formatString", "dateString", "timeString", "timeOffset", "noPreview", "prefix", "suffix"));
}
};
InternalComponents.LibraryComponents.DateInput.getDefaultString = function () {
@ -5762,19 +5778,21 @@ module.exports = (_ => {
if (timeObj.toString() == "Invalid Date" || typeof timeObj.toLocaleDateString != "function") timeObj = new Date();
return timeObj;
};
InternalComponents.LibraryComponents.DateInput.format = function (strings, time) {
if (typeof strings == "string") strings = {formatString: strings};
if (strings && typeof strings.formatString != "string") strings.formatString = "";
if (!strings || typeof strings.formatString != "string" || !time) return "";
const timeObj = InternalComponents.LibraryComponents.DateInput.parseDate(time);
InternalComponents.LibraryComponents.DateInput.format = function (values, time) {
if (typeof values == "string") values = {formatString: values};
if (values && typeof values.formatString != "string") values.formatString = "";
if (!values || typeof values.formatString != "string" || !time) return "";
let timeObj = InternalComponents.LibraryComponents.DateInput.parseDate(time);
const offset = values.timeOffset != null && parseFloat(values.timeOffset);
if ((offset || offset === 0) && !isNaN(offset)) timeObj = new Date(timeObj.getTime() + ((offset - timeObj.getTimezoneOffset() * (-1/60)) * 60*60*1000));
const language = BDFDB.LanguageUtils.getLanguage().id;
const now = new Date();
const daysAgo = Math.round((Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()) - Date.UTC(timeObj.getFullYear(), timeObj.getMonth(), timeObj.getDate()))/(1000*60*60*24));
const date = strings.dateString && typeof strings.dateString == "string" ? InternalComponents.LibraryComponents.DateInput.formatDate(strings.dateString, timeObj) : timeObj.toLocaleDateString(language);
return (strings.formatString || InternalComponents.LibraryComponents.DateInput.getDefaultString())
const date = values.dateString && typeof values.dateString == "string" ? InternalComponents.LibraryComponents.DateInput.formatDate(values.dateString, timeObj) : timeObj.toLocaleDateString(language);
return (values.formatString || InternalComponents.LibraryComponents.DateInput.getDefaultString())
.replace(/\$date/g, date)
.replace(/\$time12/g, strings.timeString && typeof strings.timeString == "string" ? InternalComponents.LibraryComponents.DateInput.formatTime(strings.timeString, timeObj, true) : timeObj.toLocaleTimeString(language, {hourCycle: "h12"}))
.replace(/\$time/g, strings.timeString && typeof strings.timeString == "string" ? InternalComponents.LibraryComponents.DateInput.formatTime(strings.timeString, timeObj) : timeObj.toLocaleTimeString(language, {hourCycle: "h23"}))
.replace(/\$time12/g, values.timeString && typeof values.timeString == "string" ? InternalComponents.LibraryComponents.DateInput.formatTime(values.timeString, timeObj, true) : timeObj.toLocaleTimeString(language, {hourCycle: "h12"}))
.replace(/\$time/g, values.timeString && typeof values.timeString == "string" ? InternalComponents.LibraryComponents.DateInput.formatTime(values.timeString, timeObj) : timeObj.toLocaleTimeString(language, {hourCycle: "h23"}))
.replace(/\$monthS/g, timeObj.toLocaleDateString(language, {month: "short"}))
.replace(/\$month/g, timeObj.toLocaleDateString(language, {month: "long"}))
.replace(/\$dayS/g, timeObj.toLocaleDateString(language, {weekday: "short"}))
@ -6664,13 +6682,14 @@ module.exports = (_ => {
}
render() {
return BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.selectwrapper,
children: BDFDB.ReactUtils.createElement(InternalComponents.NativeSubComponents.SearchableSelect, Object.assign({}, this.props, {
className: BDFDB.DOMUtils.formatClassName(this.props.className, BDFDB.disCN.selectwrapper),
children: BDFDB.ReactUtils.createElement(InternalComponents.NativeSubComponents.SearchableSelect, BDFDB.ObjectUtils.exclude(Object.assign({}, this.props, {
className: this.props.inputClassName,
autoFocus: this.props.autoFocus ? this.props.autoFocus : false,
maxVisibleItems: this.props.maxVisibleItems || 7,
renderOptionLabel: this.props.optionRenderer,
onChange: this.handleChange.bind(this)
}))
}), "inputClassName", "optionRenderer"))
});
}
};