Update TimedLightDarkMode.plugin.js
This commit is contained in:
parent
2ccac5efec
commit
181885cf20
|
@ -1,6 +1,9 @@
|
|||
//META{"name":"TimedLightDarkMode","authorId":"278543574059057154","invite":"Jx3TjNS","donate":"https://www.paypal.me/MircoWittrien","patreon":"https://www.patreon.com/MircoWittrien","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/TimedLightDarkMode","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/TimedLightDarkMode/TimedLightDarkMode.plugin.js"}*//
|
||||
|
||||
class TimedLightDarkMode {
|
||||
var TimedLightDarkMode = (_ => {
|
||||
var settings = {}, values = {};
|
||||
|
||||
return class TimedLightDarkMode {
|
||||
getName () {return "TimedLightDarkMode";}
|
||||
|
||||
getVersion () {return "1.0.6";}
|
||||
|
@ -62,9 +65,9 @@ class TimedLightDarkMode {
|
|||
if (this.started) return;
|
||||
BDFDB.PluginUtils.init(this);
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
|
||||
this.startInterval();
|
||||
|
||||
BDFDB.ModuleUtils.forceAllUpdates(this);
|
||||
}
|
||||
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
||||
}
|
||||
|
@ -86,9 +89,7 @@ class TimedLightDarkMode {
|
|||
|
||||
processRadioGroup (e) {
|
||||
if (e.instance.props && Array.isArray(e.instance.props.options) && e.instance.props.options[0] && (e.instance.props.options[0].value == "light" || e.instance.props.options[0].value == "dark") && e.instance.props.options[1] && (e.instance.props.options[1].value == "light" || e.instance.props.options[1].value == "dark") && e.node.parentElement.firstElementChild.innerText && e.node.parentElement.firstElementChild.innerText.toUpperCase() == BDFDB.LanguageUtils.LanguageStrings.THEME.toUpperCase()) {
|
||||
let settings = BDFDB.DataUtils.get(this, "settings");
|
||||
let values = BDFDB.DataUtils.get(this, "values");
|
||||
let slider, settingsbox = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCNS._timedlightdarkmodetimersettings + BDFDB.disCN.margintop8}"></div>`);
|
||||
let slider, settingsBox = BDFDB.DOMUtils.create(`<div class="${BDFDB.disCNS._timedlightdarkmodetimersettings + BDFDB.disCN.margintop8}"></div>`);
|
||||
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(BDFDB.ReactUtils.Fragment, {
|
||||
children: [
|
||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
|
@ -112,27 +113,28 @@ class TimedLightDarkMode {
|
|||
}
|
||||
})
|
||||
]
|
||||
}), settingsbox);
|
||||
e.node.parentElement.appendChild(settingsbox);
|
||||
}), settingsBox);
|
||||
e.node.parentElement.appendChild(settingsBox);
|
||||
}
|
||||
}
|
||||
|
||||
startInterval () {
|
||||
BDFDB.TimeUtils.clear(this.checkInterval);
|
||||
if (BDFDB.DataUtils.get(this, "settings", "running")) {
|
||||
let values = BDFDB.DataUtils.get(this, "values");
|
||||
settings = BDFDB.DataUtils.get(this, "settings");
|
||||
values = BDFDB.DataUtils.get(this, "values");
|
||||
if (settings.running) {
|
||||
let inverted = values.timer1 > values.timer2;
|
||||
let timer1LOW = this.getTime(values.timer1), timer2LOW = this.getTime(values.timer2);
|
||||
let timer1HIGH = this.getHighTime(timer2LOW), timer2HIGH = this.getHighTime(timer1LOW);
|
||||
let check = _ => {
|
||||
let currenttime = new Date();
|
||||
let currenthours = currenttime.getHours();
|
||||
let currentminutes = currenttime.getMinutes();
|
||||
if (inverted) this.changeTheme(!(this.checkTime(timer1LOW, timer1HIGH, [currenthours, currentminutes])));
|
||||
else this.changeTheme(this.checkTime(timer2LOW, timer2HIGH, [currenthours, currentminutes]));
|
||||
let currentTime = new Date();
|
||||
let currentHours = currentTime.getHours();
|
||||
let currentMinutes = currentTime.getMinutes();
|
||||
if (inverted) this.changeTheme(!(this.checkTime(timer1LOW, timer1HIGH, [currentHours, currentMinutes])));
|
||||
else this.changeTheme(this.checkTime(timer2LOW, timer2HIGH, [currentHours, currentMinutes]));
|
||||
};
|
||||
check();
|
||||
this.checkInterval = BDFDB.TimeUtils.interval(check, 60000);
|
||||
this.checkInterval = BDFDB.TimeUtils.interval(_ => {check();}, 60000);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,12 +149,12 @@ class TimedLightDarkMode {
|
|||
}
|
||||
|
||||
showCurrentTime (grabber) {
|
||||
let currenttime = new Date();
|
||||
let currenthours = currenttime.getHours();
|
||||
let currentminutes = currenttime.getMinutes();
|
||||
let bubble = BDFDB.DOMUtils.create(`<span class="${BDFDB.disCN.sliderbubble}">${(currenthours > 9 ? currenthours : ("0" + currenthours)) + ":" + (currentminutes > 9 ? currentminutes : ("0" + currentminutes))}</span>`);
|
||||
let currentTime = new Date();
|
||||
let currentHours = currentTime.getHours();
|
||||
let currentMinutes = currentTime.getMinutes();
|
||||
let bubble = BDFDB.DOMUtils.create(`<span class="${BDFDB.disCN.sliderbubble}">${(currentHours > 9 ? currentHours : ("0" + currentHours)) + ":" + (currentMinutes > 9 ? currentMinutes : ("0" + currentMinutes))}</span>`);
|
||||
grabber.appendChild(bubble);
|
||||
grabber.style.setProperty("left", `${this.getPercent(currenttime)}%`);
|
||||
grabber.style.setProperty("left", `${this.getPercent(currentTime)}%`);
|
||||
let mouseleave = _ => {
|
||||
BDFDB.DOMUtils.remove(bubble);
|
||||
grabber.removeEventListener("mouseleave", mouseleave);
|
||||
|
@ -165,7 +167,6 @@ class TimedLightDarkMode {
|
|||
if (BDFDB.DOMUtils.containsClass(track.parentNode, BDFDB.disCN.sliderdisabled)) return;
|
||||
let timer = grabber.getAttribute("timer");
|
||||
let input = track.parentNode.querySelector(`${BDFDB.dotCN.sliderinput}[timer="${timer}"]`);
|
||||
let values = BDFDB.DataUtils.get(this, "values");
|
||||
|
||||
BDFDB.DOMUtils.appendLocalStyle("disableTextSelection", `*{user-select: none !important;}`);
|
||||
|
||||
|
@ -232,4 +233,5 @@ class TimedLightDarkMode {
|
|||
if (hours < 0) hours = 0;
|
||||
return [hours, minutes];
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue