Move match actions to background.js.
Send notifications and play audio via message passing.
This commit is contained in:
parent
d2d435527e
commit
33fcf0ab21
|
@ -0,0 +1,13 @@
|
|||
function handleMatch(match) {
|
||||
new Notification("Match found", {body: match});
|
||||
const audio = new Audio(browser.runtime.getURL("static/notif.mp3"));
|
||||
audio.play();
|
||||
}
|
||||
|
||||
|
||||
function handleMessage(request) {
|
||||
if (request.type == "match")
|
||||
return handleMatch(request.match);
|
||||
}
|
||||
|
||||
browser.runtime.onMessage.addListener(handleMessage);
|
9
gmcr.js
9
gmcr.js
|
@ -13,7 +13,6 @@ function surroundText(haystack, wordList, padding) {
|
|||
surroundingText += "...";
|
||||
|
||||
surroundingText += "<br>";
|
||||
console.log(start, end, surroundingText);
|
||||
});
|
||||
return surroundingText.trim();
|
||||
}
|
||||
|
@ -52,15 +51,15 @@ function captionUpdate() {
|
|||
} else {
|
||||
[ matched, surroundingText ] = simpleMatch(captions, storage.words);
|
||||
}
|
||||
console.log(matched, surroundingText);
|
||||
/* The lastNotification prevents repetitive notifications because
|
||||
* of constant updates.
|
||||
*/
|
||||
if (matched && surroundingText !== lastNotification) {
|
||||
new Notification("Match found", {body: surroundingText});
|
||||
browser.runtime.sendMessage({
|
||||
type: "match",
|
||||
match: surroundingText
|
||||
});
|
||||
lastNotification = surroundingText;
|
||||
const audio = new Audio(browser.runtime.getURL("static/notif.mp3"));
|
||||
audio.play();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Google Meet Caption Regex",
|
||||
"version": "1.2",
|
||||
"version": "1.3",
|
||||
|
||||
"description": "Send a notification when a caption in Google Meet matches a certain regex.",
|
||||
"homepage_url": "https://gitlab.com/ceda_ei/google-meet-captions-regex",
|
||||
|
@ -22,11 +22,16 @@
|
|||
"default_popup": "popup/build/index.html"
|
||||
},
|
||||
|
||||
"background": {
|
||||
"scripts": ["background.js"]
|
||||
},
|
||||
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://meet.google.com/*"],
|
||||
"js": ["gmcr.js"]
|
||||
}
|
||||
],
|
||||
|
||||
"web_accessible_resources": ["static/*"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue