mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
1 line
1.6 KiB
JavaScript
1 line
1.6 KiB
JavaScript
(()=>{return(e,t)=>{class i{constructor(...e){if(e.length===0){const e=new Date;this.hour=e.getHours();this.minute=e.getMinutes()}else if(e.length===1){const[t]=e;[this.hour,this.minute]=t.split(":").slice(0,2).map(e=>this.validatePart(e));this.normalize()}else if(v.length===2){[this.hour,this.minute]=e}}validatePart(e){const t=parseInt(e);if(!isNaN(t)&&0<=t&&t<=59){return t}else{return null}}normalize(){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}}lessThan(e){if(this.hour<e.hour||this.hour===e.hour&&this.minute<e.minute){return true}return false}greaterThan(e){if(this.hour>e.hour||this.hour===e.hour&&this.minute>e.minute){return true}return false}equals(e){return this.hour===e.hour&&this.minute===e.minute}isInRange(e,t){if(e.equals(t)){return false}let i=this.greaterThan(e)&&this.lessThan(t);if(e.greaterThan(t)){i=this.greaterThan(e)||this.lessThan(t)}const s=i||this.equals(e);return s}static millisecondsBefore(e){const t=new i;const s=(new Date).getSeconds();const r=1e3*(t.hour*3600+t.minute*60+s);const n=1e3*(e.hour*3600+e.minute*60);let h=n-r;if(t.greaterThan(e)||t.equals(e)&&s!==0){h+=24*3600*1e3}return h}}function s(){if(e.darkSchedule){const t=new i(e.darkScheduleStart);const r=new i(e.darkScheduleEnd);const n=new i;const h=n.isInRange(t,r);if(e.useDarkStyle!==h){e.useDarkStyle=h;saveSettings(e)}let u=0;if(h){u=i.millisecondsBefore(r)}else{u=i.millisecondsBefore(t)}if(u!==0){setTimeout(()=>s(),u)}}}s();return{export:{ScheduleTime:i}}}})(); |