Skip to content

Commit 8313a09

Browse files
committed
[v1.0.6] Notification Added for Firefox/Edge
1 parent d8fb4f9 commit 8313a09

File tree

15 files changed

+795
-11
lines changed

15 files changed

+795
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
- **Leetcoder.html** page to show contest details as per user's GMT.
88
- **Upcoming Contest** desktop notification.
99
- **Enabling** or **Disabling** notification as per user's choice.
10-
- Implementation Status: Chrome (*Done*), Firefox (*Ongoing*)
10+
- Implementation Status: Chrome (*Done*), Edge (*Done*)
11+
- Firefox Notification handling in a different way due to mdn API limitation.
12+
- Contest details scrapping script added.
13+
- Workflow added to run the contest script.
1114

1215
**[03/06/2023]**
1316
- Improved User Interface.
Binary file not shown.
Binary file not shown.
Binary file not shown.

edge/background.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Function to show the notification
2+
function showNotification(title, message) {
3+
const options = {
4+
type: "basic",
5+
iconUrl: "res/notify_icon.png",
6+
title: title,
7+
message: message || "No Contest Available",
8+
buttons: [
9+
{ title: "Turn Off Notification" },
10+
{ title: "Visit Leetcode" }
11+
]
12+
};
13+
14+
// chrome.notifications.create("", options);
15+
// Generate a unique notification ID
16+
const notificationId = `cracktech_notification_${Date.now()}`;
17+
chrome.notifications.create(notificationId, options);
18+
}
19+
20+
// Helper function to convert epoch to date string
21+
function convertEpochToDateString(epoch) {
22+
const date = new Date(epoch * 1000);
23+
const options = { timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone };
24+
const dateTimeString = date.toLocaleString(undefined, options);
25+
return dateTimeString;
26+
}
27+
28+
// Helper function to convert duration in seconds to hours and minutes string
29+
function convertDurationToString(durationInSeconds) {
30+
const hours = Math.floor(durationInSeconds / 3600);
31+
const minutes = Math.floor((durationInSeconds % 3600) / 60);
32+
33+
let durationString = '';
34+
if (hours > 0) {
35+
durationString += `${hours}:`;
36+
}
37+
if (minutes > 0) {
38+
durationString += `${hours > 0 ? '' : ''}${minutes}`;
39+
}
40+
41+
return durationString;
42+
}
43+
44+
function fetchNotificationContent() {
45+
fetch("https://raw.githubusercontent.com/ssavi-ict/LeetCode-Which-Company/main/data/contests.json")
46+
.then(response => response.json())
47+
.then(data => {
48+
// const message = JSON.stringify(data);
49+
// console.log(message);
50+
// 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
54+
55+
Object.entries(data).forEach(([key, value]) => {
56+
const start_time = value.start_time;
57+
58+
if (start_time < currentTime) {
59+
contestCount--;
60+
}
61+
});
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+
}
70+
})
71+
.catch(error => {
72+
console.log("Error fetching notification content:", error);
73+
// showNotification(); // Show the notification with default values in case of an error
74+
});
75+
}
76+
77+
// Variable to track the first notification
78+
let firstNotificationScheduled = false;
79+
80+
// Event listener for the browser startup
81+
chrome.runtime.onStartup.addListener(function () {
82+
scheduleFirstNotification();
83+
});
84+
85+
// Event listener for the browser installation/upgrade
86+
chrome.runtime.onInstalled.addListener(function () {
87+
scheduleFirstNotification();
88+
});
89+
90+
// Function to schedule the first notification
91+
function scheduleFirstNotification() {
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+
});
101+
}
102+
103+
// chrome.tabs.onCreated.addListener(function(tab) {
104+
// fetchNotificationContent();
105+
// });
106+
107+
// Event listener for the alarm trigger
108+
chrome.alarms.onAlarm.addListener(function (alarm) {
109+
if (alarm.name === "firstNotificationAlarm") {
110+
fetchNotificationContent();
111+
scheduleSecondNotification();
112+
// firstNotificationScheduled = false; // Set the flag to false after the first notification
113+
} else if (alarm.name === "secondNotificationAlarm") {
114+
fetchNotificationContent();
115+
}
116+
});
117+
118+
// Function to schedule the second notification
119+
function scheduleSecondNotification() {
120+
chrome.alarms.create("secondNotificationAlarm", { delayInMinutes: 15 });
121+
}
122+
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+
// });
129+
130+
// Event listener for notification button clicks
131+
chrome.notifications.onButtonClicked.addListener(function (notificationId, buttonIndex) {
132+
if (notificationId.startsWith("cracktech_notification_")) {
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+
}
138+
}
139+
});

edge/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>

edge/manifest.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CrackTech - Find LeetCode Company Tags",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"homepage_url":"https://github.com/ssavi-ict/LC-Which-Company",
55
"description": "An extension that can help candidate to prepare for a Company specific DSA interview.",
66
"manifest_version": 3,
@@ -10,7 +10,16 @@
1010
"default_title": "CrackTech - Find LeetCode Company Tags"
1111
},
1212
"icons": {
13-
"32": "res/32.png"
13+
"32": "res/32.png",
14+
"16": "res/16.png",
15+
"48": "res/48.png",
16+
"128": "res/128.png"
1417
},
15-
"permissions": ["tabs"]
18+
"background": {
19+
"service_worker": "background.js"
20+
},
21+
"permissions": ["tabs", "notifications", "alarms", "storage"],
22+
"host_permissions": [
23+
"<all_urls>"
24+
]
1625
}

edge/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>

edge/res/notify_icon.png

968 Bytes
Loading

0 commit comments

Comments
 (0)