Skip to content

Commit

Permalink
Checkpoint: sound currently broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
FMaz008 committed Oct 7, 2024
1 parent 095d704 commit 6fdf86e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 77 deletions.
15 changes: 1 addition & 14 deletions page/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ var vineDomain = null;

const broadcastChannel = new BroadcastChannel("VineHelperChannel");

//Load stream-browserify
/*
(async () => {
const src = chrome.runtime.getURL("node_modules/stream-browserify/index.js");
await import(src);
})();
async function run() {
await pipeline(console.log("pipeline"), console.log("action2"));
console.log("Pipeline succeeded.");
}
run().catch(console.error);
*/

const handleReportClick = (e) => {
e.preventDefault(); // Prevent the default click behavior
report(e.target.dataset.asin);
Expand Down Expand Up @@ -161,6 +147,7 @@ window.onload = function () {
Notifications.pushNotification(note);
}
if (data.type == "newItemCheckEnd") {
console.log("end");
if (notification_added_item) {
playSoundAccordingToNotificationType(notification_highlight, notification_zeroETV);
}
Expand Down
131 changes: 68 additions & 63 deletions scripts/vh_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,72 @@ const VINE_HELPER_API_V5_WS_URL = "wss://api.vinehelper.ovh";
import { SettingsMgr } from "../scripts/SettingsMgr.js";
import "../node_modules/socket.io/client-dist/socket.io.min.js";
import "../plugins/_pluginsInit.js";
import { Streamy } from "./Streamy.js";

const myStream = new Streamy();
const filterHideitem = myStream.filter(function (data) {
if (Settings.get("notification.hideList")) {
const hideKWMatch = keywordMatch(Settings.get("general.hideKeywords"), data.title);
if (hideKWMatch) {
return false; //Do not display the notification as it matches the hide list.
}
}
return true;
});
const transformIsHighlight = myStream.transformer(function (data) {
const highlightKWMatch = keywordMatch(Settings.get("general.highlightKeywords"), data.title);
data.KWsMatch = highlightKWMatch;
return data;
});
const transformSearchPhrase = myStream.transformer(function (data) {
const search = data.title.replace(/^([a-zA-Z0-9\s',]{0,40})[\s]+.*$/, "$1");
data.search = search;
return data;
});
const transformUnixTimestamp = myStream.transformer(function (data) {
data.timestamp = dateToUnixTimestamp(data.date);
return data;
});
const transformPostNotification = myStream.transformer(function (data) {
//If the new item match a highlight keyword, push a real notification.
if (Settings.get("notification.pushNotifications") && data.highlightKWMatch) {
pushNotification(
data.asin,
data.queue,
data.is_parent_asin,
data.enrollment_guid,
data.search,
"Vine Helper - New item match KW!",
data.title,
data.img_url
);
}
//If the new item match in AFA queue, push a real notification.
else if (Settings.get("notification.pushNotificationsAFA") && data.queue == "last_chance") {
pushNotification(
data.asin,
data.queue,
data.is_parent_asin,
data.enrollment_guid,
data.search,
"Vine Helper - New AFA item",
data.title,
data.img_url
);
}
return data;
});
myStream
.pipe(filterHideitem)
.pipe(transformIsHighlight)
.pipe(transformSearchPhrase)
.pipe(transformUnixTimestamp)
.pipe(transformPostNotification)
.output((data) => {
//Broadcast the notification
//console.log("Broadcasting new item " + data.asin);
sendMessageToAllTabs(data, "notification");
});

/*
if ("function" == typeof importScripts) {
Expand Down Expand Up @@ -102,7 +168,7 @@ function connectWebSocket() {

socket.on("newItem", (data) => {
// Assuming the server sends the data in the same format as before
dispatchNewItem({
myStream.input({
index: 0,
type: "newItem",
domain: vineCountry,
Expand Down Expand Up @@ -212,7 +278,7 @@ async function fetchLast100Items(fetchAll = false) {
}
if (fetchAll || timestamp > Settings.get("notification.lastProduct")) {
Settings.set("notification.lastProduct", timestamp);
dispatchNewItem({
myStream.input({
index: i,
type: "newItem",
domain: vineCountry,
Expand Down Expand Up @@ -246,67 +312,6 @@ async function fetchLast100Items(fetchAll = false) {
});
}

function dispatchNewItem(data) {
if (Settings.get("notification.hideList")) {
const hideKWMatch = keywordMatch(Settings.get("general.hideKeywords"), data.title);
if (hideKWMatch) {
return; //Do not display the notification as it matches the hide list.
}
}

const search = data.title.replace(/^([a-zA-Z0-9\s',]{0,40})[\s]+.*$/, "$1");
const highlightKWMatch = keywordMatch(Settings.get("general.highlightKeywords"), data.title);

//If the new item match a highlight keyword, push a real notification.
if (Settings.get("notification.pushNotifications") && highlightKWMatch) {
pushNotification(
data.asin,
data.queue,
data.is_parent_asin,
data.enrollment_guid,
search,
"Vine Helper - New item match KW!",
data.title,
data.img_url
);
}
//If the new item match in AFA queue, push a real notification.
else if (Settings.get("notification.pushNotificationsAFA") && data.queue == "last_chance") {
pushNotification(
data.asin,
data.queue,
data.is_parent_asin,
data.enrollment_guid,
search,
"Vine Helper - New AFA item",
data.title,
data.img_url
);
}

//Broadcast the notification
//console.log("Broadcasting new item " + data.asin);
sendMessageToAllTabs(
{
index: data.index,
type: data.type,
domain: vineCountry,
date: data.date,
timestamp: dateToUnixTimestamp(data.date),
asin: data.asin,
title: data.title,
search: search,
img_url: data.img_url,
etv: data.etv,
queue: data.queue,
KWsMatch: highlightKWMatch,
is_parent_asin: data.is_parent_asin,
enrollment_guid: data.enrollment_guid,
},
"notification"
);
}

function pushNotification(asin, queue, is_parent_asin, enrollment_guid, search_string, title, description, img_url) {
chrome.notifications.onClicked.addListener((notificationId) => {
const { asin, queue, is_parent_asin, enrollment_guid, search } = notificationsData[notificationId];
Expand Down

0 comments on commit 6fdf86e

Please sign in to comment.