This commit is contained in:
Zack Rauen 2020-02-27 16:26:23 -05:00
parent d21f492bf3
commit 41bde44755
6 changed files with 112 additions and 81 deletions

File diff suppressed because one or more lines are too long

26
src/24hour.js Normal file
View File

@ -0,0 +1,26 @@
import {settingsCookie} from "./0globals";
import BDV2 from "./v2";
import Utils from "./utils";
export default new class TFHour {
inject24Hour() {
if (this.cancel24Hour) return;
const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`);
const convert = (data) => {
if (!settingsCookie["bda-gs-6"]) return;
const matched = data.returnValue.match(twelveHour);
if (!matched || matched.length !== 4) return;
if (matched[3] === "AM") return data.returnValue = data.returnValue.replace(matched[0], `${matched[1] === "12" ? "00" : matched[1].padStart(2, "0")}:${matched[2]}`);
return data.returnValue = data.returnValue.replace(matched[0], `${matched[1] === "12" ? "12" : parseInt(matched[1]) + 12}:${matched[2]}`);
};
const cancelCozy = Utils.monkeyPatch(BDV2.TimeFormatter, "calendarFormat", {after: convert}); // Called in Cozy mode
const cancelCompact = Utils.monkeyPatch(BDV2.TimeFormatter, "dateFormat", {after: convert}); // Called in Compact mode
this.cancel24Hour = () => {cancelCozy(); cancelCompact();}; // Cancel both
}
remove24Hour() {
if (this.cancel24Hour) this.cancel24Hour();
}
};

View File

@ -182,23 +182,6 @@ Core.prototype.initObserver = function () {
});
};
Core.prototype.inject24Hour = function() {
if (this.cancel24Hour) return;
const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`);
const convert = (data) => {
if (!settingsCookie["bda-gs-6"]) return;
const matched = data.returnValue.match(twelveHour);
if (!matched || matched.length !== 4) return;
if (matched[3] === "AM") return data.returnValue = data.returnValue.replace(matched[0], `${matched[1] === "12" ? "00" : matched[1].padStart(2, "0")}:${matched[2]}`);
return data.returnValue = data.returnValue.replace(matched[0], `${matched[1] === "12" ? "12" : parseInt(matched[1]) + 12}:${matched[2]}`);
};
const cancelCozy = Utils.monkeyPatch(BDV2.TimeFormatter, "calendarFormat", {after: convert}); // Called in Cozy mode
const cancelCompact = Utils.monkeyPatch(BDV2.TimeFormatter, "dateFormat", {after: convert}); // Called in Compact mode
this.cancel24Hour = () => {cancelCozy(); cancelCompact();}; // Cancel both
};
Core.prototype.showChangelogModal = function(options = {}) {
const ModalStack = WebpackModules.findByProps("push", "update", "pop", "popWithKey");
const ChangelogClasses = WebpackModules.findByProps("fixed", "improved");

View File

@ -1,6 +1,7 @@
import {settingsCookie} from "./0globals";
import BDV2 from "./v2";
import webpackModules from "./webpackModules";
import Utils from "./utils";
import V2C_PublicServers from "./react/publicServers";
import Layer from "./react/layer";
@ -66,8 +67,8 @@ export default new class V2_PublicServers {
addButton() {
if (this.guildPatch) return;
const GuildList = webpackModules.findModuleByDisplayName("Guilds");
this.guildPatch = webpackModules.monkeyPatch(GuildList.prototype, "render", {after: this._appendButton});
const GuildList = webpackModules.findByDisplayName("Guilds");
this.guildPatch = Utils.monkeyPatch(GuildList.prototype, "render", {after: this._appendButton});
this._appendButton();
}

View File

@ -8,6 +8,7 @@ import BDEvents from "./bdEvents";
import pluginModule from "./pluginModule";
import themeModule from "./themeModule";
import coloredText from "./coloredText";
import tfHour from "./24hour";
import publicServersModule from "./publicServers";
import voiceMode from "./voiceMode";
@ -144,7 +145,7 @@ export default new class V2_SettingsPanel {
else $("#app-mount").removeClass("bda-dark");
}
if (enabled && id == "bda-gs-6") coloredText.inject24Hour();
if (enabled && id == "bda-gs-6") tfHour.inject24Hour();
if (id == "bda-gs-7") {
if (enabled) coloredText.injectColoredText();
@ -196,7 +197,7 @@ export default new class V2_SettingsPanel {
this.saveSettings();
}
initializeSettings() {
async initializeSettings() {
// if (settingsCookie["bda-gs-b"]) $("body").addClass("bd-blue");
if (settingsCookie["bda-gs-2"]) $("body").addClass("bd-minimal");
@ -204,7 +205,7 @@ export default new class V2_SettingsPanel {
if (settingsCookie["bda-gs-1"]) publicServersModule.addButton();
if (settingsCookie["bda-gs-4"]) voiceMode.enable();
if (settingsCookie["bda-gs-5"]) $("#app-mount").addClass("bda-dark");
if (settingsCookie["bda-gs-6"]) coloredText.inject24Hour();
if (settingsCookie["bda-gs-6"]) tfHour.inject24Hour();
if (settingsCookie["bda-gs-7"]) coloredText.injectColoredText();
if (settingsCookie["bda-es-4"]) emoteModule.autoCapitalize();
if (settingsCookie["fork-ps-4"]) ClassNormalizer.start();
@ -222,7 +223,7 @@ export default new class V2_SettingsPanel {
saveSettings() {
DataStore.setSettingGroup("settings", settingsCookie);
}
loadSettings() {
Object.assign(settingsCookie, DataStore.getSettingGroup("settings"));
}

View File

@ -4,7 +4,7 @@ const CircularDependencyPlugin = require("circular-dependency-plugin");
module.exports = {
mode: "development",
target: "node",
devtool: "eval-source-map",
devtool: "eval-cheap-source-map",
entry: "./src/index.js",
output: {
filename: "main.js",