@@ -81,7 +81,7 @@ window.onload = async (e) => {
8181 const output = range . closest ( 'div' ) . querySelector ( 'output' )
8282 range . value = settings [ range . name ] / divisor
8383 const unit = output . dataset . unit
84- output . innerHTML = await formatUnitAndValue ( unit , range . value )
84+ output . innerHTML = await window . utils . formatUnitAndValue ( unit , range . value )
8585 document . querySelector ( '#longBreakEvery' ) . closest ( 'div' ) . querySelector ( 'output' )
8686 . innerHTML = await window . i18next . t ( 'utils.minutes' , { count : parseInt ( realBreakInterval ( ) ) } )
8787 } )
@@ -205,18 +205,18 @@ window.onload = async (e) => {
205205 const output = range . closest ( 'div' ) . querySelector ( 'output' )
206206 range . value = settings [ range . name ] / divisor
207207 const unit = output . dataset . unit
208- output . innerHTML = await formatUnitAndValue ( unit , range . value )
208+ output . innerHTML = await window . utils . formatUnitAndValue ( unit , range . value )
209209 document . querySelector ( '#longBreakEvery' ) . closest ( 'div' ) . querySelector ( 'output' )
210210 . innerHTML = await window . i18next . t ( 'utils.minutes' , { count : parseInt ( realBreakInterval ( ) ) } )
211211 if ( ! eventsAttached ) {
212212 range . onchange = async event => {
213- output . innerHTML = await formatUnitAndValue ( unit , range . value )
213+ output . innerHTML = await window . utils . formatUnitAndValue ( unit , range . value )
214214 document . querySelector ( '#longBreakEvery' ) . closest ( 'div' ) . querySelector ( 'output' )
215215 . innerHTML = await window . i18next . t ( 'utils.minutes' , { count : parseInt ( realBreakInterval ( ) ) } )
216216 window . settings . saveSettings ( range . name , range . value * divisor )
217217 }
218218 range . oninput = async event => {
219- output . innerHTML = await formatUnitAndValue ( unit , range . value )
219+ output . innerHTML = await window . utils . formatUnitAndValue ( unit , range . value )
220220 document . querySelector ( '#longBreakEvery' ) . closest ( 'div' ) . querySelector ( 'output' )
221221 . innerHTML = await window . i18next . t ( 'utils.minutes' , { count : parseInt ( realBreakInterval ( ) ) } )
222222 }
@@ -321,22 +321,4 @@ window.onload = async (e) => {
321321 const breakInterval = document . querySelector ( '#longBreakEvery' ) . value * 1
322322 return microbreakInterval * ( breakInterval + 1 )
323323 }
324-
325- // TODO take out and test
326- async function formatUnitAndValue ( unit , value ) {
327- if ( unit === 'seconds' ) {
328- if ( value < 60 ) {
329- return await window . i18next . t ( 'utils.seconds' , { count : parseInt ( value ) } )
330- } else {
331- const val = parseFloat ( value / 60 ) . toFixed ( 1 )
332- if ( val % 1 === 0 ) {
333- return await window . i18next . t ( 'utils.minutes' , { count : parseInt ( val ) } )
334- } else {
335- return await window . i18next . t ( 'utils.minutes' , { count : parseFloat ( val ) } )
336- }
337- }
338- } else {
339- return await window . i18next . t ( `utils.${ unit } ` , { count : parseInt ( value ) } )
340- }
341- }
342324}
0 commit comments