Skip to content

Commit 08ffbde

Browse files
committed
[v1.0.6] Contest Notification Updated
1 parent 44fd83f commit 08ffbde

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

chrome/background.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ function showNotification(title, message) {
4949
message: message || "No Contest Available"
5050
};
5151

52-
chrome.notifications.create("", options);
52+
// chrome.notifications.create("", options);
53+
// Generate a unique notification ID
54+
const notificationId = `cracktech_notification_${Date.now()}`;
55+
chrome.notifications.create(notificationId, options);
5356
}
5457

5558
// Helper function to convert epoch to date string
@@ -144,3 +147,22 @@ chrome.alarms.onAlarm.addListener(function (alarm) {
144147
function scheduleSecondNotification() {
145148
chrome.alarms.create("secondNotificationAlarm", { delayInMinutes: 18 });
146149
}
150+
151+
// Function to show the popup with notification ID
152+
function showPopup(notificationId) {
153+
const popupUrl = chrome.runtime.getURL(`content.html?id=${notificationId}`);
154+
chrome.windows.create({ url: popupUrl, type: "popup", width: 400, height: 200 });
155+
}
156+
157+
// Event listener for notification click
158+
chrome.notifications.onClicked.addListener(function (notificationId) {
159+
// Perform actions based on the clicked notification
160+
if (notificationId.startsWith("cracktech_notification_")) {
161+
// Extract the associated notification ID
162+
const notificationIdNumber = Number(notificationId.split("_")[2]);
163+
164+
// Perform actions based on the notification ID
165+
// For example, show a popup with the notification details
166+
showPopup(notificationIdNumber);
167+
}
168+
});

chrome/content.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Popup Window</title>
5+
<style>
6+
body {
7+
font-family: Arial, sans-serif;
8+
padding: 20px;
9+
}
10+
11+
h1 {
12+
font-size: 20px;
13+
margin-bottom: 10px;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<h1>Notification Popup</h1>
19+
<p id="notificationId"></p>
20+
<script type="text/javascript" src="script/content_script.js"></script>
21+
</body>
22+
</html>

chrome/script/content_script.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Get the notification ID from the query string parameters
2+
const urlParams = new URLSearchParams(window.location.search);
3+
const notificationId = urlParams.get("id");
4+
5+
// Display the notification ID in the popup
6+
const notificationIdElement = document.getElementById("notificationId");
7+
notificationIdElement.textContent = `Clicked notification ID: ${notificationId}`;

0 commit comments

Comments
 (0)