Skip to content

Commit

Permalink
Reminder_worked
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaprasath2004 committed Jun 22, 2024
1 parent 37eda4a commit 87d76af
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions Tab Reminder/scripts/popup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let Reminds=[]
function getTimeInMinutes(time, unit) {
return unit === 'hours' ? time * 60 : time;
}

document.getElementById('setReminder').addEventListener('click', () => {
const time = parseInt(document.getElementById('time').value);
const timeUnit = document.getElementById('timeUnit').value;
Expand All @@ -13,7 +13,7 @@ document.getElementById('setReminder').addEventListener('click', () => {
}

const minutes = getTimeInMinutes(time, timeUnit);

try{
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
const tab = tabs[0];
const alarmName = `reminder-${tab.id}-${Date.now()}`;
Expand All @@ -30,9 +30,26 @@ document.getElementById('setReminder').addEventListener('click', () => {
updateReminders();
});
});
}catch(err){
let data={id:Reminds.length,time:`${minutes}${timeUnit}`,message:message,now:Date.now(),remindTime:Date.now()+minutes*6000}
Reminds.push(data)
updateReminders()
setTimeout(()=>{
Reminds.map(item=>{
if(item.remindTime<Date.now()){
let li=document.getElementById(`reminder${item.remindTime}`)
const reminderList = document.getElementById('reminderList');
reminderList.removeChild(li)
alert(`Reminder set for ${item.message} in ${item.time}.`);
}
})
Reminds=data
},minutes*60000)
}
});

function updateReminders() {
try{
chrome.storage.local.get(null, data => {
const reminderList = document.getElementById('reminderList');
reminderList.innerHTML = '';
Expand All @@ -53,5 +70,17 @@ function updateReminders() {
}
});
}
catch(err){
if(Reminds.length>0){
const reminderList = document.getElementById('reminderList');
Reminds.map(item=>{
let li=document.createElement('li')
li.textContent=`Time:${item.time} Mess:${item.message}`
li.setAttribute('id',`reminder${item.remindTime}`)
reminderList.appendChild(li)
})
}
}
}

updateReminders();

0 comments on commit 87d76af

Please sign in to comment.