Skip to content

Commit ffb903f

Browse files
committed
directly open expose from notification
1 parent 2caa916 commit ffb903f

File tree

3 files changed

+54
-47
lines changed

3 files changed

+54
-47
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This is a browser extension for Chromium based browsers ([Vivaldi](https://vival
1010
- makes sure listing are sorted by latest
1111
- only reloads search pages, not the pages of single listing
1212
- previews the listing title in notifications
13-
- clicking on a notification focuses the tab with the new listing
13+
- clicking on a notification opens a new tab with the new listing
1414

1515
## Visual improvements
1616

background.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
4040
console.log(new Date().toLocaleString());
4141
if (addedIds.size > 0 && prevIds.size > 0) {
4242
console.info(`‼️ ${addedIds.size} new listings`, addedIds);
43-
const titles = [...addedIds].map((id) => titleById[id]);
44-
showNotification(
45-
tabId,
46-
`${addedIds.size} ${addedIds.size === 1 ? "neue Anzeige" : "neue Anzeigen"}`,
47-
titles.join(" · "),
48-
);
43+
const ids = [...addedIds];
44+
for (const id of ids) {
45+
showNotification(
46+
id,
47+
`${addedIds.size} ${addedIds.size === 1 ? "neue Anzeige" : "neue Anzeigen"}`,
48+
titleById[id],
49+
);
50+
}
4951
} else {
5052
console.log("no new listings", prevIds);
5153
}
@@ -65,11 +67,12 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
6567
chrome.notifications.onClicked.addListener(async (notificationId) => {
6668
const prefix = "immo24:";
6769
if (notificationId.startsWith(prefix)) {
68-
const tabId = parseInt(notificationId.slice(prefix.length), 10);
69-
if (!isNaN(tabId)) {
70+
const exposeId = parseInt(notificationId.slice(prefix.length), 10);
71+
if (!isNaN(exposeId)) {
7072
try {
71-
const tab = await chrome.tabs.get(tabId);
72-
await chrome.tabs.update(tabId, { active: true });
73+
const tab = await chrome.tabs.create({
74+
url: `https://www.immobilienscout24.de/expose/${exposeId}`,
75+
});
7376
await chrome.windows.update(tab.windowId, { focused: true });
7477
} catch (err) {
7578
console.error("Failed to focus tab", err);
@@ -93,8 +96,8 @@ function collectListingIds() {
9396
}
9497

9598
// Show notification from service worker
96-
async function showNotification(tabId, title, message) {
97-
await chrome.notifications.create("immo24:" + tabId, {
99+
async function showNotification(exposeId, title, message) {
100+
await chrome.notifications.create("immo24:" + exposeId, {
98101
type: "basic",
99102
iconUrl: "icon-48.png",
100103
title: title,

manifest.json

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
{
2-
"name": "Immo24 Notifier",
3-
"version": "1.1.0",
4-
"manifest_version": 3,
5-
"description": "Immo24 Notifier extension by Maximilian Hoffmann",
6-
"homepage_url": "https://github.com/maxhoffmann/immo-extension",
7-
"permissions": [
8-
"tabs",
9-
"notifications",
10-
"scripting"
11-
],
12-
"host_permissions": [
13-
"https://www.immobilienscout24.de/*"
14-
],
15-
"icons": {
16-
"16": "icon-16.png",
17-
"19": "icon-19.png",
18-
"38": "icon-38.png",
19-
"48": "icon-48.png",
20-
"128": "icon-128.png"
21-
},
22-
"action": {
23-
"default_title": "Immo24 Notifier",
24-
"default_icon": "icon-128.png",
25-
"default_popup": "popup.html"
26-
},
27-
"background": {
28-
"service_worker": "background.js"
29-
},
30-
"content_scripts": [
31-
{
32-
"matches": ["https://www.immobilienscout24.de/*"],
33-
"css": ["immo.css"]
34-
}
35-
]
2+
"name": "Immo24 Notifier",
3+
"version": "2.0.0",
4+
"manifest_version": 3,
5+
"description": "Immo24 Notifier extension by Maximilian Hoffmann",
6+
"homepage_url": "https://github.com/maxhoffmann/immo-extension",
7+
"permissions": [
8+
"tabs",
9+
"notifications",
10+
"scripting"
11+
],
12+
"host_permissions": [
13+
"https://www.immobilienscout24.de/*"
14+
],
15+
"icons": {
16+
"16": "icon-16.png",
17+
"19": "icon-19.png",
18+
"38": "icon-38.png",
19+
"48": "icon-48.png",
20+
"128": "icon-128.png"
21+
},
22+
"action": {
23+
"default_title": "Immo24 Notifier",
24+
"default_icon": "icon-128.png",
25+
"default_popup": "popup.html"
26+
},
27+
"background": {
28+
"service_worker": "background.js"
29+
},
30+
"content_scripts": [
31+
{
32+
"matches": [
33+
"https://www.immobilienscout24.de/*"
34+
],
35+
"css": [
36+
"immo.css"
37+
]
38+
}
39+
]
3640
}

0 commit comments

Comments
 (0)