forked from Sulagna-Dutta-Roy/GGExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Sulagna-Dutta-Roy#1304 from Sambit-Mondal/TabReminder
Fixes Sulagna-Dutta-Roy#85 : Tab Reminder
- Loading branch information
Showing
7 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |