Skip to content

Commit 9f92f54

Browse files
committed
[v1.0.6][Chrome] Notification Feature Upgraded
1 parent 08ffbde commit 9f92f54

File tree

7 files changed

+347
-102
lines changed

7 files changed

+347
-102
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Find all the change history listed below
22

3+
**[__/__/2023]**
4+
- v1.0.6 [Features](https://github.com/ssavi-ict/LeetCode-Which-Company/issues/81) implementation.
5+
- **Contribute** button changed to `Upcoming Contest` button.
6+
- **Contribute** option modified and showed as a link.
7+
- **Leetcoder.html** page to show contest details as per user's GMT.
8+
- **Upcoming Contest** desktop notification.
9+
- **Enabling** or **Disabling** notification as per user's choice.
10+
- Implementation Status: Chrome (*Done*), Firefox (*Ongoing*)
11+
312
**[03/06/2023]**
413
- Improved User Interface.
514
- Extension name updated to `CrackTech - Find LeetCode Company Tags` from `LeetCode Which Company`

chrome/background.js

Lines changed: 48 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,14 @@
1-
// // Example event listener for when a new tab is opened or when the user visits leetcode.com
2-
// chrome.tabs.onCreated.addListener(checkNotification);
3-
// chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
4-
// if (changeInfo.status === 'complete' && tab.url.includes('leetcode.com')) {
5-
// checkNotification(tab);
6-
// }
7-
// });
8-
9-
// function checkNotification(tab) {
10-
// // Check if the last notification was sent more than 24 hours ago
11-
// chrome.storage.local.get('lastNotificationSent', result => {
12-
// let lastNotificationSent = result.lastNotificationSent;
13-
// lastNotificationSent = false;
14-
// console.log(lastNotificationSent);
15-
16-
// // Check if the last notification exists and if it is older than 24 hours
17-
// // if (!lastNotificationSent || (Date.now() - lastNotificationSent) >= 24 * 60 * 60 * 1000) {
18-
// // if (!lastNotificationSent) {
19-
// // Check if the user is on leetcode.com
20-
// // if (tab.url.includes('leetcode.com')) {
21-
// // Fetch the JSON data and send the notification
22-
// fetch('https://raw.githubusercontent.com/ssavi-ict/LeetCode-Which-Company/main/data/contests.json')
23-
// .then(response => response.json())
24-
// .then(data => {
25-
// const jsonData = JSON.stringify(data);
26-
// chrome.notifications.create('notificationId', {
27-
// type: 'basic',
28-
// title: 'Notification Title',
29-
// message: jsonData,
30-
// iconUrl: 'res/notify_icon.png'
31-
// });
32-
// chrome.storage.local.set({ lastNotificationSent: Date.now() });
33-
// })
34-
// .catch(error => {
35-
// // Handle any errors that occurred during the fetch request
36-
// console.log('Error Occured');
37-
// });
38-
// // }
39-
// // }
40-
// });
41-
// }
42-
431
// Function to show the notification
442
function showNotification(title, message) {
453
const options = {
464
type: "basic",
475
iconUrl: "res/notify_icon.png",
486
title: title,
49-
message: message || "No Contest Available"
7+
message: message || "No Contest Available",
8+
buttons: [
9+
{ title: "Turn Off Notification" },
10+
{ title: "Visit Leetcode" }
11+
]
5012
};
5113

5214
// chrome.notifications.create("", options);
@@ -86,25 +48,29 @@ function fetchNotificationContent() {
8648
// const message = JSON.stringify(data);
8749
// console.log(message);
8850
// showNotification(message);
51+
const title = `CrackTech Contest Notification`;
52+
let contestCount = Object.keys(data).length; // Count the number of key-value pairs
53+
const currentTime = Date.now() / 1000; // Current time in seconds
8954

90-
const contestCount = Object.keys(data).length; // Count the number of key-value pairs
55+
Object.entries(data).forEach(([key, value]) => {
56+
const start_time = value.start_time;
9157

92-
let notificationMessage = '';
93-
let title = `Upcoming Leetcode Contest - ${contestCount}\n`;
94-
95-
Object.entries(data).forEach(([key, value], index) => {
96-
const { title, start_time, contest_duration } = value;
97-
const startTimeString = convertEpochToDateString(start_time);
98-
const durationString = convertDurationToString(contest_duration);
99-
100-
notificationMessage += `${index + 1}. ${title} - ${startTimeString} for ${durationString} hr.\n`;
58+
if (start_time < currentTime) {
59+
contestCount--;
60+
}
10161
});
102-
103-
showNotification(title, notificationMessage);
62+
if (contestCount > 0){
63+
const notificationMessage = `You have ${contestCount} contest(s) coming up soon. Get ready!!`;
64+
showNotification(title, notificationMessage);
65+
}
66+
else{
67+
const notificationMessage = `No Upcoming Contest(s).`;
68+
showNotification(title, notificationMessage);
69+
}
10470
})
10571
.catch(error => {
106-
console.error("Error fetching notification content:", error);
107-
showNotification(); // Show the notification with default values in case of an error
72+
console.log("Error fetching notification content:", error);
73+
// showNotification(); // Show the notification with default values in case of an error
10874
});
10975
}
11076

@@ -123,10 +89,15 @@ chrome.runtime.onInstalled.addListener(function () {
12389

12490
// Function to schedule the first notification
12591
function scheduleFirstNotification() {
126-
if (!firstNotificationScheduled) {
127-
chrome.alarms.create("firstNotificationAlarm", { delayInMinutes: 2 });
128-
firstNotificationScheduled = true;
129-
}
92+
chrome.storage.local.get("switchState", function (result) {
93+
const switchState = result.switchState;
94+
console.log('Hello'); console.log(switchState);
95+
if (switchState) {
96+
// fetchNotificationContent();
97+
chrome.alarms.create("firstNotificationAlarm", { delayInMinutes: 1 }); // Trigger every day
98+
firstNotificationScheduled = true;
99+
}
100+
});
130101
}
131102

132103
// chrome.tabs.onCreated.addListener(function(tab) {
@@ -138,31 +109,31 @@ chrome.alarms.onAlarm.addListener(function (alarm) {
138109
if (alarm.name === "firstNotificationAlarm") {
139110
fetchNotificationContent();
140111
scheduleSecondNotification();
112+
// firstNotificationScheduled = false; // Set the flag to false after the first notification
141113
} else if (alarm.name === "secondNotificationAlarm") {
142114
fetchNotificationContent();
143115
}
144116
});
145117

146118
// Function to schedule the second notification
147119
function scheduleSecondNotification() {
148-
chrome.alarms.create("secondNotificationAlarm", { delayInMinutes: 18 });
120+
chrome.alarms.create("secondNotificationAlarm", { delayInMinutes: 15 });
149121
}
150122

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-
}
123+
// // Event listener for notification click
124+
// chrome.notifications.onClicked.addListener(function (notificationId) {
125+
// if (notificationId.startsWith("cracktech_notification_")) {
126+
// chrome.tabs.create({ url: "https://leetcode.com/contest/" });
127+
// }
128+
// });
156129

157-
// Event listener for notification click
158-
chrome.notifications.onClicked.addListener(function (notificationId) {
159-
// Perform actions based on the clicked notification
130+
// Event listener for notification button clicks
131+
chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
160132
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);
133+
if (buttonIndex === 0) {
134+
chrome.storage.local.set({ switchState: false });
135+
} else if (buttonIndex === 1) {
136+
chrome.tabs.create({ url: "https://leetcode.com/contest/" });
137+
}
167138
}
168-
});
139+
});

