Skip to content

Commit a50b899

Browse files
committed
feat: v1.1.0 - welcome page redirect, settings bridge, instanceUrl support
- Open welcome page on extension install via instanceUrl - Add pastefox-bridge.js content script for postMessage communication - Add openSettings handler in background scripts - Register content_scripts in manifests for PasteFox + localhost - Bump version to 1.1.0
1 parent 29a90ce commit a50b899

7 files changed

Lines changed: 68 additions & 8 deletions

File tree

chrome/background.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Context menu setup
2-
chrome.runtime.onInstalled.addListener(() => {
1+
// Context menu setup + welcome page on install
2+
chrome.runtime.onInstalled.addListener(async (details) => {
33
chrome.contextMenus.create({
44
id: "pastefox-selection",
55
title: "Share to PasteFox",
@@ -11,6 +11,16 @@ chrome.runtime.onInstalled.addListener(() => {
1111
title: "Share page content to PasteFox",
1212
contexts: ["page"],
1313
});
14+
15+
// Open welcome page on first install
16+
if (details.reason === "install") {
17+
const settings = await getSettings();
18+
const baseUrl = settings.instanceUrl.replace(/\/$/, "");
19+
chrome.tabs.create({
20+
url: `${baseUrl}/extension/welcome?browser=chrome&token=pf-ext-installed`,
21+
active: true,
22+
});
23+
}
1424
});
1525

1626
// Handle context menu clicks
@@ -40,6 +50,10 @@ chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
4050
getSettings().then(sendResponse);
4151
return true;
4252
}
53+
if (msg.action === "openSettings") {
54+
chrome.runtime.openOptionsPage();
55+
sendResponse({ success: true });
56+
}
4357
});
4458

4559
// Settings helper

chrome/manifest.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "PasteFox",
44
"description": "Share code and text snippets to PasteFox with one click",
5-
"version": "1.0.0",
5+
"version": "1.1.0",
66
"icons": {
77
"16": "icons/icon16.png",
88
"48": "icons/icon48.png",
@@ -28,5 +28,12 @@
2828
],
2929
"background": {
3030
"service_worker": "background.js"
31-
}
31+
},
32+
"content_scripts": [
33+
{
34+
"matches": ["https://pastefox.com/*", "https://*.pastefox.com/*", "http://localhost/*", "http://127.0.0.1/*"],
35+
"js": ["pastefox-bridge.js"],
36+
"run_at": "document_idle"
37+
}
38+
]
3239
}

chrome/pastefox-bridge.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Bridge script — injected only on PasteFox pages
2+
// Listens for postMessage from the webpage to open extension settings
3+
4+
window.addEventListener("message", (event) => {
5+
if (event.source !== window) return;
6+
if (event.data?.type === "PASTEFOX_OPEN_SETTINGS") {
7+
chrome.runtime.sendMessage({ action: "openSettings" });
8+
}
9+
});

firefox/background.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Context menu setup
2-
chrome.runtime.onInstalled.addListener(() => {
1+
// Context menu setup + welcome page on install
2+
chrome.runtime.onInstalled.addListener(async (details) => {
33
chrome.contextMenus.create({
44
id: "pastefox-selection",
55
title: "Share to PasteFox",
@@ -11,6 +11,16 @@ chrome.runtime.onInstalled.addListener(() => {
1111
title: "Share page content to PasteFox",
1212
contexts: ["page"],
1313
});
14+
15+
// Open welcome page on first install
16+
if (details.reason === "install") {
17+
const settings = await getSettings();
18+
const baseUrl = settings.instanceUrl.replace(/\/$/, "");
19+
chrome.tabs.create({
20+
url: `${baseUrl}/extension/welcome?browser=firefox&token=pf-ext-installed`,
21+
active: true,
22+
});
23+
}
1424
});
1525

1626
// Handle context menu clicks
@@ -40,6 +50,10 @@ chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
4050
getSettings().then(sendResponse);
4151
return true;
4252
}
53+
if (msg.action === "openSettings") {
54+
chrome.runtime.openOptionsPage();
55+
sendResponse({ success: true });
56+
}
4357
});
4458

4559
// Settings helper

firefox/manifest.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 3,
33
"name": "PasteFox",
44
"description": "Share code and text snippets to PasteFox with one click",
5-
"version": "1.0.0",
5+
"version": "1.1.0",
66
"browser_specific_settings": {
77
"gecko": {
88
"id": "extension@pastefox.com",
@@ -40,5 +40,12 @@
4040
],
4141
"background": {
4242
"scripts": ["background.js"]
43-
}
43+
},
44+
"content_scripts": [
45+
{
46+
"matches": ["https://pastefox.com/*", "https://*.pastefox.com/*", "http://localhost/*", "http://127.0.0.1/*"],
47+
"js": ["pastefox-bridge.js"],
48+
"run_at": "document_idle"
49+
}
50+
]
4451
}

firefox/pastefox-bridge.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Bridge script — injected only on PasteFox pages
2+
// Listens for postMessage from the webpage to open extension settings
3+
4+
window.addEventListener("message", (event) => {
5+
if (event.source !== window) return;
6+
if (event.data?.type === "PASTEFOX_OPEN_SETTINGS") {
7+
chrome.runtime.sendMessage({ action: "openSettings" });
8+
}
9+
});

0 commit comments

Comments
 (0)