Skip to content

Commit

Permalink
Merge pull request Sulagna-Dutta-Roy#1304 from Sambit-Mondal/TabReminder
Browse files Browse the repository at this point in the history
Fixes Sulagna-Dutta-Roy#85 : Tab Reminder
  • Loading branch information
Sulagna-Dutta-Roy authored Jun 9, 2024
2 parents 77ac27b + 94dde4f commit 8d2bba3
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 0 deletions.
Binary file added Tab Reminder/game-39-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Tab Reminder/game-39-48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions Tab Reminder/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"manifest_version": 3,
"name": "Tab Reminder",
"version": "1.0",
"description": "Set reminders for your browser tabs.",
"author": "Sambit Mondal",
"permissions": [
"notifications",
"storage",
"alarms",
"tabs"
],
"background": {
"service_worker": "background.js"
},
"action": {
"default_popup": "popup.html",
"default_icon": {
"48": "game-39-48.png",
"128": "game-39-128.png"
}
},
"icons": {
"48": "game-39-48.png",
"128": "game-39-128.png"
}
}
29 changes: 29 additions & 0 deletions Tab Reminder/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>

<head>
<title>Tab Reminder</title>
<link rel="stylesheet" href="src/style.css">
</head>

<body>
<h1>Tab Reminder</h1>
<div>
<label for="time">Remind me in:</label>
<input type="number" id="time" min="1">
<select id="timeUnit">
<option value="minutes">Minutes</option>
<option value="hours">Hours</option>
</select>
</div>
<div>
<label for="message">Reminder message:</label>
<input type="text" id="message">
</div>
<button id="setReminder">Set Reminder</button>
<h2>Active Reminders</h2>
<ul id="reminderList"></ul>
<script src="scripts/popup.js"></script>
</body>

</html>
24 changes: 24 additions & 0 deletions Tab Reminder/scripts/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
chrome.alarms.onAlarm.addListener(alarm => {
chrome.storage.local.get(alarm.name, data => {
const reminder = data[alarm.name];
if (reminder) {
chrome.notifications.create(alarm.name, {
type: 'basic',
iconUrl: 'icons/icon128.png',
title: 'Tab Reminder',
message: reminder.message,
priority: 2
});
}
});
});

chrome.notifications.onClicked.addListener(notificationId => {
chrome.storage.local.get(notificationId, data => {
const reminder = data[notificationId];
if (reminder) {
chrome.tabs.update(reminder.tabId, { active: true });
chrome.notifications.clear(notificationId);
}
});
});
57 changes: 57 additions & 0 deletions Tab Reminder/scripts/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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;
const message = document.getElementById('message').value || 'Reminder!';

if (isNaN(time) || time < 1) {
alert('Please enter a valid time.');
return;
}

const minutes = getTimeInMinutes(time, timeUnit);

chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
const tab = tabs[0];
const alarmName = `reminder-${tab.id}-${Date.now()}`;
const reminder = {
tabId: tab.id,
title: tab.title,
message,
time: Date.now() + minutes * 60000
};

chrome.storage.local.set({ [alarmName]: reminder }, () => {
chrome.alarms.create(alarmName, { delayInMinutes: minutes });
alert(`Reminder set for ${tab.title} in ${time} ${timeUnit}.`);
updateReminders();
});
});
});

function updateReminders() {
chrome.storage.local.get(null, data => {
const reminderList = document.getElementById('reminderList');
reminderList.innerHTML = '';
for (let key in data) {
if (key.startsWith('reminder-')) {
const reminder = data[key];
const listItem = document.createElement('li');
listItem.textContent = `${reminder.title}: ${reminder.message}`;
const cancelButton = document.createElement('button');
cancelButton.textContent = 'Cancel';
cancelButton.addEventListener('click', () => {
chrome.alarms.clear(key);
chrome.storage.local.remove(key, updateReminders);
});
listItem.appendChild(cancelButton);
reminderList.appendChild(listItem);
}
}
});
}

updateReminders();
24 changes: 24 additions & 0 deletions Tab Reminder/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
body {
font-family: Arial, sans-serif;
padding: 10px;
width: 300px;
}

h1 {
font-size: 20px;
}

label {
display: block;
margin-top: 10px;
}

input {
width: 50px;
margin-top: 5px;
}

button {
margin-top: 10px;
padding: 5px 10px;
}

0 comments on commit 8d2bba3

Please sign in to comment.