chrome/content.html

Lines changed: 0 additions & 22 deletions
This file was deleted.

chrome/leetcoder.html

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>CrackTech - Find LeetCode Company Tags</title>
5+
<style>
6+
body {
7+
font-family: Verdana;
8+
margin: 0;
9+
padding: 20px;
10+
max-width: 1200px;
11+
margin: 0 auto;
12+
}
13+
14+
.header {
15+
display: flex;
16+
align-items: center;
17+
justify-content: space-between;
18+
margin-bottom: 20px;
19+
}
20+
21+
.switch {
22+
display: flex;
23+
align-items: center;
24+
font-size: 16px;
25+
}
26+
27+
.switch-text {
28+
margin-right: 10px;
29+
}
30+
31+
.checkbox {
32+
width: 16px;
33+
height: 16px;
34+
border: 1px solid #ccc;
35+
border-radius: 3px;
36+
display: inline-block;
37+
margin-right: 5px;
38+
position: relative;
39+
cursor: pointer;
40+
transition: all 0.2s;
41+
}
42+
43+
.checkbox::before {
44+
content: '';
45+
position: absolute;
46+
top: 50%;
47+
left: 50%;
48+
transform: translate(-50%, -50%) scale(0);
49+
width: 8px;
50+
height: 8px;
51+
background-color: #2196F3;
52+
border-radius: 2px;
53+
transition: all 0.2s;
54+
}
55+
56+
.checkbox input[type="checkbox"] {
57+
display: none;
58+
}
59+
60+
.checkbox input[type="checkbox"]:checked + .checkbox::before {
61+
transform: translate(-50%, -50%) scale(1);
62+
}
63+
64+
.content-container {
65+
border: 1px dotted purple;
66+
padding: 10px;
67+
border-radius: 5px;
68+
max-width: 1200px;
69+
}
70+
71+
table {
72+
margin-top: 20px;
73+
width:80%;
74+
}
75+
76+
th, td {
77+
text-align: left;
78+
padding: 10px;
79+
font-size: 14px;
80+
border: 1px solid purple;
81+
}
82+
83+
th {
84+
background-color: #f2f2f2;
85+
}
86+
87+
.gmt-offset {
88+
font-size: 10px;
89+
vertical-align: super;
90+
}
91+
.content-header {
92+
width:80%;
93+
display: flex;
94+
margin-left: 120px;
95+
font-family: Tahoma;
96+
font-size: 15px;
97+
}
98+
</style>
99+
</head>
100+
<body>
101+
<div class="content-container" style="margin: 0 auto;">
102+
103+
<div class="intro-content-1" style="font-family: 'Segoe UI'; font-size: medium; text-align: center;">
104+
<h1>APPRECIATE</h1>
105+
<p>Thank you for using <i>CrackTech - Find LeetCode Company Tags</i> extension.<br>
106+
This is a small effort to help you in your dream company specific preparation. I wish your prepartion is going well. <br>
107+
And this extension is helping you in every possible way. Read the
108+
<a href = "https://sites.google.com/view/iamavik/leetcode-which-company-a-company-names-retrieval-extension" target="_blank">background</a>
109+
of working on this extension. Visit my writings on <a href="https://sites.google.com/view/iamavik/" target="_blank">Avik Sarkar | <i>Let Avik Connect You!</i></a>
110+
<br>
111+
Do consider sharing this free extension among your fellow LeetCoders. I feel it will be helpful for them as well.
112+
</p>
113+
<hr>
114+
</div>
115+
<div class="header">
116+
<h3 style="margin-left:120px;">Upcoming LeetCode Contest(s)</h3>
117+
<div class="switch" style="margin-right:120px;">
118+
<span class="switch-text">Contest Notification: </span>
119+
<label class="checkbox">
120+
<input type="checkbox" id="notificationCheckbox" checked>
121+
<span class="checkbox"></span>
122+
</label>
123+
<p>[&nbsp;</p><i><span id="switchStatus">Turned On</span></i><p> &nbsp;]</p>
124+
</div>
125+
</div>
126+
<table id="contestTable" style="margin: 0 auto;">
127+
<tr>
128+
<th>Name</th>
129+
<th>Start Date</th>
130+
<th>Start Time</th>
131+
<th>Duration</th>
132+
</tr>
133+
</table>
134+
<table id="nbtable" style="margin: 0 auto;">
135+
<tr>
136+
<td style="border: none;"><i>** Note: Contest information will update around 8AM everyday.</i></td>
137+
</tr>
138+
</table>
139+
<br><br>
140+
<hr>
141+
<div class="preparation-container">
142+
<!-- <h3><center>User Profile Analytics</center></h3> -->
143+
</div>
144+
<br><br>
145+
<div class = "intro-content-2" style="font-family: 'Segoe UI'; font-size: medium; text-align: center;">
146+
<h1>CONTRIBUTIONS</h1>
147+
I appreciate your intention towards contributing in this repository.<br>
148+
Currently I am accepting only the <b>Company Contributions</b> to enrich the company database.<br>
149+
To contribute please follow the instructions of this issue
150+
<a href='https://github.com/ssavi-ict/LC-Which-Company/issues/4' target="_blank">[CONTRIBUTE] Dear Contributors, Requesting Your Attention Regarding Company Contribution</a>.<br>
151+
</div>
152+
<br><br><hr><br><br>
153+
<footer style="text-align: center; font-size: 13px; width:80%; margin-left: 120px;">Made With &#10084; by <a href="https://www.linkedin.com/in/ssavi-ict/">Avik Sarkar</a></footer>
154+
<br>
155+
</div>
156+
</body>
157+
<script type="text/javascript" src="script/helper.js"></script>
158+
</html>

