It is for daflen.com
It should measure number of notification on the extension
Error: No notification on extension
Code
{
"manifest_version": 3,
"name": "Darflen Notification Counter",
"version": "1.1",
"description": "Displays notification count from Darflen.",
"permissions": ["alarms", "notifications"],
"host_permissions": ["https://www.darflen.com/*"],
"background": {
"service_worker": "background.js"
},
"action": {
"default_icon": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"default_title": "Darflen Notifications"
}
}
async function fetchNotificationCount() {
try {
console.log("Fetching notifications...");
const response = await fetch("https://www.darflen.com/explore");
console.log("Response status:", response.status);
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.statusText}`);
}
const text = await response.text();
console.log("Fetched HTML snippet:", text.substring(0, 500)); // Log part of the page HTML
const parser = new DOMParser();
const doc = parser.parseFromString(text, "text/html");
const notificationElement = doc.querySelector(".nav-notification");
if (notificationElement) {
const notificationCount = notificationElement.textContent.trim();
console.log(`Notification count found: ${notificationCount}`);
chrome.action.setBadgeText({ text: notificationCount });
chrome.action.setBadgeBackgroundColor({ color: "#ff0000" });
} else {
console.log("No notifications found, setting badge to 0.");
chrome.action.setBadgeText({ text: "0" });
chrome.action.setBadgeBackgroundColor({ color: "#808080" });
} catch (error) {
console.error("Error fetching notifications:", error);
chrome.action.setBadgeText({ text: "!" });
chrome.action.setBadgeBackgroundColor({ color: "#888888" }); // Gray badge
}
}
chrome.alarms.create("checkNotifications", { periodInMinutes: 1 });
chrome.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === "checkNotifications") {
fetchNotificationCount();
}
});
fetchNotificationCount();
chrome.action.onClicked.addListener(() => {
chrome.tabs.create({ url: "https://www.darflen.com/notifications" });
});
//darflen website notification
<span class="nav-notifications">1</span>
//found:
https://darflen.com/explore
Only when a notification is present if it isnt that line does not exist
By - BigBrush7625
Comments