@@ -27,6 +27,17 @@ var noSleep = new NoSleep();
2727
2828document . addEventListener ( "DOMContentLoaded" , function ( ) {
2929 device ( ) ;
30+ // Theme
31+ if ( localStorage . getItem ( "theme" ) === "dark" ) {
32+ // ローカルストレージを読み込み、テーマを反映
33+ toggleTheme ( "d" ) ;
34+ } else if ( localStorage . getItem ( "theme" ) === "light" ) {
35+ toggleTheme ( "l" ) ;
36+ } else if ( localStorage . getItem ( "theme" ) === "auto" ) {
37+ toggleTheme ( "a" ) ;
38+ } else {
39+ toggleTheme ( isDark ) ;
40+ }
3041 let params = new URL ( window . location . href ) . searchParams ;
3142 if ( params . get ( "date" ) && params . get ( "time" ) ) {
3243 paramStatus = 0 ;
@@ -185,17 +196,6 @@ function onload() {
185196 /*パラメータ取得*/
186197 showVolume ( ) ;
187198 countTimes = 0 ;
188- // Theme
189- if ( localStorage . getItem ( "theme" ) === "dark" ) {
190- // ローカルストレージを読み込み、テーマを反映
191- toggleTheme ( "d" ) ;
192- } else if ( localStorage . getItem ( "theme" ) === "light" ) {
193- toggleTheme ( "l" ) ;
194- } else if ( localStorage . getItem ( "theme" ) === "auto" ) {
195- toggleTheme ( "a" ) ;
196- } else {
197- toggleTheme ( isDark ) ;
198- }
199199 var param = location . search ;
200200 var paramObject = new Object ( ) ;
201201 param = param . substring ( 1 ) ;
@@ -216,20 +216,21 @@ function onload() {
216216 title = localStorage . getItem ( "ct-title" ) ;
217217 document . getElementById ( "title" ) . value = title ;
218218 }
219- if ( ( setType === "duration" ) || ( firstLoad === 0 && localStorage . getItem ( "ct-lastType" ) == "1" ) && ! paramObject . date && ! paramObject . time ) {
219+ console . log ( myDate + " " + myTime ) ;
220+ console . log ( setType ) ;
221+ if ( ( setType === "duration" ) || ( ( firstLoad === 0 && localStorage . getItem ( "ct-lastType" ) == "1" ) && ! paramObject . date && ! paramObject . time ) ) {
220222 durationStatus = 1 ;
221223 if ( ! document . getElementById ( "durationHeader" ) . classList . contains ( "active" ) ) {
222224 window . addEventListener ( "load" , clickHeader , false ) ;
223225 }
224- localStorage . setItem ( "ct-lastType" , 1 ) ;
225226 changeURL ( ) ;
226- if ( ( ( ( localStorage . getItem ( "ct-lastType" ) && ! firstLoad ) && ( localStorage . getItem ( "ct-lastSet" ) !== "0" ) ) || durationStop ) && ! durationChange ) {
227+ if ( ( ( ( localStorage . getItem ( "ct-lastType" ) === "1" && ! firstLoad ) && ( Number ( localStorage . getItem ( "ct-lastSet" ) ) >= 1000 ) ) || durationStop ) && ! durationChange ) {
227228 let localSet = localStorage . getItem ( "ct-lastSet" ) ;
228229 let localSetHour = Math . floor ( localSet / ( 1000 * 60 * 60 ) ) ;
229230 let localSetMin = Math . floor ( ( localSet - localSetHour * 1000 * 60 * 60 ) / ( 1000 * 60 ) ) ;
230231 let localSetSec = ( localSet - localSetHour * 1000 * 60 * 60 - localSetMin * 1000 * 60 ) / 1000 ;
231232 afterTime ( localSetHour , localSetMin , localSetSec ) ;
232- } else {
233+ } else if ( firstLoad ) {
233234 let elementList = document . getElementsByClassName ( "durationSet" ) ;
234235 for ( let i = 0 ; i < elementList . length ; i ++ ) {
235236 let element = elementList [ i ] ;
@@ -239,10 +240,16 @@ function onload() {
239240 }
240241 afterTime ( document . getElementById ( "hour" ) . value , document . getElementById ( "minute" ) . value , document . getElementById ( "seconds" ) . value ) ;
241242 }
243+ if ( ( ( ( ( localStorage . getItem ( "ct-lastType" ) === "1" && ! firstLoad ) && ( Number ( localStorage . getItem ( "ct-lastSet" ) ) >= 1000 ) ) || durationStop ) && ! durationChange ) || firstLoad ) {
242244 localStorage . setItem ( "ct-lastDuration" , document . getElementById ( "hour" ) . value + ":" + document . getElementById ( "minute" ) . value + ":" + document . getElementById ( "seconds" ) . value ) ;
243245 durationStop = false ;
244246 durationChange = false ;
247+ localStorage . setItem ( "ct-lastType" , 1 ) ;
248+ setType = "duration" ;
245249 down = setInterval ( myCount , 200 ) ;
250+ } else {
251+ noParams ( ) ;
252+ }
246253 function afterTime ( hour , minute , second ) {
247254 let now = new Date ( ) ;
248255 now . setHours ( now . getHours ( ) + Number ( hour ) ) ;
@@ -300,8 +307,36 @@ function myCount() {
300307 var displayPlace = document . getElementById ( "displayTime" ) ;
301308 var date = new Date ( ) ;
302309 var diffTime = target . getTime ( ) - date . getTime ( ) ; //時間の差を計算
303- if ( diffTime ) {
310+ if ( diffTime || diffTime === 0 ) {
304311 localStorage . setItem ( "ct-lastSet" , diffTime ) ;
312+ if ( setType === "duration" ) {
313+ document . getElementById ( "durationIcon" ) . style . display = "inline" ;
314+ document . getElementById ( "targetIcon" ) . style . display = "none" ;
315+ } else {
316+ document . getElementById ( "durationIcon" ) . style . display = "" ;
317+ document . getElementById ( "targetIcon" ) . style . display = "" ;
318+ }
319+ let newMyDate = new Date ( myDate ) ;
320+ let myDisplayTime ;
321+ if ( durationStatus ) {
322+ let myTimeSplit = myTime . split ( ":" ) ;
323+ if ( Number ( myTimeSplit [ 1 ] ) < 10 ) {
324+ myTimeSplit [ 1 ] = "0" + myTimeSplit [ 1 ] ;
325+ }
326+ myDisplayTime = myTimeSplit [ 0 ] + ":" + myTimeSplit [ 1 ] ;
327+ } else {
328+ myDisplayTime = myTime ;
329+ }
330+ if ( newMyDate . getFullYear ( ) === date . getFullYear ( ) ) {
331+ if ( newMyDate . getMonth ( ) === date . getMonth ( ) && newMyDate . getDate ( ) === date . getDate ( ) ) {
332+ document . getElementById ( "alarmTimeValue" ) . textContent = myDisplayTime ;
333+ } else {
334+ document . getElementById ( "alarmTimeValue" ) . textContent = newMyDate . getMonth ( ) + 1 + "/" + newMyDate . getDate ( ) + " " + myDisplayTime ;
335+ }
336+ } else {
337+ document . getElementById ( "alarmTimeValue" ) . textContent =
338+ myDate + " " + myDisplayTime ;
339+ }
305340 }
306341 var diffHour = Math . floor ( diffTime / ( 1000 * 60 * 60 ) ) ; //時間に変換
307342 var diffMinute = Math . floor (
@@ -317,6 +352,10 @@ function myCount() {
317352 diffSecond = "0" + diffSecond ;
318353 }
319354 var display = diffHour + ":" + diffMinute + ":" + diffSecond ;
355+ if ( countTimes === 0 ) {
356+ document . getElementById ( "stopTimer" ) . style . display = "inline-flex" ;
357+ document . getElementById ( "setTimer" ) . style . display = "none" ;
358+ }
320359 if ( display === "0:00:00" ) {
321360 display = "0:00:00" ;
322361 displayPlace . textContent = display ;
@@ -342,6 +381,10 @@ function myCount() {
342381
343382 alarm . play ( ) ;
344383 stop ( ) ;
384+ if ( setType === "duration" ) {
385+ durationChange = true ;
386+ setType = "duration" ;
387+ }
345388 document . title = "やまだのタイマー" ;
346389 displayEnd = setInterval ( function ( ) {
347390 document . title = "時間です!" ;
@@ -365,29 +408,8 @@ function myCount() {
365408 noParams ( ) ;
366409 } else {
367410 if ( countTimes === 0 ) {
368- let newMyDate = new Date ( myDate ) ;
369- let myDisplayTime ;
370- if ( durationStatus ) {
371- let myTimeSplit = myTime . split ( ":" ) ;
372- if ( Number ( myTimeSplit [ 1 ] ) < 10 ) {
373- myTimeSplit [ 1 ] = "0" + myTimeSplit [ 1 ] ;
374- }
375- myDisplayTime = myTimeSplit [ 0 ] + ":" + myTimeSplit [ 1 ] ;
376- } else {
377- myDisplayTime = myTime ;
378- }
379- if ( newMyDate . getFullYear ( ) === date . getFullYear ( ) ) {
380- if ( newMyDate . getMonth ( ) === date . getMonth ( ) && newMyDate . getDate ( ) === date . getDate ( ) ) {
381- document . getElementById ( "alarmTimeValue" ) . textContent = myDisplayTime ;
382- } else {
383- document . getElementById ( "alarmTimeValue" ) . textContent = newMyDate . getMonth ( ) + 1 + "/" + newMyDate . getDate ( ) + " " + myDisplayTime ;
384- }
385- } else {
386- document . getElementById ( "alarmTimeValue" ) . textContent =
387- myDate + " " + myDisplayTime ;
388- }
389- document . getElementById ( "stopTimer" ) . style . display = "inline-flex" ;
390- document . getElementById ( "setTimer" ) . style . display = "none" ;
411+
412+
391413 if ( paramStatus ) {
392414 if ( ! durationStatus ) {
393415 localStorage . setItem ( "ct-date" , myDate ) ;
@@ -430,6 +452,8 @@ function noParams() {
430452 document . getElementById ( "Time" ) . value ;
431453 document . getElementById ( "alarmTimeValue" ) . textContent =
432454 defaultTime + " (自動設定)" ;
455+ localStorage . setItem ( "ct-lastType" , 0 ) ;
456+ durationStatus = 0 ;
433457}
434458function set ( ) {
435459 /*SETボタンを押したときの挙動*/
@@ -885,9 +909,7 @@ document.addEventListener("DOMContentLoaded", () => {
885909 set ( ) ;
886910 } , false ) ;
887911 document . getElementById ( "targetSetBtn" ) . addEventListener ( "click" , ( ) => {
888- if ( setType === "duration" ) {
889- setType = "target" ;
890- }
912+ setType = "target" ;
891913 set ( ) ;
892914 } , false ) ;
893915 document . getElementById ( "setTimer" ) . addEventListener ( "click" , set , false ) ;
0 commit comments