PerfectTimeToSleepAndSalatTime

Perfect Time To Sleep And SalatTime

// ==UserScript==
// @name         PerfectTimeToSleepAndSalatTime
// @namespace    http://tampermonkey.net/
// @version      0.8
// @description  Perfect Time To Sleep And SalatTime
// @author       MeGaMoSbah
// @match        https://muslimsalat.com/oran/daily.json
// @include      https://muslimsalat.com/oran/daily.json
// @icon         https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant        none
// ==/UserScript==


var GetTime = function() {
	/*toHoursAndMinutes*/
	function toHoursAndMinutes(totalMinutes) {
		const hours = Math.floor(totalMinutes / 60);
		const minutes = totalMinutes % 60;

		return {
			hours,
			minutes
		};
	}
	var xhttp = new XMLHttpRequest();
	xhttp.onreadystatechange = function() {
		if (this.readyState == 4 && this.status == 200) {
			var response = (xhttp.responseText);
			var Timefajr = (response.substring(response.indexOf('fajr') + 7, response.indexOf('fajr') + 14));
			console.log("fajr's time is " + Timefajr);
			var Timeshurooq = (response.substring(response.indexOf('shurooq') + 10, response.indexOf('shurooq') + 17));
			console.log("shurooq's time is " + Timeshurooq);
			var Timedhuhr = (response.substring(response.indexOf('dhuhr') + 8, response.indexOf('dhuhr') + 15));
			console.log("dhuhr's time is " + Timedhuhr);
			var Timeasr = (response.substring(response.indexOf('asr') + 6, response.indexOf('asr') + 13));
			console.log("asr's time is " + Timeasr);
			var Timemaghrib = (response.substring(response.indexOf('maghrib') + 10, response.indexOf('maghrib') + 17));
			console.log("maghrib's time is " + Timemaghrib);
			var Timeisha = (response.substring(response.indexOf('isha') + 7, response.indexOf('isha') + 14));
			console.log("'ishas time is " + Timeisha);
			/*Night time*/
			var minStart = Timeisha.substring('2', '4');
			//console.log('Night begin at minut : ' + minStart);
			minStart = +minStart;
			var minEnd = Timefajr.substring('2', '4');
			//console.log('Night end at minute : ' + minEnd);
			minEnd = +minEnd;
			var hourStart = Timeisha.substring('0', '1');
			//console.log('Night Start at hour : ' + hourStart);
			hourStart = +hourStart;
			var hourEnd = Timefajr.substring('0', '1');
			//console.log('Night end at hour : ' + hourEnd);
			hourEnd = +hourEnd;
			//var isha= {hourStart, minStart};console.log('isha time is : '+isha);
			//var fajr= {hourEnd, minEnd};console.log(fajr);
			var diffHour = (12 - (hourStart - hourEnd));
			//console.log('all night hour is :' + diffHour);
			var diffMin = ((minStart) - (minEnd));
			//console.log('Night minute to add to hour is :' + diffMin);
			var NightTime = (60 * diffHour) + diffMin;
			console.log('All night time minute is : ' + (NightTime) + ' Minuts');
			var CycleTimeSleep = Math.floor(+NightTime / 6);
			console.log('Cycle sleep Time by minute is :' + CycleTimeSleep);
			/**/
			var firstTime = (Timeisha);
			console.log('first cycle start at ' + firstTime);
			/**/
			var secondTimeM = (minStart + (hourStart * 60) + CycleTimeSleep) - (Math.floor((minStart + (hourStart * 60) + CycleTimeSleep) / 60) * 60);
			//console.log('second time minutes start at :'+secondTimeM);
			var secondTimeH = 1+hourStart + (Math.floor((CycleTimeSleep) / 60));
			if (secondTimeH > 12) {
				secondTimeH = secondTimeH - 12
			} //console.log('second time hours start at :'+ secondTimeH);
			if (secondTimeM < 10) {
				console.log('second cycle start at :' + secondTimeH + ':0' + secondTimeM);
			} else {
				console.log('second cycle start at ' + secondTimeH + ':' + secondTimeM);
			};
			/**/
			var thirdTimeM = (minStart + (hourStart * 60) + CycleTimeSleep * 2) - (Math.floor((minStart + (hourStart * 60) + CycleTimeSleep * 2) / 60) * 60);
			//console.log('second time minutes start at :'+thirdTimeM);
			var thirdTimeH = hourStart + (Math.floor((CycleTimeSleep * 2) / 60));
			if (thirdTimeH > 12) {
				thirdTimeH = thirdTimeH - 12
			} //console.log('second time hours start at :'+ thirdTimeH);
			if (thirdTimeM < 10) {
				console.log('third cycle start at :' + thirdTimeH + ':0' + thirdTimeM);
			} else {
				console.log('third cycle start at ' + thirdTimeH + ':' + thirdTimeM);
			};
			/**/
			var forthTimeM = (minStart + (hourStart * 60) + CycleTimeSleep * 3) - (Math.floor((minStart + (hourStart * 60) + CycleTimeSleep * 3) / 60) * 60);
			//console.log('second time minutes start at :'+forthTimeM);
			var forthTimeH = hourStart + (Math.floor((CycleTimeSleep * 3) / 60));
			if (forthTimeH => 12) {
				forthTimeH = forthTimeH - 12
			} //console.log('second time hours start at :'+ forthTimeH);
			if (forthTimeM < 10) {
				console.log('forth cycle <<midlle of the night>> start at :' + forthTimeH + ':0' + forthTimeM);
			} else {
				console.log('forth cycle <<midlle of the night>> start at ' + forthTimeH + ':' + forthTimeM);
			};
			/**/
			var FifthTimeM = (minStart + (hourStart * 60) + CycleTimeSleep * 4) - (Math.floor((minStart + (hourStart * 60) + CycleTimeSleep * 4) / 60) * 60);
			//console.log('second time minutes start at :'+FifthTimeM);
			var FifthTimeH = -1+hourStart + (Math.floor((CycleTimeSleep * 4) / 60));
			if (FifthTimeH > 12) {
				FifthTimeH = FifthTimeH - 12
			} //console.log('second time hours start at :'+ FifthTimeH);
			if (FifthTimeM < 10) {
				console.log('fifth cycle start at :' + FifthTimeH + ':0' + FifthTimeM);
			} else {
				console.log('fifth cycle start at ' + FifthTimeH + ':' + FifthTimeM);
			};
			/**/
			var SixthTimeM = (minStart + (hourStart * 60) + CycleTimeSleep * 5) - (Math.floor((minStart + (hourStart * 60) + CycleTimeSleep * 5) / 60) * 60);
			//console.log('second time minutes start at :'+SixthTimeM);
			var SixthTimeH = hourStart + (Math.floor((CycleTimeSleep * 5) / 60));
			if (SixthTimeH > 12) {
				SixthTimeH = SixthTimeH - 12
			} //console.log('second time hours start at :'+ SixthTimeH);
			if (SixthTimeM < 10) {
				console.log('sixth cycle start at :' + SixthTimeH + ':0' + SixthTimeM);
			} else {
				console.log('sixth cycle start at ' + SixthTimeH + ':' + SixthTimeM);
			};
			/**/
			var seventhTimeM = (minStart + (hourStart * 60) + CycleTimeSleep * 6) - (Math.floor((minStart + (hourStart * 60) + CycleTimeSleep * 6) / 60) * 60);
			//console.log('second time minutes start at :'+seventhTimeM);
			var seventhTimeH = hourStart + (Math.floor((CycleTimeSleep * 6) / 60));
			if (seventhTimeH > 12) {
				seventhTimeH = seventhTimeH - 12
			} //console.log('second time hours start at :'+ seventhTimeH);
			if (seventhTimeM < 10) {
				console.log('seventh cycle start at :' + seventhTimeH + ':0' + seventhTimeM);
			} else {
				console.log('seventh cycle start at ' + seventhTimeH + ':' + seventhTimeM);
			};
		}
	};
	xhttp.open("GET", "https://muslimsalat.com/oran/daily.json", true);
	xhttp.send();
};
GetTime();


//setInterval(function(){},100);





/*document.getElementById("Utc_Time").style.fontSize */