chrome/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"background": {
1919
"service_worker": "background.js"
2020
},
21-
"permissions": ["tabs", "notifications", "alarms"],
21+
"permissions": ["tabs", "notifications", "alarms", "storage"],
2222
"host_permissions": [
2323
"<all_urls>"
2424
]

chrome/popup.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@
5353
<td colspan="3"><a href="index.html" target="_blank"><strong style="font-size: 15px;">All Company</strong></a></td>
5454
</tr>
5555
<tr>
56-
<td><a href="https://github.com/ssavi-ict/LeetCode-Which-Company/issues/4" target="_blank">Contribute</a></td>
56+
<td><a href="leetcoder.html" target="_blank">Upcoming Contest</a></td>
5757
<td><a href="https://forms.gle/cAW1jxYxUTwgUmMd9" target="_blank">Feedback</a></td>
5858
<td><a href="https://www.buymeacoffee.com/ssavi" target="_blank">Buy Me A Coffee</a></td>
5959
</tr>
6060
</table>
6161
</div>
6262
<div class="footer">
63-
&copy; ssavi
63+
[<a href="https://github.com/ssavi-ict/LeetCode-Which-Company/issues/4" target="_blank" style="text-decoration: none;">contribute</a>]
64+
&nbsp;|&nbsp;
65+
[&copy;<a href="https://www.linkedin.com/in/ssavi-ict/" style="text-decoration: none;">ssavi</a>]
6466
</div>
6567
</body>
6668
<script type="text/javascript" src="popup.js"></script>

0 commit comments

Comments
 (0)