1
1
//
2
- // Copyright (c) 2020 by Shahed Nasser. All Rights Reserved.
2
+ // Copyright (c) 2021 by Shahed Nasser. All Rights Reserved.
3
3
//
4
4
5
5
$ ( document ) . ready ( function ( ) {
@@ -9,7 +9,9 @@ $(document).ready(function(){
9
9
weekdays = [ 'Monday' , 'Tuesday' , 'Wednesday' , 'Thursday' , 'Friday' , 'Saturday' , 'Sunday' ] ,
10
10
hijriHolidays = [ ] ,
11
11
currentHijriMonths = [ ] ,
12
- extensionURL = encodeURI ( "https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg" ) ;
12
+ extensionURL = encodeURI ( "https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg" ) ,
13
+ prayerTimeFormat = 24 ,
14
+ shouldRefresh = false ;
13
15
const messageRegex = / _ _ M S G _ ( \w + ) _ _ / g,
14
16
months = [ 'January' , 'February' , 'March' , 'April' , 'May' , 'June' , 'July' , 'August' , 'September' ,
15
17
'October' , 'November' , 'December' ] ,
@@ -109,7 +111,7 @@ $(document).ready(function(){
109
111
$ ( ".calendar-container" ) . removeClass ( "show" ) ;
110
112
} ) ;
111
113
112
- function load ( reload , withTopSites , isReport = false ) {
114
+ function load ( reload , withTopSites ) {
113
115
audio = null ;
114
116
$ ( ".reload img" ) . hide ( ) ;
115
117
$ ( ".reload .loader" ) . show ( ) ;
@@ -118,21 +120,32 @@ $(document).ready(function(){
118
120
chrome . storage . local . get ( [ 'image' , 'verse' , 'calendar' , 'prayerTimesCalendar' ] , function ( result ) {
119
121
chrome . storage . sync . get ( [ 'show_translation' , 'translation_language' , 'recitation' ,
120
122
'translation_identifier' , 'show_top_sites' , 'show_athkar' ,
121
- 'calendar_start_day' , 'removed_top_sites' , 'show_prayer_times' ] , function ( syncResult ) {
123
+ 'calendar_start_day' , 'removed_top_sites' , 'show_prayer_times' ,
124
+ 'prayer_times_format' , 'should_refresh' , 'last_update' ] , function ( syncResult ) {
125
+ if ( syncResult . should_refresh ) {
126
+ shouldRefresh = true ;
127
+ }
128
+ if ( syncResult . last_update && ! syncResult . last_update . shown ) {
129
+ Swal . fire ( {
130
+ html : syncResult . last_update . message
131
+ } ) ;
132
+ syncResult . last_update . shown = true ;
133
+ chrome . storage . sync . set ( { last_update : syncResult . last_update } ) ;
134
+ }
122
135
if ( navigator . onLine ) {
123
136
if ( ! syncResult . hasOwnProperty ( 'show_translation' ) || ! syncResult . hasOwnProperty ( 'translation_language' ) ||
124
137
! syncResult . show_translation || ! syncResult . translation_language || ! syncResult . translation_identifier ) {
125
138
$ ( ".translation-container" ) . remove ( ) ;
126
139
}
127
140
let now = ( new Date ( ) ) . getTime ( ) ;
128
- if ( result . hasOwnProperty ( 'image' ) && result . image && now <= result . image . timeout && ! reload && ! isReport ) {
141
+ if ( result . hasOwnProperty ( 'image' ) && result . image && ! shouldRefresh && now <= result . image . timeout && ! reload ) {
129
142
setBackgroundImage ( result . image . src ) ;
130
143
}
131
144
else {
132
145
setNewImage ( reload ) ;
133
146
}
134
147
135
- if ( result . hasOwnProperty ( 'verse' ) && result . verse && now <= result . verse . timeout && ! reload ) {
148
+ if ( result . hasOwnProperty ( 'verse' ) && result . verse && ! shouldRefresh && now <= result . verse . timeout && ! reload ) {
136
149
setVerse ( result . verse . data ) ;
137
150
audio = new Audio ( result . verse . audio ) ;
138
151
if ( syncResult . hasOwnProperty ( 'show_translation' ) && syncResult . show_translation &&
@@ -204,12 +217,17 @@ $(document).ready(function(){
204
217
}
205
218
206
219
if ( ! syncResult . hasOwnProperty ( 'show_prayer_times' ) || syncResult . show_prayer_times ) {
220
+ if ( syncResult . prayer_times_format ) {
221
+ prayerTimeFormat = syncResult . prayer_times_format ;
222
+ }
207
223
if ( ! result . hasOwnProperty ( 'prayerTimesCalendar' ) || ! result . prayerTimesCalendar || ! result . prayerTimesCalendar . hasOwnProperty ( 'month' ) ||
208
224
! result . prayerTimesCalendar . hasOwnProperty ( 'calendar' ) || result . prayerTimesCalendar . month != ( new Date ( ) ) . getMonth ( ) ) {
209
225
getPrayerTimesCalendar ( ) ;
210
226
} else {
211
227
getPrayerTimes ( ) ;
212
228
}
229
+ } else {
230
+ $ ( ".next-prayer" ) . remove ( ) ;
213
231
}
214
232
}
215
233
else {
@@ -644,7 +662,7 @@ $(document).ready(function(){
644
662
` )
645
663
646
664
var toastElList = [ ] . slice . call ( document . querySelectorAll ( '.toast:not(.hide)' ) )
647
- var toastList = toastElList . map ( function ( toastEl ) {
665
+ toastElList . map ( function ( toastEl ) {
648
666
return new bootstrap . Toast ( toastEl , {
649
667
autohide : false
650
668
} ) . show ( )
@@ -669,32 +687,80 @@ $(document).ready(function(){
669
687
670
688
function getPrayerTimes ( ) {
671
689
chrome . storage . local . get ( [ 'prayerTimesCalendar' ] , function ( result ) {
672
- console . log ( result )
673
690
if ( result . hasOwnProperty ( 'prayerTimesCalendar' ) && result . prayerTimesCalendar . hasOwnProperty ( 'calendar' ) ) {
674
691
//get today's prayer times
675
- const today = new Date ( ) ;
692
+ const today = new Date ( ) ,
693
+ todayMoment = moment ( ) ;
676
694
const prayerTimesContainer = $ ( ".prayer-times-container" ) ,
677
695
prayerTimesWrapper = prayerTimesContainer . find ( ".prayer-times-wrapper" ) ;
678
696
prayerTimesContainer . addClass ( 'd-none' ) ;
679
697
prayerTimesWrapper . empty ( ) ;
698
+ let nextPrayerTime = 0 , nextPrayerName = "" ;
680
699
result . prayerTimesCalendar . calendar . some ( ( dateData ) => {
681
700
if ( parseInt ( dateData . date . gregorian . day ) == today . getDate ( ) ) {
701
+ const fajr = formatTime ( dateData . timings . Fajr ) ,
702
+ dhuhr = formatTime ( dateData . timings . Dhuhr ) ,
703
+ asr = formatTime ( dateData . timings . Asr ) ,
704
+ maghrib = formatTime ( dateData . timings . Maghrib ) ,
705
+ isha = formatTime ( dateData . timings . Isha ) ,
706
+ momentFajr = moment ( fajr , getTimeFormat ( ) ) . year ( todayMoment . year ( ) ) . month ( todayMoment . month ( ) ) . date ( todayMoment . date ( ) ) ,
707
+ momentDhuhr = moment ( dhuhr , getTimeFormat ( ) ) . year ( todayMoment . year ( ) ) . month ( todayMoment . month ( ) ) . date ( todayMoment . date ( ) ) ,
708
+ momentAsr = moment ( asr , getTimeFormat ( ) ) . year ( todayMoment . year ( ) ) . month ( todayMoment . month ( ) ) . date ( todayMoment . date ( ) ) ,
709
+ momentMaghrib = moment ( maghrib , getTimeFormat ( ) ) . year ( todayMoment . year ( ) ) . month ( todayMoment . month ( ) ) . date ( todayMoment . date ( ) ) ,
710
+ momentIsha = moment ( isha , getTimeFormat ( ) ) . year ( todayMoment . year ( ) ) . month ( todayMoment . month ( ) ) . date ( todayMoment . date ( ) ) ;
711
+
712
+ switch ( false ) {
713
+ case todayMoment . isAfter ( momentFajr ) :
714
+ nextPrayerTime = todayMoment . to ( momentFajr ) ;
715
+ nextPrayerName = chrome . i18n . getMessage ( 'fajr' ) ;
716
+ break ;
717
+ case todayMoment . isAfter ( momentDhuhr ) :
718
+ nextPrayerTime = todayMoment . to ( momentDhuhr ) ;
719
+ nextPrayerName = chrome . i18n . getMessage ( 'dhuhr' ) ;
720
+ break ;
721
+ case todayMoment . isAfter ( momentAsr ) :
722
+ nextPrayerTime = todayMoment . to ( momentAsr ) ;
723
+ nextPrayerName = chrome . i18n . getMessage ( 'asr' ) ;
724
+ break ;
725
+ case todayMoment . isAfter ( momentMaghrib ) :
726
+ nextPrayerTime = todayMoment . to ( momentMaghrib ) ;
727
+ nextPrayerName = chrome . i18n . getMessage ( 'maghrib' ) ;
728
+ break ;
729
+ case todayMoment . isAfter ( momentIsha ) :
730
+ nextPrayerTime = todayMoment . to ( momentIsha ) ;
731
+ nextPrayerName = chrome . i18n . getMessage ( 'isha' ) ;
732
+ break ;
733
+ }
734
+
682
735
//show prayer times
683
- prayerTimesWrapper . append ( `<div class="prayer-time fajr">${ formatTime ( dateData . timings . Fajr ) } </div>` ) ;
684
- prayerTimesWrapper . append ( `<div class="prayer-time dhuhr">${ formatTime ( dateData . timings . Dhuhr ) } </div>` ) ;
685
- prayerTimesWrapper . append ( `<div class="prayer-time asr">${ formatTime ( dateData . timings . Asr ) } </div>` ) ;
686
- prayerTimesWrapper . append ( `<div class="prayer-time maghrib">${ formatTime ( dateData . timings . Maghrib ) } </div>` ) ;
687
- prayerTimesWrapper . append ( `<div class="prayer-time isha">${ formatTime ( dateData . timings . Isha ) } </div>` ) ;
736
+ prayerTimesWrapper . append ( `<div class="prayer-time fajr">${ fajr } </div>` ) ;
737
+ prayerTimesWrapper . append ( `<div class="prayer-time dhuhr">${ dhuhr } </div>` ) ;
738
+ prayerTimesWrapper . append ( `<div class="prayer-time asr">${ asr } </div>` ) ;
739
+ prayerTimesWrapper . append ( `<div class="prayer-time maghrib">${ maghrib } </div>` ) ;
740
+ prayerTimesWrapper . append ( `<div class="prayer-time isha">${ isha } </div>` ) ;
688
741
prayerTimesContainer . removeClass ( 'd-none' ) ;
689
742
return true ; //break the loop
690
743
}
691
744
return false ;
692
745
} ) ;
746
+
747
+ console . log ( nextPrayerTime , nextPrayerName ) ;
748
+ if ( nextPrayerTime ) {
749
+ $ ( ".next-prayer" ) . text ( nextPrayerName + " " + nextPrayerTime ) ;
750
+ }
693
751
}
694
752
} )
695
753
}
696
754
697
755
function formatTime ( time ) {
698
- return time . split ( " " ) [ 0 ] ;
756
+ let formattedTime = time . split ( " " ) [ 0 ] ;
757
+ const momentTime = moment ( formattedTime , 'HH:mm' ) ;
758
+ formattedTime = momentTime . format ( getTimeFormat ( ) )
759
+
760
+ return formattedTime ;
761
+ }
762
+
763
+ function getTimeFormat ( ) {
764
+ return prayerTimeFormat == 12 ? "hh:mm A" : 'HH:mm' ;
699
765
}
700
766
} ) ;
0 commit comments