This commit is contained in:
Mirco Wittrien 2021-03-15 11:46:49 +01:00
parent 22112b691c
commit f8f3fe5067
2 changed files with 10 additions and 70 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 1.4.6
* @version 1.4.7
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -22,7 +22,7 @@ module.exports = (_ => {
"info": {
"name": "BDFDB",
"author": "DevilBro",
"version": "1.4.6",
"version": "1.4.7",
"description": "Required Library for DevilBro's Plugins"
},
"rawUrl": `https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js`,
@ -3919,67 +3919,6 @@ module.exports = (_ => {
}
else return original;
};
BDFDB.StringUtils.formatTime = function (time, config = {}) {
let timeObj = time || new Date();
if (typeof time == "string" || typeof time == "number") timeObj = new Date(time);
if (timeObj.toString() == "Invalid Date") timeObj = new Date(parseInt(time));
if (timeObj.toString() == "Invalid Date" || typeof timeObj.toLocaleDateString != "function") return "";
let languageId = config.language && BDFDB.LanguageUtils.languages[config.language] ? config.language : BDFDB.LanguageUtils.getLanguage().id, timeString = "";
if (!config.formatString || typeof config.formatString != "string") {
const cutOffSeconds = string => {
return string.replace(/(.{1,2}:.{1,2}):.{1,2}(.*)/, "$1$2").replace(/(.{1,2}\..{1,2})\..{1,2}(.*)/, "$1$2").replace(/(.{1,2} h .{1,2} min) .{1,2} s(.*)/, "$1$2");
};
const addLeadingZeros = string => {
let charArray = string.split("");
let numReg = /[0-9]/;
for (let i = 0; i < charArray.length; i++) if (!numReg.test(charArray[i-1]) && numReg.test(charArray[i]) && !numReg.test(charArray[i+1])) charArray[i] = "0" + charArray[i];
return charArray.join("");
};
let timestamp = [];
if (config.displayDate) timestamp.push(timeObj.toLocaleDateString(languageId));
if (config.displayTime) timestamp.push(config.cutSeconds ? cutOffSeconds(timeObj.toLocaleTimeString(languageId)) : timeObj.toLocaleTimeString(languageId));
if (config.otherOrder) timestamp.reverse();
timeString = timestamp.length > 1 ? timestamp.join(", ") : (timestamp.length > 0 ? timestamp[0] : "");
if (timeString && config.forceZeros) timeString = addLeadingZeros(timeString);
}
else {
let hours = timeObj.getHours();
let minutes = timeObj.getMinutes();
let seconds = timeObj.getSeconds();
let milliSeconds = timeObj.getMilliseconds();
let day = timeObj.getDate();
let month = timeObj.getMonth()+1;
let timeMode = "";
let now = new Date();
let daysAgo = Math.round((Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()) - Date.UTC(timeObj.getFullYear(), timeObj.getMonth(), timeObj.getDate()))/(1000*60*60*24));
if (config.formatString.indexOf("$timemode") > -1) {
timeMode = hours >= 12 ? "PM" : "AM";
hours = hours % 12;
hours = hours ? hours : 12;
}
timeString = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(config.formatString
.replace(/\$hour/g, config.forceZeros && hours < 10 ? "0" + hours : hours)
.replace(/\$minute/g, minutes < 10 ? "0" + minutes : minutes)
.replace(/\$second/g, seconds < 10 ? "0" + seconds : seconds)
.replace(/\$msecond/g, config.forceZeros ? (milliSeconds < 10 ? "00" + milliSeconds : (milliSeconds < 100 ? "0" + milliSeconds : milliSeconds)) : milliSeconds)
.replace(/\$timemode/g, timeMode)
.replace(/\$weekdayL/g, timeObj.toLocaleDateString(languageId, {weekday: "long"}))
.replace(/\$weekdayS/g, timeObj.toLocaleDateString(languageId, {weekday: "short"}))
.replace(/\$monthnameL/g, timeObj.toLocaleDateString(languageId, {month: "long"}))
.replace(/\$monthnameS/g, timeObj.toLocaleDateString(languageId, {month: "short"}))
.replace(/\$daysago/g, config.maxDaysAgo == 0 || config.maxDaysAgo >= daysAgo ? (daysAgo > 1 ? (config.useDateInDaysAgo ? timeObj.toLocaleDateString(languageId) : BDFDB.LanguageUtils.LanguageStringsFormat("ACTIVITY_FEED_USER_PLAYED_DAYS_AGO", daysAgo)) : BDFDB.LanguageUtils.LanguageStrings[`SEARCH_SHORTCUT_${daysAgo == 1 ? "YESTERDAY" : "TODAY"}`]) : "")
.replace(/\$day/g, config.forceZeros && day < 10 ? "0" + day : day)
.replace(/\$month/g, config.forceZeros && month < 10 ? "0" + month : month)
.replace(/\$yearS/g, parseInt(timeObj.getFullYear().toString().slice(-2)))
.replace(/\$year/g, timeObj.getFullYear())
.trim().split(" ").filter(n => n).join(" "));
}
return timeString;
};
BDFDB.SlateUtils = {};
BDFDB.SlateUtils.isRichValue = function (richValue) {
@ -5669,7 +5608,7 @@ module.exports = (_ => {
});
}
handleChange() {
if (typeof this.props.onChange == "function") this.props.onChange(BDFDB.ObjectUtils.extract(this.props, "customString", "dateString", "timeString"));
if (typeof this.props.onChange == "function") this.props.onChange(BDFDB.ObjectUtils.extract(this.props, "formatString", "dateString", "timeString"));
}
render() {
let input = this, preview;
@ -5688,9 +5627,9 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TextInput, {
className: BDFDB.disCN.dateinputfield,
placeholder: InternalComponents.LibraryComponents.DateInput.getDefaultString(),
value: this.props.customString,
value: this.props.formatString,
onChange: value => {
this.props.customString = value;
this.props.formatString = value;
this.handleChange.apply(this, []);
BDFDB.ReactUtils.forceUpdate(preview);
}
@ -5749,7 +5688,7 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(class DateInputPreview extends LibraryModules.React.Component {
componentDidMount() {preview = this;}
render() {
return BDFDB.ReactUtils.createElement("div", {
return !input.props.noPreview && BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.dateinputpreview,
children: [
input.props.prefix && BDFDB.ReactUtils.createElement("div", {
@ -5758,7 +5697,7 @@ module.exports = (_ => {
}),
BDFDB.ReactUtils.createElement(InternalComponents.LibraryComponents.TextScroller, {
children: InternalComponents.LibraryComponents.DateInput.format({
formatString: input.props.customString,
formatString: input.props.formatString,
dateString: input.props.dateString,
timeString: input.props.timeString
}, new Date((new Date()) - (1000*60*60*24*2)))
@ -5770,7 +5709,7 @@ module.exports = (_ => {
]
})
]
}), "onChange", "label", "customString", "dateString", "timeString", "prefix"));
}), "onChange", "label", "formatString", "dateString", "timeString", "noPreview", "prefix"));
}
};
InternalComponents.LibraryComponents.DateInput.getDefaultString = function () {
@ -5786,6 +5725,7 @@ module.exports = (_ => {
};
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);
const language = BDFDB.LanguageUtils.getLanguage().id;

View File

@ -660,12 +660,12 @@ img:not([src]), img[src=""], img[src="null"] {
[REPLACE_CLASS_dateinputcontrols] {
display: flex;
align-items: center;
margin-bottom: 8px;
}
[REPLACE_CLASS_dateinputpreview] {
display: flex;
align-items: center;
color: var(--header-primary);
margin-top: 8px;
font-weight: normal;
}
[REPLACE_CLASS_dateinputpreviewprefix] {