document.onkeydown = (e) => { if (e.key == 123) {e.preventDefault();} if (e.ctrlKey && e.shiftKey && e.key == 'I') {e.preventDefault();} //if (e.ctrlKey && e.shiftKey && e.key == 'C') {e.preventDefault();} if (e.ctrlKey && e.shiftKey && e.key == 'J') {e.preventDefault();} if (e.ctrlKey && e.key == 'U') {e.preventDefault();} //if (e.ctrlKey && e.key == 'u') {e.preventDefault();} }; function capfirst(str) { return str.toLowerCase().split(' ').map(function(word) { return word.charAt(0).toUpperCase() + word.slice(1); }).join(' '); } function capEachWord(kalimat, lowercase=true, a_spasi='_', b_spasi=' ') { const words = lowercase==false ? kalimat : kalimat.toLowerCase(); const kataArray = words.split(a_spasi); const kataKapitalArray = kataArray.map(ka=>{ if (ka.length === 0) { return '';} return ka.charAt(0).toUpperCase() + ka.slice(1); }); return kataKapitalArray.join(b_spasi); } function truncate(text, maxLength) { if (text.length > maxLength) { return text.substring(0, maxLength) + "..."; } return text } function isDateBetweenRange(dateToCheck, startDate, endDate) { // Convert dates to milliseconds for robust comparison const timeToCheck = dateToCheck.getTime(); const timeStart = startDate.getTime(); const timeEnd = endDate.getTime(); // Check if the date falls within the range (inclusive of start and end dates) return timeToCheck >= timeStart && timeToCheck <= timeEnd; } function numOfDays(tanggalAwal, tanggalAkhir) { // Membuat objek Date dari string tanggal const startDate = new Date(tanggalAwal); const endDate = new Date(tanggalAkhir); // Menghitung selisih waktu dalam milidetik const diffTime = Math.abs(endDate - startDate); // Konversi milidetik ke hari (1 hari = 1000 ms * 60 detik * 60 menit * 24 jam) const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); return diffDays; } function numOfSpesificDays(nomorHari, tanggalAwal, tanggalAkhir) { const startDate = new Date(tanggalAwal); const endDate = new Date(tanggalAkhir); let countD = 0; // Pastikan tanggal awal tidak lebih besar dari tanggal akhir if (startDate > endDate) { return 0; } // Iterasi dari tanggal awal sampai tanggal akhir for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) { if (d.getDay() === nomorHari) { // 5 berarti Jumat countD++; } } return countD; } function getTextWidth(text, font=false) { const canvas = document.createElement('canvas'); const context = canvas.getContext('2d'); context.font = Boolean(font)==true ? font : ('400 ' + (4 * 3.5) + 'px Roboto'); const metrics = context.measureText(text); return metrics.width; } function hitungUsiaRelatif(tanggalLahir, targetDate=false) { const theday = Boolean(targetDate)?new Date(targetDate):new Date(); const birthDate = new Date(tanggalLahir); let years = theday.getFullYear() - birthDate.getFullYear(); let months = theday.getMonth() - birthDate.getMonth(); // Sesuaikan bulan jika bulan hari ini lebih kecil dari bulan lahir if (months < 0 || (months === 0 && theday.getDate() < birthDate.getDate())) { years--; months += 12; // Tambahkan 12 bulan } // Sesuaikan bulan jika hari hari ini lebih kecil dari hari lahir (sudah diatasi di atas, tapi untuk jaga-jaga) if (theday.getDate() < birthDate.getDate()) { months--; } // Pastikan bulan tidak negatif if (months < 0) { months += 12; } return { years: years, months: months }; } delete history.pushState; for (let i = 0; i <= 30; i++) { history.pushState({ page: i }, "/", ""); } // history.pushState({ page: 1 }, "", ""); // history.back(); // window.history.forward();