$(document).ready(function(){
//js
//js
//jika dibuka dari hp, logo hilang
if(parseInt($('body').width()) < 750)
{
$(".logo").hide();
}
else
{
$(".logo").show();
}
//fungsi buka dari hp
function bukaDariHp(){
//jika dibuka dari HP kecil, menu samping kiri menutup
var lebar = $('body').width();
if(parseInt(lebar) < 750)
{
$("body").addClass('sidebar-collapse');
$("body").removeClass('sidebar-open');
}
}
//tombol buka sidebar
$(document).on('click','.btn-bukasidebar',function(){
$(".btn-bukasidebar").hide();
$(".warning-notif").hide();
$(".btn-tutupsidebar").show();
if(parseInt($('body').width()) < 750)
{
$(".btn-logourg").hide();
$(".btn-logowhite").show();
$('.btn-logowhite').removeClass('logo-putih-sembunyi');
$('.btn-logowhite').addClass('logo-putih-tampil');
}
else
{
$(".btn-logourg").hide();
}
});
//tombol tutup sidebar
$(document).on('click','.btn-tutupsidebar',function(){
$(".btn-bukasidebar").show();
$(".warning-notif").show();
$(".btn-tutupsidebar").hide();
if(parseInt($('body').width()) < 750)
{
setTimeout(function(){
$(".btn-logowhite").hide();
$(".btn-logourg").show();
},375);
$('.btn-logowhite').removeClass('logo-putih-tampil');
$('.btn-logowhite').addClass('logo-putih-sembunyi');
}
else
{
$(".btn-logourg").show();
}
});
//tombol logo jika klik geser ke atas
$(document).on('click','.btn-logourg',function(){
$("html, body").animate({scrollTop: 0}, 500);
$('#periksaonline').removeClass('jarak-padding');
$('#perbaikiapa').removeClass('jarak-padding');
});
//jika klik kerjasama geser ke paling bawah
$(document).on('click','.kerjasama',function(){
$("html, body").animate({scrollTop: $(document).height()}, 1000);
$('#periksaonline').removeClass('jarak-padding');
$('#perbaikiapa').removeClass('jarak-padding');
});
//tombol btn-periksaonline
$(document).on('click','.btn-periksaonline',function(){
$('#perbaikiapa').removeClass('jarak-padding');
$('#periksaonline').addClass('jarak-padding');
});
//tombol btn-perbaikiapa
$(document).on('click','.btn-perbaikiapa',function(){
$('#periksaonline').removeClass('jarak-padding');
$('#perbaikiapa').addClass('jarak-padding');
});
//menu atur toko
$(document).on('click','.ubah-profil',function(){
$(".row").hide();
$("#ubah-profil").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-2").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Ubah Profil');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
});
//buka menu sidebar nutup sidebar kiri
$(document).on('click','.menu-sidebar',function(){
$(".btn-tutupsidebar").hide();
$(".warning-notif").show();
if(parseInt($('body').width()) < 750)
{
setTimeout(function(){
$(".btn-logowhite").hide();
},375);
$('.btn-logowhite').removeClass('logo-putih-tampil');
$('.btn-logowhite').addClass('logo-putih-sembunyi');
}
});
//menu riwayat saldo
$(document).on('click','.saldo',function(){
$(".row").hide();
$("#saldo").show();
$(".sidebar-menu li").removeClass('active');
//$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Riwayat Saldo');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//riwayat saldo & penghasilan (reseller)
setTimeout( function() { listPenghasilanReseller("","");}, 2000);
setTimeout( function() { penghasilanHariIniReseller();}, 4000);
setTimeout( function() { penghasilanBulanIniReseller();}, 6000);
});
//menu riwayat saldo
$(document).on('click','.saldo-bonus',function(){
$(".row").hide();
$("#saldo").show();
$(".sidebar-menu li").removeClass('active');
//$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Riwayat Saldo');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//riwayat saldo & penghasilan (reseller)
setTimeout( function() { listPenghasilanReseller("","");}, 500);
setTimeout( function() { penghasilanHariIniReseller();}, 1000);
setTimeout( function() { penghasilanBulanIniReseller();}, 1500);
});
//menu bonus
$(document).on('click','.bonus',function(){
$(".row").hide();
$("#bonus").show();
$(".sidebar-menu li").removeClass('active');
//$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Ambil Bonus');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//riwayat saldo & penghasilan (reseller)
setTimeout( function() { listPenghasilanReseller("","");}, 500);
setTimeout( function() { penghasilanHariIniReseller();}, 1000);
setTimeout( function() { penghasilanBulanIniReseller();}, 1500);
});
//menu riwayat poin
$(document).on('click','.poin',function(){
$(".row").hide();
$("#poin").show();
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('urgentPoint');
$('.btn-logourg').hide();
$('.btn-backhome').hide();$('.btn-backpesanan').show(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
});
//menu ubah password
$(document).on('click','.ubah-password',function(){
$(".row").hide();
$("#ubah-password").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Ubah Password');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
});
//menu pesanan
$(document).on('click','.pesanan',function(){
$(".row").hide();
$("#pesanan").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-1").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Pesananku');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//membuka tab proses
$('#li-proses').addClass('active');
$('#li-selesai').removeClass('active');
$('#li-proses a').attr('aria-expanded','true');
$('#li-selesai a').attr('aria-expanded','false');
$('#tab-pesanan-proses').addClass('active');
$('#tab-pesanan-selesai').removeClass('active');
});
//menu chat list
$(document).on('click','.chat-list',function(){
$(".row").hide();
$("#chat-list").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-n1").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Chat Masuk');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
setTimeout( function() { listChatToko("");}, 1000);
});
//menu beranda
$(document).on('click','.beranda',function(){
beranda();
});
//ketika tombol back
window.addEventListener('popstate',beranda);
//ketika semua tombol diklik agar saat back kembali ke beranda
$(document).on('click','.btn',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.sidebar-menu li',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.post',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.post-pesanan',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.post-chat',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.tulis',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.btn-toko-terpilih',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','input[name="cari_nota"]',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
function beranda() {
$(".row").hide();
$("#beranda").show();
$('#modal-detail-order').modal('hide');
$('#modal-tim').modal('hide');
$('#modal-buat-antrian').modal('hide');
$('#modal-toko').modal('hide');
$('#modal-detail-laporan').modal('hide');
$('#modal-tulis-daftar-harga').modal('hide');
$('#modal-detail-pesanan').modal('hide');
$(".sidebar-menu li").removeClass('active');
$("#sidebar-7").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
//$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('');
$('.btn-logourg').show();
$('.btn-backhome').hide();$('.btn-backpesanan').hide();
$('.btn-opensidebar').show();
$('.notif-kanan').hide();
bukaDariHp();
//tambahan jika cari_nota
$('.btn-toko-terpilih').show();
$('.div-menu-atas').show();
$('.nav-tab-beranda').show();
$('.filter-cari-nota').show();
$('.div-bawah-beranda').show();
var tab_terbuka = $('#beranda').attr('data-tabterbuka');
if(typeof(tab_terbuka) != 'undefined' && tab_terbuka != null)
{
$('#tab'+tab_terbuka+'').show();
}
}
//cegah input ' dan "
$(document).on('keyup','input[type="text"]',function(){
var nb = $(this).val();
nb = nb.replace(/'/g,'');
nb = nb.replace(/"/g,'');
nb = nb.replace(/&/g,'');
nb = nb.replace('(','');
nb = nb.replace(')','');
nb = nb.replace('[','');
nb = nb.replace(']','');
nb = nb.replace('{','');
nb = nb.replace('}','');
$(this).val(nb);
});
$(document).on('keyup','textarea',function(){
var nb = $(this).val();
nb = nb.replace(/'/g,'');
nb = nb.replace(/"/g,'');
nb = nb.replace(/&/g,'');
nb = nb.replace('(','');
nb = nb.replace(')','');
nb = nb.replace('[','');
nb = nb.replace(']','');
nb = nb.replace('{','');
nb = nb.replace('}','');
$(this).val(nb);
});
//replaceAll tidak support browser versi lama 2021, buat fungsi baru
function gantiSemua(variabel, awal, ganti) {
if(typeof variabel != 'string' && variabel != null && variabel != 'null' && variabel != '')
{
var variabel_baru = variabel.toString();
}
else
{
var variabel_baru = variabel;
}
if(awal != '' && awal != 'null' && awal != null && variabel != null && variabel != 'null' && variabel != '')
{
var pecah_vb = variabel_baru.split(awal);
if(pecah_vb.length <= 2)
{
var variabel_baru = variabel_baru.replace(awal,ganti);
}
else
{
var susun_var_baru = '';
for(pvb = 0; pvb < pecah_vb.length; pvb++)
{
if(pvb == 0)
{
susun_var_baru = susun_var_baru+''+pecah_vb[pvb];
}
else
{
susun_var_baru = susun_var_baru+''+ganti+''+pecah_vb[pvb];
}
//variabel_baru = variabel_baru.replace(awal,ganti);
}
variabel_baru = susun_var_baru;
}
}
return variabel_baru;
}
$('.loadingtop').hide();
//tekan link akan muncul loading
$("a").click(function(){
$('.loadingtop').show();
setTimeout( function() { $('.loadingtop').hide(); }, 4000);
});
//mengubah 1000000 jadi 1.000.000
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + '.' + '$2');
}
return x1 + x2;
}
function formatRupiah(angka, prefix){
if(angka != null && angka != "" && prefix != null && angka != "")
{
var number_string = angka.replace(/[^,\d]/g, '').toString(),
split = number_string.split(','),
sisa = split[0].length % 3,
rupiah = split[0].substr(0, sisa),
ribuan = split[0].substr(sisa).match(/\d{3}/gi);
// tambahkan titik jika yang di input sudah menjadi angka ribuan
if(ribuan){
separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.');
}
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
return prefix == undefined ? rupiah : (rupiah ? 'Rp ' + rupiah : '');
}
}
//format tgl indonesia, input Y-m-d H:i:s, output d/m/Y H:i
function tglindo(tgl)
{
if(tgl != null && tgl != "" && tgl != "null" && tgl.length >= 19)
{
//console.log('tglindo : '+tgl);
if(tgl.indexOf(":") > -1)
{
//pecah tgl
var pecah = tgl.split(" ");
var pecah_tgl = pecah[0].split("-");
var tanggal = pecah_tgl[2]+'/'+pecah_tgl[1]+'/'+pecah_tgl[0];
var pecah_jam = pecah[1].split(":");
var jam = pecah_jam[0]+':'+pecah_jam[1];
var tampil_tgl = tanggal+' '+jam;
return tampil_tgl;
}
else
{
return '00';
}
}
else
{
var tampil_tgl = '-';
return tampil_tgl;
}
}
//mengitung tinggal berapa hari dari sekarang
function sisahari(tgl)
{
if(tgl != null && tgl != "" && tgl != "null")
{
//isi tanggal
var MyDate = new Date(tgl);
//isi tanggal sekarang
var DateNow = new Date();
var MyDateString;
//hitung sisa hari
//var sisa_hari = MyDate.getDate() - DateNow.getDate(); //penambahan jam (dalam jam)
var timeDiff = (MyDate - DateNow)/1000; //penambahan jam (dalam jam)
var sisa_hari = Math.round(timeDiff/(86400));
var tampil_tgl;
if(sisa_hari == 0) { tampil_tgl = 'HARI INI'; }
else if(sisa_hari == 1) { tampil_tgl = 'BESOK'; }
else if(sisa_hari < 0)
{
sisa_hari_p = sisa_hari * -1;
tampil_tgl = 'TELAT '+sisa_hari_p+' HARI';
}
else if(sisa_hari > 1) { tampil_tgl = ''+sisa_hari+' HARI LAGI'; }
tampil_tgl = ''+tampil_tgl+'';
return tampil_tgl;
}
else
{
var tampil_tgl = '-';
return tampil_tgl;
}
}
//mengitung tanggal hangus
function tglhangus(tgl,hari)
{
var someDate = new Date(tgl);
someDate.setDate(someDate.getDate() + hari);
var dd = someDate.getDate();
var mm = someDate.getMonth() + 1;
var y = someDate.getFullYear();
var someFormattedDate = dd + '/'+ mm + '/'+ y;
return someFormattedDate;
}
//supaya ngetik uang delay biar gak error
function delay(callback, ms) {
var timer = 0;
return function() {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(context, args);
}, ms || 0);
};
}
// Format rupiah dengan delay 2s
$('.rupiah').keyup(delay(function (e) {
$(this).val(formatRupiah(this.value, 'Rp '));
}, 2000));
//1. tgl now
function tglLokal() {
const d = new Date();
//bulan
var bulan = d.getMonth() + 1;
if(bulan < 10) { bulan = '0'+bulan; }
//tahun
var tahun = d.getFullYear();
//tgl
var tgl = d.getDate();
if(tgl < 10) { tgl = '0'+tgl; }
//jam
var jam = d.getHours();
if(jam < 10) { jam = '0'+jam; }
//menit
var menit = d.getMinutes();
if(menit < 10) { menit = '0'+menit; }
//detik
var detik = d.getSeconds();
if(detik < 10) { detik = '0'+detik; }
var tgl_now = tahun+'-'+bulan+'-'+tgl+' '+jam+':'+menit+':'+detik;
return tgl_now;
}
setTimeout( function() { hitungMundur();}, 3000);
//isi div jam-hari-ini
function hitungMundur()
{
//isi div jam-hari-ini
const d = new Date();
var sisa_waktu = tampilSisaWaktu(d);
$('.sisa-waktu').html(sisa_waktu);
//cek otomatis ulangi target
var tgl_terakhir_target_tercapai = $('input[name="tgl_terakhir_target_tercapai"]').val();
//2024-05-01
var tgl_sekarang = tglLokal().slice(0, 10);
$('input[name="tgl_sekarang"]').val(tgl_sekarang);
if(tgl_terakhir_target_tercapai != '' && tgl_terakhir_target_tercapai != null && tgl_terakhir_target_tercapai != 'null')
{
var otomatis_ulangi_target = $('input[name="otomatis_ulangi_target"]').prop('checked');
if(tgl_sekarang != tgl_terakhir_target_tercapai && otomatis_ulangi_target == true)
{
ulangiSemuaTarget();
}
}
setTimeout( function() { hitungMundur();}, 1000);
}
function tampilSisaWaktu(tgl)
{
//isi div jam-hari-ini
const d = new Date(tgl);
//jam
var jam = parseInt(d.getHours());
var jam_berikutnya = jam;
var selisih_menit = 0;
var selisih_detik = 0;
var batas_menit = 0;
//detik
var detik = parseInt(d.getSeconds());
//menit
var menit = parseInt(d.getMinutes());
if(menit < 25)
{
batas_menit = 25;
$('.div-waktu-kerja').show();
$('.div-waktu-istirahat').hide();
//$('.navbar-static-top').css('background','#5599FF');
$('#beranda').css('background','linear-gradient(#5599FF 200px, #ffffff 0%)');
}
else if(menit >= 25 && menit < 30)
{
batas_menit = 30;
$('.div-waktu-kerja').hide();
$('.div-waktu-istirahat').show();
//$('.navbar-static-top').css('background','#26a77a');
$('#beranda').css('background','linear-gradient(#26a77a 200px, #ffffff 0%)');
}
else if(menit >= 30 && menit < 55)
{
batas_menit = 55;
$('.div-waktu-kerja').show();
$('.div-waktu-istirahat').hide();
//$('.navbar-static-top').css('background','#5599FF');
$('#beranda').css('background','linear-gradient(#5599FF 200px, #ffffff 0%)');
}
else if(menit >= 55 && menit < 60)
{
batas_menit = 60;
$('.div-waktu-kerja').hide();
$('.div-waktu-istirahat').show();
jam_berikutnya = jam+1;
if(jam_berikutnya >= 24) { jam_berikutnya = 0; }
//$('.navbar-static-top').css('background','#26a77a');
$('#beranda').css('background','linear-gradient(#26a77a 200px, #ffffff 0%)');
}
if(detik > 0)
{
selisih_detik = 60 - detik;
menit = menit + 1;
}
selisih_menit = batas_menit - menit;
if(batas_menit == 60) { batas_menit = '00'; }
var judul_sisa_waktu = ''+selisih_menit+' menit lagi jam '+jam_berikutnya+'.'+batas_menit;
if( $('input[name="audio_aktif"]').prop('checked') == true && parseInt($('.list-amal').attr('data-jumlahamal')) > 0 && parseInt($('.jumlah-target-tercentang').html()) < parseInt($('.list-amal').attr('data-jumlahamal')) )
{
//menit 0 dan 30
if((menit == 0 && detik == 0) || (menit == 30 && detik == 0))
{
//sound
audioLanjutKerja.play();
setTimeout( function()
{
var baca_menit = menit;
if(baca_menit < 10) { baca_menit = '0'+baca_menit; }
var kalimat = 'Istirahat selesai. Sekarang jam '+jam+' '+baca_menit+'. Yuk lanjut mengejar target lagi';
suara(kalimat);
}, 3000);
}
//menit 25 dan 55
if((menit == 25 && detik == 0) || (menit == 55 && detik == 0))
{
//sound
audioIstirahat.play();
setTimeout( function()
{
var kalimat = 'Waktunya istirahat 5 menit. Pilih kegiatan istirahat berikut';
suara(kalimat);
}, 3000);
}
//10 menit lagi
else if(selisih_menit == 10 && selisih_detik == 0)
{
//sound
audioPengumuman1.play();
setTimeout( function()
{
var kalimat = '10 menit lagi waktu habis';
suara(kalimat);
}, 3000);
}
//3 menit lagi
else if(selisih_menit == 3 && selisih_detik == 0)
{
//sound
audioPengumuman1.play();
setTimeout( function()
{
var kalimat = '3 menit lagi waktu habis';
suara(kalimat);
}, 3000);
}
//1 menit lagi
else if(selisih_menit == 1 && selisih_detik == 0)
{
//sound
audioElement.play();
setTimeout( function()
{
var kalimat = '1 menit lagi waktu habis';
suara(kalimat);
}, 3000);
}
//15 detik lagi : alarm
else if(selisih_menit == 0 && selisih_detik == 15)
{
//sound
audioWaktuHabis.play();
}
//10 detik lagi hitung mundur
else if(selisih_menit == 0 && selisih_detik <= 10 && selisih_detik > 0)
{
var kalimat = selisih_detik;
suara(kalimat);
}
}
if(jam < 10) { tampil_jam = '0'+jam; }
if(selisih_menit < 10) { selisih_menit = '0'+selisih_menit; }
if(selisih_detik < 10) { selisih_detik = '0'+selisih_detik; }
var sisa_waktu = '
'+selisih_menit+' : '+selisih_detik+'
menuju jam '+jam_berikutnya+'.'+batas_menit;
if(parseInt($('.list-amal').attr('data-jumlahamal')) > 0)
{
$(document).attr('title', judul_sisa_waktu);
}
return sisa_waktu;
}
setTimeout( function() { tampilHariTglSekarang();}, 1000);
//isi div jam-hari-ini
function tampilHariTglSekarang()
{
//isi div jam-hari-ini
const d = new Date();
var tgl_now = tampilHariTgl(d);
$('.hari-ini').html(tgl_now);
}
function tampilHariTgl(tgl)
{
//isi div jam-hari-ini
const d = new Date(tgl);
//bulan
var bulan = tglBulan(d);
//tahun
var tahun = d.getFullYear();
//tgl
var tgl = d.getDate();
if(tgl < 10) { tgl = '0'+tgl; }
//hari
var hari = tglHari(d);
var tgl_now = hari+', '+parseInt(tgl)+' '+bulan+' '+tahun;
return tgl_now;
}
function tglHari(tgl)
{
const d = new Date(tgl);
let nomor_hari = d.getDay();
var nama_hari = '';
switch(nomor_hari)
{
case 0:
nama_hari = 'Minggu';
break;
case 1:
nama_hari = 'Senin';
break;
case 2:
nama_hari = 'Selasa';
break;
case 3:
nama_hari = 'Rabu';
break;
case 4:
nama_hari = 'Kamis';
break;
case 5:
nama_hari = 'Jumat';
break;
case 6:
nama_hari = 'Sabtu';
break;
}
return nama_hari;
}
function tglBulan(tgl)
{
//isi div jam-hari-ini
const d = new Date(tgl);
//bulan
var nomor_bulan = d.getMonth() + 1;
var nama_bulan = '';
switch(nomor_bulan)
{
case 1:
nama_bulan = 'Januari';
break;
case 2:
nama_bulan = 'Februari';
break;
case 3:
nama_bulan = 'Maret';
break;
case 4:
nama_bulan = 'April';
break;
case 5:
nama_bulan = 'Mei';
break;
case 6:
nama_bulan = 'Juni';
break;
case 7:
nama_bulan = 'Juli';
break;
case 8:
nama_bulan = 'Agustus';
break;
case 9:
nama_bulan = 'September';
break;
case 10:
nama_bulan = 'Oktober';
break;
case 11:
nama_bulan = 'November';
break;
case 12:
nama_bulan = 'Desember';
break;
}
return nama_bulan;
}
// Applied globally on all textareas with the "autoExpand" class
$(document)
.one('focus.autoExpand', 'textarea.autoExpand', function(){
var savedValue = this.value;
this.value = '';
this.baseScrollHeight = this.scrollHeight;
this.value = savedValue;
})
.on('input.autoExpand', 'textarea.autoExpand', function(){
var minRows = this.getAttribute('data-min-rows')|0, rows;
this.rows = minRows;
rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 16);
this.rows = minRows + rows;
});
setTimeout( function()
{
$('#beranda').show();
$('.bagian-footer').show();
}, 1000);
//buat antrian baru
$(".btn-buat-amal").click(function(){
buatAmal();
});
function buatAmal(){
$('#modal-buat-amal').modal('show');
$('#modal-buat-amal').css('overflow', 'auto');
$('.pilih-amal button').removeClass('active');
$('input[name="sekalian_pilih"]').val('');
$('textarea[name="amal_baru"]').val('');
$('textarea[name="amal_baru"]').attr('rows','1');
// semua dikembalikan kondisi awal dahulu
$('.btn-edit-target').show();
$('.span-edit-target').hide();
$('textarea[name="amal_baru"]').prop('autofocus', false);
setTimeout( function()
{
$('textarea[name="amal_baru"]').focus();
}, 1000);
}
$(document).on('click','.pilih-istirahat button',function(){
var pilih = $(this).html();
var pilih_istirahat = $('input[name="pilih_istirahat"]').val();
if(pilih_istirahat.indexOf(pilih) > -1)
{
//sebelumnya ada, maka dihapus dan dinonaktifkan
$(this).removeClass('active');
pilih_istirahat = gantiSemua(pilih_istirahat,pilih+', ', '');
$('input[name="pilih_istirahat"]').val(pilih_istirahat);
}
else
{
$(this).addClass('active');
$('input[name="pilih_istirahat"]').val(pilih_istirahat+''+pilih+', ');
}
// semua dikembalikan kondisi awal dahulu
$('.btn-edit-target').show();
$('.span-edit-target').hide();
});
//btn-ulangi-semua-target
$(document).on('click','.btn-ulangi-semua-target',function(){
ulangiSemuaTarget();
$('html, body').animate({scrollTop: 0}, 1000);
});
function ulangiSemuaTarget(){
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
list_amal = localStorage.getItem('list_amal');
list_amal = gantiSemua(list_amal,'|:|1|:|','|:|0|:|');
//simpan di lokal
localStorage.setItem('list_amal', list_amal);
setTimeout( function()
{
listAmalDataLocal();
}, 100);
}
}
}
//btn-hapus-semua-target
$(document).on('click','.btn-hapus-semua-target',function(){
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
//hapus
localStorage.removeItem('list_amal');
$('html, body').animate({scrollTop: 0}, 1000);
setTimeout( function()
{
listAmalDataLocal();
}, 100);
}
}
});
$(document).on('click','.pilih-amal button',function(){
var pilih = $(this).html();
var sekalian_pilih = $('input[name="sekalian_pilih"]').val();
if(sekalian_pilih.indexOf(pilih) > -1)
{
//sebelumnya ada, maka dihapus dan dinonaktifkan
$(this).removeClass('active');
sekalian_pilih = gantiSemua(sekalian_pilih,pilih+', ', '');
$('input[name="sekalian_pilih"]').val(sekalian_pilih);
}
else
{
$(this).addClass('active');
$('input[name="sekalian_pilih"]').val(sekalian_pilih+''+pilih+', ');
}
});
$(document).on('click','.btn-submit-amal',function(){
var _token = $('input[name="_token"]').val();
var amal_baru = $('textarea[name="amal_baru"]').val();
var sekalian_pilih = $('input[name="sekalian_pilih"]').val();
if(amal_baru != null || sekalian_pilih != null)
{
$('#modal-buat-amal').modal('hide');
var list_amal = '';
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
list_amal = localStorage.getItem('list_amal');
}
}
else
{
$('#beranda').hide();
$('.browser-tidak-support').show();
}
if(amal_baru != '' && amal_baru != 'null' && amal_baru != null)
{
//menghilangkan dobel enter
amal_baru = gantiSemua(amal_baru,'\r','\n');
amal_baru = gantiSemua(amal_baru,'\n\n','\n');
amal_baru = gantiSemua(amal_baru,'\n\n','\n');
//pecah sekalian_pilih
var rincian = amal_baru.split('\n');
for(r = 0; r < rincian.length; r++)
{
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null)
{
list_amal = list_amal+''+rincian[r]+'|:|0|:|;,;';
}
}
}
if(sekalian_pilih != '' && sekalian_pilih != 'null' && sekalian_pilih != null)
{
//pecah sekalian_pilih
var rincian = sekalian_pilih.split(', ');
for(r = 0; r < rincian.length; r++)
{
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null)
{
list_amal = list_amal+''+rincian[r]+'|:|0|:|;,;';
}
}
}
//simpan di lokal
localStorage.setItem('list_amal', list_amal);
setTimeout( function()
{
listAmalDataLocal();
}, 100);
}
});
//agar bisa geser list sortable, harus ada delay
setTimeout( function()
{
listAmalDataLocal();
}, 500);
//fungsi pilihan antrian
function listAmalDataLocal()
{
var list = '';
var list_tercentang = '';
var centang = '';
var tampil_target = '';
var tampil_tercentang = '';
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
list_amal = '';
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
list_amal = localStorage.getItem('list_amal');
if(list_amal != '' && list_amal != 'null' && list_amal != null)
{
//pecah list_amal
var rincian = list_amal.split(';,;');
var jumlah_belum_tercentang = 0;
//update data-jumlahamal
$('.list-amal').attr('data-jumlahamal',rincian.length);
if(rincian.length > 1)
{
$('.div-tombol-ulangi-hapus').show();
}
else
{
$('.div-tombol-ulangi-hapus').hide();
}
for(r = 0; r < rincian.length; r++)
{
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null)
{
//format : rincian[r]|:|centang(0/1)|:|tgl_selesai;,;';
var pecah_rincian = rincian[r].split('|:|');
var isi_target = pecah_rincian[0];
var cek_centang = pecah_rincian[1];
var tgl_selesai = pecah_rincian[2];
if(cek_centang == '1')
{
centang = 'checked';
tampil_target = 'display:none;';
tampil_tercentang = '';
if(tgl_selesai != '' && tgl_selesai != 'null' && tgl_selesai != null)
{
//2024-05-01
$('input[name="tgl_terakhir_target_tercapai"]').val(tgl_selesai.slice(0, 10));
}
}
else
{
centang = '';
tampil_target = '';
tampil_tercentang = 'display:none;';
jumlah_belum_tercentang = jumlah_belum_tercentang + 1;
}
list = list+' ';
//drag handle
list = list+' ';
list = list+''+isi_target+'';
//edit dan hapus target
list = list+'';
list = list+'';
//2024-05-01 00:00:00
if(tgl_selesai != '' && tgl_selesai != 'null' && tgl_selesai != null )
{
jam_selesai = tgl_selesai.substr(11, 2)+':'+tgl_selesai.substr(14, 2);
}
else { jam_selesai = ''; }
list_tercentang = list_tercentang+' '+isi_target+'';
//edit dan hapus target
list_tercentang = list_tercentang+'';
list_tercentang = list_tercentang+'Selesai jam '+jam_selesai+'
';
}
}
//tampil
$('.list-amal').html(list);
$('.list-amal-tercentang').html(list_tercentang);
if(jumlah_belum_tercentang > 2)
{
$('.div-cara-urutkan').show();
}
else
{
$('.div-cara-urutkan').hide();
}
}
}
if(list == '')
{
$('.teks-tambah-target').html('Tulis targetmu sekarang...');
$('.teks-tambah-target-judul').html('Tulis Targetmu Sekarang');
//buka pop up buat sistem antrian baru
setTimeout( function()
{
buatAmal();
$('.list-amal').html('');
$('.list-amal-tercentang').html('');
}, 200);
if( $('input[name="audio_aktif"]').prop('checked') == true)
{
setTimeout( function()
{
var kalimat = 'Selamat datang di Targetku.com. Yuk tulis targetmu sekarang lalu klik simpan';
suara(kalimat);
}, 2000);
setTimeout( function() { audioBerhasil2.play(); }, 6000);
}
$('.judul-target-tercapai').hide();
}
else
{
$('.teks-tambah-target').html('Tambah target...');
$('.teks-tambah-target-judul').html('Tambah target');
if(list_amal.indexOf('|:|1|:|') > -1)
{
var pecah_list_amal = list_amal.split('|:|1|:|');
var jumlah_tercapai = pecah_list_amal.length - 1;
$('.judul-target-tercapai').show();
$('.jumlah-target-tercentang').html(jumlah_tercapai);
}
else
{
$('.judul-target-tercapai').hide();
}
}
}
else
{
$('#beranda').hide();
$('.browser-tidak-support').show();
}
}
//jQuery UI sortable for the todo list
$('.list-sortable').sortable({
placeholder: 'sort-highlight',
handle: '.handle',
forcePlaceholderSize: true,
zIndex: 999999,
axis: 'y',
stop: function (event, ui) {
var data = $(this).sortable('serialize');
$('input[name="urutan_amal"]').val(data);
updateUrutanAmal();
}
}).disableSelection();
$('.list-sortable li').draggable();
//update urutan amal setelah drag and drop
function updateUrutanAmal(){
var urutan_amal = $('input[name="urutan_amal"]').val();
if(urutan_amal != null && urutan_amal != 'null' && urutan_amal != '')
{
//pecah list_amal
var rincian = urutan_amal.split('item[]=');
var list_amal = '';
//start dari 1 karena 0 tidak ada
for(r = 1; r < rincian.length; r++)
{
rincian[r] = gantiSemua(rincian[r],'&','');
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null)
{
//ambil data
var isi_target = $('#id'+rincian[r]+'amal').attr('data-amal');
var cek_centang = $('#id'+rincian[r]+'amal').attr('data-centang');
var tgl_selesai = $('#id'+rincian[r]+'amal').attr('data-tglselesai');
list_amal = list_amal+''+isi_target+'|:|'+cek_centang+'|:|'+tgl_selesai+';,;';
}
}
//simpan di lokal
localStorage.setItem('list_amal', list_amal);
setTimeout( function()
{
listAmalDataLocal();
}, 100);
}
}
// btn-paham-urutkan
$(document).on('click','.btn-paham-urutkan',function(){
$('.isi-cara-urutkan').hide();
});
//btn-edit-target
$(document).on('click','.btn-edit-target',function(){
var id_target = $(this).attr('data-id');
// semua dikembalikan kondisi awal dahulu
$('.btn-edit-target').show();
$('.span-edit-target').hide();
//yang diklik editnya ditampilkan
$(this).hide();
$('.span-edit-target-'+id_target+'').show();
});
//ketik edit_target
$(document).on('keyup','input[name="edit_target"]',function(){
var id_edit = $(this).attr('data-id');
var edit_target = $(this).val();
$('input[name="edit_target"][data-id="'+id_edit+'"]').focus();
//ubah tampilan
$('.btn-edit-target[data-id="'+id_edit+'"]').html(edit_target);
$('input[name="edit_target"][data-id="'+id_edit+'"]').val(edit_target);
//memperbarui list_amal
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
list_amal = localStorage.getItem('list_amal');
if(list_amal != '' && list_amal != 'null' && list_amal != null)
{
//pecah list_amal
var rincian = list_amal.split(';,;');
var list_amal_baru = '';
var jumlah_belum_tercentang = 0;
for(r = 0; r < rincian.length; r++)
{
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null)
{
//format : rincian[r]|:|centang(0/1)|:|tgl_selesai;,;';
var pecah_rincian = rincian[r].split('|:|');
var isi_target = pecah_rincian[0];
var cek_centang = pecah_rincian[1];
var tgl_selesai = pecah_rincian[2];
if(r == id_edit)
{
isi_target = edit_target;
}
if(cek_centang != '1')
{
jumlah_belum_tercentang = jumlah_belum_tercentang + 1;
}
list_amal_baru = list_amal_baru+''+isi_target+'|:|'+cek_centang+'|:|'+tgl_selesai+';,;';
}
}
if(jumlah_belum_tercentang > 2)
{
$('.div-cara-urutkan').show();
}
else
{
$('.div-cara-urutkan').hide();
}
//simpan di lokal
localStorage.setItem('list_amal', list_amal_baru);
if(list_amal_baru.indexOf('|:|1|:|') > -1)
{
var pecah_list_amal = list_amal_baru.split('|:|1|:|');
var jumlah_tercapai = pecah_list_amal.length - 1;
$('.judul-target-tercapai').show();
$('.jumlah-target-tercentang').html(jumlah_tercapai);
}
else
{
$('.judul-target-tercapai').hide();
}
}
}
}
});
//btn-hapus-target
$(document).on('click','.btn-hapus-target',function(){
var id_hapus = $(this).attr('data-id');
//menghapus tampilan
$('#item-'+id_hapus+'').remove();
$('#tercentang-'+id_hapus+'').remove();
//memperbarui list_amal
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
list_amal = localStorage.getItem('list_amal');
if(list_amal != '' && list_amal != 'null' && list_amal != null)
{
//pecah list_amal
var rincian = list_amal.split(';,;');
var list_amal_baru = '';
var jumlah_belum_tercentang = 0;
for(r = 0; r < rincian.length; r++)
{
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null && r != id_hapus)
{
//format : rincian[r]|:|centang(0/1)|:|tgl_selesai;,;';
var pecah_rincian = rincian[r].split('|:|');
var isi_target = pecah_rincian[0];
var cek_centang = pecah_rincian[1];
var tgl_selesai = pecah_rincian[2];
if(cek_centang != '1')
{
jumlah_belum_tercentang = jumlah_belum_tercentang + 1;
}
list_amal_baru = list_amal_baru+''+isi_target+'|:|'+cek_centang+'|:|'+tgl_selesai+';,;';
}
}
if(jumlah_belum_tercentang > 2)
{
$('.div-cara-urutkan').show();
}
else
{
$('.div-cara-urutkan').hide();
}
//simpan di lokal
localStorage.setItem('list_amal', list_amal_baru);
if(list_amal_baru.indexOf('|:|1|:|') > -1)
{
var pecah_list_amal = list_amal_baru.split('|:|1|:|');
var jumlah_tercapai = pecah_list_amal.length - 1;
$('.judul-target-tercapai').show();
$('.jumlah-target-tercentang').html(jumlah_tercapai);
}
else
{
$('.judul-target-tercapai').hide();
}
}
}
}
});
//ketika checkbox centang diklik
$(document).on('click','.cbx',function(){
// semua dikembalikan kondisi awal dahulu
$('.btn-edit-target').show();
$('.span-edit-target').hide();
//ambil kondisi tercentang atau tidak
var centang = $(this).attr('data-centang');
var id_centang = $(this).attr('data-id');
var cek_centang = 0;
if(centang == '1')
{
cek_centang_baru = 1;
//2024-05-01
var tgl_sekarang = tglLokal().slice(0, 10);
$('input[name="tgl_terakhir_target_tercapai"]').val(tgl_sekarang);
//sembunyikan
$('#item-'+id_centang+'').hide();
$('#tercentang-'+id_centang+'').show();
$('.kembang-api').show();
setTimeout( function() { $('.kembang-api').hide(); }, 2000);
if( $('input[name="audio_aktif"]').prop('checked') == true)
{
var jumlah_tercentang = parseInt($('.jumlah-target-tercentang').html());
if(jumlah_tercentang == 0 || jumlah_tercentang == 3)
{
//sound
audioBerhasil2.play();
}
else if(jumlah_tercentang == 1 || jumlah_tercentang == 3)
{
//sound
audioBerhasil3.play();
}
else if(jumlah_tercentang == 2 || jumlah_tercentang == 4)
{
//sound
audioBerhasil4.play();
}
else if(jumlah_tercentang > 4)
{
//kelipatan 5
if(jumlah_tercentang % 5 === 0)
{
//sound
audioBerhasil1.play();
}
//kelipatan 2
else if(jumlah_tercentang % 2 === 0)
{
//sound
audioBerhasil2.play();
}
//kelipatan 3
else if(jumlah_tercentang % 3 === 0)
{
//sound
audioBerhasil3.play();
}
else
{
//sound
audioBerhasil4.play();
}
}
setTimeout( function() { audioYesBerhasil.play(); }, 2000);
setTimeout( function()
{
jumlah_tercentang = parseInt($('.jumlah-target-tercentang').html());
var kalimat = jumlah_tercentang+' target tercapai';
suara(kalimat);
}, 3000);
if(jumlah_tercentang >= 3)
{
//kelipatan 3
if(jumlah_tercentang % 3 === 0)
{
//sound
setTimeout( function() { audioTepukTangan1.play(); }, 5000);
}
//kelipatan 2
else if(jumlah_tercentang % 2 === 0)
{
//sound
setTimeout( function() { audioTepukTangan2.play(); }, 5000);
}
else
{
//sound
setTimeout( function() { audioTepukTangan3.play(); }, 5000);
}
}
}
}
else
{
cek_centang_baru = 0;
//tampilkan
$('#item-'+id_centang+'').show();
$('#tercentang-'+id_centang+'').hide();
}
$('#id'+id_centang+'amal').attr('data-centang',cek_centang_baru);
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('list_amal'))
{
list_amal = localStorage.getItem('list_amal');
if(list_amal != '' && list_amal != 'null' && list_amal != null)
{
//pecah list_amal
var rincian = list_amal.split(';,;');
var list_amal_baru = '';
var jumlah_belum_tercentang = 0;
for(r = 0; r < rincian.length; r++)
{
if(rincian[r] != '' && rincian[r] != 'null' && rincian[r] != null)
{
//format : rincian[r]|:|centang(0/1)|:|tgl_selesai;,;';
var pecah_rincian = rincian[r].split('|:|');
var isi_target = pecah_rincian[0];
var cek_centang = pecah_rincian[1];
var tgl_selesai = pecah_rincian[2];
//ubah centang
if(r == id_centang)
{
cek_centang = cek_centang_baru;
//tgl hari ini
tgl_selesai = tglLokal().slice(0, 19);
var jam_selesai = tgl_selesai.substr(11, 2)+':'+tgl_selesai.substr(14, 2);
//ubah jam-selesai
$('.jam-selesai-'+r).html(jam_selesai);
}
if(cek_centang != '1')
{
jumlah_belum_tercentang = jumlah_belum_tercentang + 1;
}
list_amal_baru = list_amal_baru+''+isi_target+'|:|'+cek_centang+'|:|'+tgl_selesai+';,;';
}
}
if(jumlah_belum_tercentang > 2)
{
$('.div-cara-urutkan').show();
}
else
{
$('.div-cara-urutkan').hide();
}
//simpan di lokal
localStorage.setItem('list_amal', list_amal_baru);
if(list_amal_baru.indexOf('|:|1|:|') > -1)
{
var pecah_list_amal = list_amal_baru.split('|:|1|:|');
var jumlah_tercapai = pecah_list_amal.length - 1;
$('.judul-target-tercapai').show();
$('.jumlah-target-tercentang').html(jumlah_tercapai);
}
else
{
$('.judul-target-tercapai').hide();
}
}
}
}
});
setTimeout( function() { cekAudioAktif();}, 1000);
//cek audio aktif
function cekAudioAktif()
{
var audio_aktif = $('input[name="audio_aktif"]').prop('checked');
var cek_audio = 1;
if(audio_aktif == true)
{
cek_audio = 1;
}
else
{
cek_audio = 0;
}
//simpan di lokal
localStorage.setItem('cek_audio', cek_audio);
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('cek_audio'))
{
cek_audio = localStorage.getItem('cek_audio');
if(cek_audio == '' || cek_audio == 'null' || cek_audio == null)
{
$('input[name="audio_aktif"]').prop('checked', true);
localStorage.setItem('cek_audio', 1);
}
else
{
if(cek_audio == 1)
{
$('input[name="audio_aktif"]').prop('checked', true);
}
else
{
$('input[name="audio_aktif"]').prop('checked', false);
}
}
}
else
{
$('input[name="audio_aktif"]').prop('checked', true);
localStorage.setItem('cek_audio', 1);
}
}
else
{
$('#beranda').hide();
$('.browser-tidak-support').show();
}
}
function setAudioAktif()
{
var audio_aktif = $('input[name="audio_aktif"]').prop('checked');
var cek_audio = 1;
if(audio_aktif == true)
{
cek_audio = 1;
}
else
{
cek_audio = 0;
}
//simpan di lokal
localStorage.setItem('cek_audio', cek_audio);
//langsung akses data lokal
if (typeof(Storage) !== 'undefined') //cek jika browser support
{
//cek target sebelumnya
if(localStorage.getItem('cek_audio'))
{
list_amal = localStorage.getItem('cek_audio');
}
}
else
{
$('#beranda').hide();
$('.browser-tidak-support').show();
}
}
//audio notifikasi
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'https://targetku.com/sound/Airport-Bell.mp3');
var audioPengumuman1 = document.createElement('audio');
audioPengumuman1.setAttribute('src', 'https://targetku.com/sound/airport-pengumuman.wav');
var audioWaktuHabis = document.createElement('audio');
audioWaktuHabis.setAttribute('src', 'https://targetku.com/sound/alarm-waktu-habis.wav');
var audioIstirahat = document.createElement('audio');
audioIstirahat.setAttribute('src', 'https://targetku.com/sound/cuitan-burung.wav');
var audioLanjutKerja = document.createElement('audio');
audioLanjutKerja.setAttribute('src', 'https://targetku.com/sound/lanjut-kerja.wav');
var audioYesBerhasil = document.createElement('audio');
audioYesBerhasil.setAttribute('src', 'https://targetku.com/sound/yes-berhasil.wav');
var audioBerhasil1 = document.createElement('audio');
audioBerhasil1.setAttribute('src', 'https://targetku.com/sound/dapat-bonus-2.wav');
var audioBerhasil2 = document.createElement('audio');
audioBerhasil2.setAttribute('src', 'https://targetku.com/sound/dapat-koin.wav');
var audioBerhasil3 = document.createElement('audio');
audioBerhasil3.setAttribute('src', 'https://targetku.com/sound/dapat-poin.wav');
var audioBerhasil4 = document.createElement('audio');
audioBerhasil4.setAttribute('src', 'https://targetku.com/sound/dapat-bonus.wav');
var audioTepukTangan1 = document.createElement('audio');
audioTepukTangan1.setAttribute('src', 'https://targetku.com/sound/tepuk-tangan.wav');
var audioTepukTangan2 = document.createElement('audio');
audioTepukTangan2.setAttribute('src', 'https://targetku.com/sound/tepuk-tangan-2.wav');
var audioTepukTangan3 = document.createElement('audio');
audioTepukTangan3.setAttribute('src', 'https://targetku.com/sound/tepuk-tangan.wav');
//START fungsi suara
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
function suara(kalimat)
{
msg.voice = voices[0]; // Note: some voices don't support altering params
msg.voiceURI = 'native';
msg.volume = 1; // 0 to 1
msg.rate = 1; // 0.1 to 10
msg.pitch = 1; //0 to 2
msg.text = kalimat;
msg.lang = 'id-ID';
msg.onend = function(e) {
console.log('Finished in ' + event.elapsedTime + ' seconds.');
console.log('lang : '+msg.lang);
};
speechSynthesis.speak(msg);
}
//FINISH fungsi suara
});
// PWA : Register service worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw-targetku.js').then(function(registration) {
console.log('Service worker registered for the following scope: ', registration.scope);
}, function(err) {
console.error('Fail to register service worker', err);
});
});
}
function refreshSW()
{
link_page = 'https://targetku.com/getProfilUser';
//cek apakah situs bisa diakses (online) atau tidak dari cek profil
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
//jika sukses
caches.delete('all-cache-v1');
setTimeout( function()
{
//refresh setelah 2 detik
location.reload();
}, 1000);
}
});
}