Add text validate for dark schedule

This commit is contained in:
the1812 2018-09-28 16:57:07 +08:00
parent f096943dbd
commit ec2aa12100
6 changed files with 47 additions and 11 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,7 @@
const $ = unsafeWindow.$ || self$;
const settings = {
darkScheduleStart: "18:00",
darkScheduleEnd: "06:00",
darkScheduleEnd: "6:00",
darkSchedule: false,
blurSettingsPanel: false,
blurVideoControl: false,

View File

@ -22,7 +22,7 @@
const $ = unsafeWindow.$ || self$;
const settings = {
darkScheduleStart: "18:00",
darkScheduleEnd: "06:00",
darkScheduleEnd: "6:00",
darkSchedule: false,
blurSettingsPanel: false,
blurVideoControl: false,

File diff suppressed because one or more lines are too long

View File

@ -26,7 +26,7 @@
ok: "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"
};
const textValidate = {
"customStyleColor": text =>
customStyleColor: text =>
{
const match = text.match(/^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/);
if (match)
@ -45,7 +45,7 @@
return settings.customStyleColor;
}
},
"blurBackgroundOpacity": text =>
blurBackgroundOpacity: text =>
{
const match = text.match(/^([-\+]?\d+)(\.\d+)?$/);
if (match)
@ -59,6 +59,42 @@
return settings.blurBackgroundOpacity;
}
};
function darkScheduleValidate(text, defaultValue)
{
const match = text.match(/^([\d]{1,2}):([\d]{1,2})$/);
if (match && match.length >= 3)
{
const time = { hour: match[1], minute: match[2] };
(function ()
{
while (this.minute < 0)
{
this.minute += 60;
this.hour -= 1;
}
while (this.minute >= 60)
{
this.minute -= 60;
this.hour += 1;
}
while (this.hour < 0)
{
this.hour += 24;
}
while (this.hour >= 24)
{
this.hour -= 24;
}
}).call(time);
return `${time.hour}:${time.minute}`;
}
else
{
return defaultValue;
}
}
textValidate.darkScheduleStart = text => darkScheduleValidate(text, settings.darkScheduleStart);
textValidate.darkScheduleEnd = text => darkScheduleValidate(text, settings.darkScheduleEnd);
function settingsChange(key, _, newValue)
{