Skip to content

Commit 21e660a

Browse files
committed
added new features
1 parent ee3e250 commit 21e660a

File tree

8 files changed

+173
-22
lines changed

8 files changed

+173
-22
lines changed

_locales/en/messages.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,29 @@
350350
},
351351
"prayer_times_hint": {
352352
"message": "These might not be accurate. Please check the settings to change the method of calculation for a better result."
353+
},
354+
"prayer_times_format": {
355+
"message": "Prayer Times Format"
356+
},
357+
"refresh_every_tab": {
358+
"message": "Should Refresh on Every New Tab"
359+
},
360+
"until": {
361+
"message": "Until"
362+
},
363+
"fajr": {
364+
"message": "Fajr"
365+
},
366+
"dhuhr": {
367+
"message": "Dhuhr"
368+
},
369+
"asr": {
370+
"message": "Asr"
371+
},
372+
"maghrib": {
373+
"message": "Maghrib"
374+
},
375+
"isha": {
376+
"message": "Isha"
353377
}
354378
}

css/styles.css

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2019 by Shahed Nasser. All Rights Reserved.
2+
Copyright (c) 2021 by Shahed Nasser. All Rights Reserved.
33
*/
44

55
@font-face {
@@ -35,7 +35,7 @@ body {
3535
filter: brightness(50%);
3636
}
3737

38-
.verse, .bismillah, .athkar-container, .prayer-times-container {
38+
.verse, .bismillah, .athkar-container, .prayer-times-container, .next-prayer {
3939
font-family: QuranFont, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
4040
}
4141

@@ -404,6 +404,10 @@ body {
404404
font-size: 1.9em !important;
405405
}
406406

407+
.swal2-content {
408+
text-align: __MSG_@@bidi_start_edge__ !important
409+
}
410+
407411
.new-features-list {
408412
text-align: __MSG_@@bidi_start_edge__ !important;
409413
}
@@ -434,6 +438,7 @@ body {
434438
max-width: 200px;
435439
word-spacing: 4px;
436440
padding-right: 25px;
441+
padding-bottom: 30px;
437442
}
438443

439444
.prayer-times-icon {
@@ -483,6 +488,15 @@ body {
483488
background-image: url(../assets/isha.svg);
484489
}
485490

491+
.next-prayer {
492+
margin-top: 10px;
493+
font-size: 1.2rem;
494+
background-color: rgba(255, 255, 255, .7);
495+
color: #333;
496+
text-align: center;
497+
border-radius: 10px;
498+
}
499+
486500
@media screen and (min-width: 992px) {
487501
.calendar {
488502
width: 70%;

js/background.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,20 @@ function isFastingDay (day, dayOfWeek, holidays, dayBeforeHolidays, dayAfterHoli
118118
holidays.includes("Ashura") || holidays.includes("Arafa") || dayBeforeHolidays.includes("Ashura") ||
119119
dayAfterHolidays.includes("Ashura");
120120
}
121+
122+
chrome.runtime.onInstalled.addListener(() => {
123+
const manifest = chrome.runtime.getManifest();
124+
chrome.storage.sync.get(['last_update'], (result) => {
125+
if (!result.hasOwnProperty('last_update') || result.last_update.version != manifest.version) {
126+
//send request to server to get message
127+
$.get('https://quran-extension-api.alwaysdata.net/updates/' + manifest.version, (data) => {
128+
let message;
129+
if (data.success) {
130+
message = data.message;
131+
}
132+
133+
chrome.storage.sync.set({last_update: {version: manifest.version, message, shown: message.length === 0}});
134+
});
135+
}
136+
})
137+
})

js/main.js

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2020 by Shahed Nasser. All Rights Reserved.
2+
// Copyright (c) 2021 by Shahed Nasser. All Rights Reserved.
33
//
44

55
$(document).ready(function(){
@@ -9,7 +9,9 @@ $(document).ready(function(){
99
weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
1010
hijriHolidays = [],
1111
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;
1315
const messageRegex = /__MSG_(\w+)__/g,
1416
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September',
1517
'October', 'November', 'December'],
@@ -109,7 +111,7 @@ $(document).ready(function(){
109111
$(".calendar-container").removeClass("show");
110112
});
111113

112-
function load(reload, withTopSites, isReport = false){
114+
function load(reload, withTopSites){
113115
audio = null;
114116
$(".reload img").hide();
115117
$(".reload .loader").show();
@@ -118,21 +120,32 @@ $(document).ready(function(){
118120
chrome.storage.local.get(['image', 'verse', 'calendar', 'prayerTimesCalendar'], function(result){
119121
chrome.storage.sync.get(['show_translation', 'translation_language', 'recitation',
120122
'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+
}
122135
if(navigator.onLine){
123136
if(!syncResult.hasOwnProperty('show_translation') || !syncResult.hasOwnProperty('translation_language') ||
124137
!syncResult.show_translation || !syncResult.translation_language || !syncResult.translation_identifier){
125138
$(".translation-container").remove();
126139
}
127140
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){
129142
setBackgroundImage(result.image.src);
130143
}
131144
else {
132145
setNewImage(reload);
133146
}
134147

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){
136149
setVerse(result.verse.data);
137150
audio = new Audio(result.verse.audio);
138151
if(syncResult.hasOwnProperty('show_translation') && syncResult.show_translation &&
@@ -204,12 +217,17 @@ $(document).ready(function(){
204217
}
205218

206219
if (!syncResult.hasOwnProperty('show_prayer_times') || syncResult.show_prayer_times) {
220+
if (syncResult.prayer_times_format) {
221+
prayerTimeFormat = syncResult.prayer_times_format;
222+
}
207223
if (!result.hasOwnProperty('prayerTimesCalendar') || !result.prayerTimesCalendar || !result.prayerTimesCalendar.hasOwnProperty('month') ||
208224
!result.prayerTimesCalendar.hasOwnProperty('calendar') || result.prayerTimesCalendar.month != (new Date()).getMonth()) {
209225
getPrayerTimesCalendar();
210226
} else {
211227
getPrayerTimes();
212228
}
229+
} else {
230+
$(".next-prayer").remove();
213231
}
214232
}
215233
else{
@@ -644,7 +662,7 @@ $(document).ready(function(){
644662
`)
645663

646664
var toastElList = [].slice.call(document.querySelectorAll('.toast:not(.hide)'))
647-
var toastList = toastElList.map(function (toastEl) {
665+
toastElList.map(function (toastEl) {
648666
return new bootstrap.Toast(toastEl, {
649667
autohide: false
650668
}).show()
@@ -669,32 +687,80 @@ $(document).ready(function(){
669687

670688
function getPrayerTimes() {
671689
chrome.storage.local.get(['prayerTimesCalendar'], function(result) {
672-
console.log(result)
673690
if (result.hasOwnProperty('prayerTimesCalendar') && result.prayerTimesCalendar.hasOwnProperty('calendar')) {
674691
//get today's prayer times
675-
const today = new Date();
692+
const today = new Date(),
693+
todayMoment = moment();
676694
const prayerTimesContainer = $(".prayer-times-container"),
677695
prayerTimesWrapper = prayerTimesContainer.find(".prayer-times-wrapper");
678696
prayerTimesContainer.addClass('d-none');
679697
prayerTimesWrapper.empty();
698+
let nextPrayerTime = 0, nextPrayerName = "";
680699
result.prayerTimesCalendar.calendar.some((dateData) => {
681700
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+
682735
//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>`);
688741
prayerTimesContainer.removeClass('d-none');
689742
return true; //break the loop
690743
}
691744
return false;
692745
});
746+
747+
console.log(nextPrayerTime, nextPrayerName);
748+
if (nextPrayerTime) {
749+
$(".next-prayer").text(nextPrayerName + " " + nextPrayerTime);
750+
}
693751
}
694752
})
695753
}
696754

697755
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';
699765
}
700766
});

js/options.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ $(document).ready(function(){
1414
calendarStartDayElement = $("select[name=calendar_start_day]"),
1515
sendFastingNotificationElement = $("input[name=send_fasting_notification]"),
1616
showPrayerTimesElement = $("#show_prayer_times"),
17-
prayerTimesMethodElement = $("#prayer_times_method");
17+
prayerTimesMethodElement = $("#prayer_times_method"),
18+
prayerTimesFormatElement = $("#prayer_times_format"),
19+
shouldRefreshElement = $("#should_refresh");
1820
chrome.storage.sync.get([
1921
"translation_language",
2022
"show_translation",
@@ -25,7 +27,9 @@ $(document).ready(function(){
2527
"calendar_start_day",
2628
"send_fasting_notification",
2729
"show_prayer_times",
28-
"prayer_times_method"], function(result){
30+
"prayer_times_method",
31+
"prayer_times_format",
32+
"should_refresh"], function(result){
2933
if(result.hasOwnProperty('show_translation') && result.show_translation){
3034
showTranslationElement.prop('checked', true);
3135
translationLanguagesElement.prop('disabled', false);
@@ -53,11 +57,18 @@ $(document).ready(function(){
5357
if (!result.hasOwnProperty('show_prayer_times') || result.show_prayer_times) {
5458
showPrayerTimesElement.prop('checked', true);
5559
prayerTimesMethodElement.prop('disabled', false);
60+
prayerTimesFormatElement.prop('disabled', false);
5661
}
5762

5863
if (result.hasOwnProperty('prayer_times_method')) {
5964
prayerTimesMethodElement.val(result.prayer_times_method)
6065
}
66+
67+
if (result.hasOwnProperty('prayer_times_format')) {
68+
prayerTimesFormatElement.val(result.prayer_times_format)
69+
}
70+
71+
shouldRefreshElement.prop('checked', !result.hasOwnProperty('should_refresh') || result.should_refresh);
6172
});
6273

6374
$("#save").click(function(){
@@ -72,15 +83,19 @@ $(document).ready(function(){
7283
calendar_start_day = calendarStartDayElement.val(),
7384
send_fasting_notification = sendFastingNotificationElement.is(":checked"),
7485
show_prayer_times = showPrayerTimesElement.is(":checked"),
75-
prayer_times_method = prayerTimesMethodElement.val();
86+
prayer_times_method = prayerTimesMethodElement.val(),
87+
prayer_times_format = prayerTimesFormatElement.val(),
88+
should_refresh = shouldRefreshElement.is(":checked");
89+
7690
if(translation_identifier === null){
7791
$(".alerts").html('<div class="alert alert-danger">' + chrome.i18n.getMessage('error') + '</div>')
7892
}
7993
chrome.storage.sync.set({translation_language: translation_language, show_translation: show_translation,
8094
recitation: recitation, translation_identifier: translation_identifier,
8195
show_top_sites: show_top_sites, show_athkar: show_athkar, show_date: show_date,
8296
calendar_start_day: calendar_start_day, send_fasting_notification: send_fasting_notification,
83-
show_prayer_times: show_prayer_times, prayer_times_method: prayer_times_method}, function(){
97+
show_prayer_times: show_prayer_times, prayer_times_method: prayer_times_method,
98+
prayer_times_format: prayer_times_format, should_refresh: should_refresh}, function(){
8499
chrome.storage.local.set({image: null, verse: null, prayerTimesCalendar: null}, function(){
85100
$(".alerts").html('<div class="alert alert-success mt-3">' + chrome.i18n.getMessage('saved') + '</div>');
86101

@@ -113,6 +128,7 @@ $(document).ready(function(){
113128

114129
showPrayerTimesElement.change(function () {
115130
prayerTimesMethodElement.prop('disabled', !$(this).is(":checked"));
131+
prayerTimesFormatElement.prop('disabled', !$(this).is(":checked"));
116132
})
117133

118134
function getTranslationLanguageIdentifier(code){

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Quran In New Tab",
3-
"version": "2.1.3",
3+
"version": "2.1.4",
44
"description": "View Quran verses on the new tab page.",
55
"permissions": [
66
"storage",

newtab.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ <h6 class="text-center mb-3">
3232
</div>
3333
<div class="hijri-date">
3434
</div>
35+
<div class="next-prayer"></div>
3536
<div class="holidays">
3637
</div>
3738
</div>

options.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ <h2 class="mb-4">__MSG_general__</h2>
2828
</div>
2929
<small class="text-secondary">__MSG_show_hijri_date_description__</small>
3030
</div>
31+
<div class="form-group mb-4">
32+
<div class="form-check form-switch">
33+
<input type="checkbox" class="form-check-input" id="should_refresh" name="should_refresh">
34+
<label class="form-check-label" for="should_refresh">__MSG_refresh_every_tab__</label>
35+
</div>
36+
</div>
3137
<hr />
3238
<h2 class="mb-4">__MSG_quran__</h2>
3339
<div class="form-group mb-4">
@@ -237,6 +243,13 @@ <h2 class="mb-4">__MSG_prayer_times__</h2>
237243
</div>
238244
<small class="text-secondary">__MSG_show_prayer_times_description__</small>
239245
</div>
246+
<div class="form-group mb-4">
247+
<label class="mb-2">__MSG_prayer_times_format__</label>
248+
<select class="form-control" id="prayer_times_format" name="prayer_times_format" disabled>
249+
<option value="24">24h Format</option>
250+
<option value="12">12h Format</option>
251+
</select>
252+
</div>
240253
<div class="form-group mb-4">
241254
<label class="mb-2">__MSG_prayer_times_method__</label>
242255
<select class="form-control" id="prayer_times_method" name="prayer_times_method" disabled>

0 commit comments

Comments
 (0)