Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

on:
pull_request:
branches: [master]
push:
branches: [master]

permissions:
contents: read

jobs:
test-and-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
- run: npm test
- run: npm run build
- run: npm run build:chromium
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
dist/
dist-chromium/
*.log
.DS_Store
web-ext-artifacts/
Expand Down
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BagMark 🎒

> An advanced, lightweight Firefox extension to quickly save bookmarks to customizable or date-organized folders with rich metadata and duplicate detection.
> An advanced, lightweight extension for Firefox, Chrome, and Brave to quickly save bookmarks to customizable or date-organized folders with rich metadata and duplicate detection.

![BagMark Icon](public/assets/icon.svg)

Expand All @@ -12,10 +12,11 @@
- **Context Submenus for Custom Folders**: Right-click submenu (`"Bag It to ▸"`) dynamically lists your favorite / pinned bookmark folders.
- **Chronological Date Organization**: Optional auto-filing into year-month subfolders (e.g. `BagMark / 2026-09 / ...`), created on the fly.
- **Rich Metadata Capture**: Automatically records exact timestamps (`dateAdded`), originating webpage URL/title, and any highlighted quote/text excerpt into local storage.
- **Duplicate Link Detection**: Alerts you if a link has already been bookmarked, showing where and when it was saved.
- **Duplicate Link Detection**: Skips links already saved in the destination folder while allowing the same link in other collections. Compares both URLs without known tracking parameters, preserving meaningful query parameters, fragments, and path differences. Disable this in Settings to allow repeated links in the same folder.
- **Interactive Popup Dashboard**: Fast, search-as-you-type dashboard to filter bookmarks by title, URL, quote, or tags, with folder filters, relative time badges, and 1-click clipboard copy.
- **Save Open Tabs**: Expand **Save open tabs** in the popup, choose an existing folder or create a new subfolder, and save all web tabs from the current window in tab order. Tabs stay open, browser pages are skipped, and the result shows saved, skipped, and failed counts. The chosen folder is used directly, without automatic date subfolders.
- **Options & Customization**: Configure default folder name, toggle date-based subfolders, manage pinned submenu folders, and adjust alert notifications.
- **Modern Stack**: Built with TypeScript, Vite, Vitest, and Firefox Manifest V3.
- **Modern Stack**: Built with TypeScript, Vite, Vitest, and Manifest V3.

---

Expand All @@ -25,7 +26,7 @@

- Node.js (v18+)
- npm or pnpm
- Mozilla Firefox (v115+)
- Mozilla Firefox (v115+), Chrome (v123+), or Brave based on Chromium v123+

### Installation & Development

Expand Down Expand Up @@ -56,6 +57,21 @@
- Select `dist/manifest.json` from this project directory.
- Right-click any link on the web to start bagging links!

### Chrome & Brave

Both browsers use the same Chromium build:

```bash
npm run build:chromium
```

1. Open `chrome://extensions` in Chrome or `brave://extensions` in Brave.
2. Enable **Developer mode**.
3. Click **Load unpacked** and select the project's `dist-chromium` folder.
4. Pin BagMark to the toolbar, then right-click a webpage or link to save it.

Firefox builds remain in `dist`; Chromium builds go to `dist-chromium` so rebuilding one does not remove the other. After rebuilding, click **Reload** on the extension's card. The existing packaging and signing commands produce Firefox artifacts; Chrome and Brave use the unpacked Chromium folder for local testing.

---

## 📦 Distribution & Packaging
Expand Down Expand Up @@ -111,7 +127,7 @@ bagmark/
│ ├── utils.ts # Date formatters & URL normalizer
│ ├── storage.ts # Metadata local storage manager
│ ├── config.ts # Settings persistence
│ └── bookmarks.ts # Firefox bookmark tree traversal & creation
│ └── bookmarks.ts # Cross-browser bookmark tree traversal & creation
└── tests/ # Vitest automated test suite
```

Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"manifest_version": 3,
"name": "BagMark - Advanced Bookmarks",
"version": "1.0.2",
"version": "1.1.0",
"description": "Right-click to save bookmarks to custom or date-based folders with rich metadata.",
"permissions": [
"bookmarks",
"menus",
"contextMenus",
"storage",
"notifications",
"tabs"
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "bag-bookmark",
"version": "1.0.2",
"description": "Advanced Firefox bookmark extension with date tracking, custom folders, and context menu quick-save",
"version": "1.1.0",
"description": "Advanced bookmark extension for Firefox, Chrome, and Brave with date tracking, custom folders, and context menu quick-save",
"type": "module",
"scripts": {
"dev": "vite build --watch",
"build": "tsc --noEmit && vite build",
"build:chromium": "tsc --noEmit && vite build --mode chromium",
"lint": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
Expand Down
130 changes: 46 additions & 84 deletions src/background/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { ensureRootFolder, ensureDateSubfolder, findDuplicateBookmark } from '../lib/bookmarks';
import '../lib/browser';
import { saveBookmark } from '../lib/bookmarks';
import { getSettings } from '../lib/config';
import { saveMetadata } from '../lib/storage';
import { BookmarkMetadata } from '../lib/types';
import { formatDisplayDate } from '../lib/utils';
import { saveOpenTabs } from '../lib/tabs';

const QUICK_SAVE_ID = 'bagmark_quick_save';
const SUBMENU_ROOT_ID = 'bagmark_submenu_root';

async function updateContextMenus() {
await browser.menus.removeAll();
await browser.contextMenus.removeAll();

const settings = await getSettings();

// 1. Top-level 1-click Quick Save to default folder
browser.menus.create({
browser.contextMenus.create({
id: QUICK_SAVE_ID,
title: `Bag It (Save to ${settings.defaultFolderName})`,
contexts: ['link', 'page', 'selection'],
});

// 2. Submenu for custom / favorite folders
if (settings.favoriteFolderIds && settings.favoriteFolderIds.length > 0) {
browser.menus.create({
browser.contextMenus.create({
id: SUBMENU_ROOT_ID,
title: 'Bag It to ▸',
contexts: ['link', 'page', 'selection'],
Expand All @@ -31,7 +31,7 @@ async function updateContextMenus() {
try {
const nodes = await browser.bookmarks.get(folderId);
if (nodes && nodes[0]) {
browser.menus.create({
browser.contextMenus.create({
id: `bagmark_target_${folderId}`,
parentId: SUBMENU_ROOT_ID,
title: nodes[0].title,
Expand All @@ -46,7 +46,7 @@ async function updateContextMenus() {
}

async function handleSaveAction(
info: browser.menus.OnClickData,
info: browser.contextMenus.OnClickData,
tab?: browser.tabs.Tab
) {
if (info.menuItemId === SUBMENU_ROOT_ID) {
Expand All @@ -58,82 +58,39 @@ async function handleSaveAction(
if (!targetUrl) return;

const targetTitle = info.linkText || tab?.title || targetUrl;
const quote = info.selectionText || undefined;
const sourcePageUrl = info.pageUrl;
const sourcePageTitle = tab?.title;
try {
const targetFolderId = info.menuItemId.toString().startsWith('bagmark_target_')
? info.menuItemId.toString().replace('bagmark_target_', '')
: undefined;
const { node, isDuplicate, folderTitle } = await saveBookmark({
url: targetUrl,
title: targetTitle,
targetFolderId,
defaultFolderName: settings.defaultFolderName,
enableDateSubfolders: settings.enableDateSubfolders,
warnDuplicates: settings.warnDuplicates,
sourcePageUrl: info.pageUrl,
sourcePageTitle: tab?.title,
quote: info.selectionText || undefined,
});

// Duplicate Check
if (settings.warnDuplicates) {
const duplicate = await findDuplicateBookmark(targetUrl);
if (duplicate) {
if (settings.showNotifications) {
const addedDate = duplicate.dateAdded ? formatDisplayDate(duplicate.dateAdded) : 'previously';
if (settings.showNotifications) {
if (isDuplicate) {
const addedDate = node.dateAdded ? formatDisplayDate(node.dateAdded) : 'previously';
browser.notifications.create({
type: 'basic',
iconUrl: 'assets/icon-48.png',
title: 'Already in this folder!',
message: `"${node.title}" was already saved in ${folderTitle} on ${addedDate}.`,
});
} else {
browser.notifications.create({
type: 'basic',
iconUrl: 'assets/icon-48.png',
title: 'Already in BagMark!',
message: `"${duplicate.title}" was already saved on ${addedDate}.`,
title: 'Bagged Successfully! 🎒',
message: `Saved "${targetTitle}" to ${folderTitle}`,
});
}
return;
}
}

try {
// Determine base folder
let baseFolderId: string;
let baseFolderTitle: string = settings.defaultFolderName;

if (info.menuItemId.toString().startsWith('bagmark_target_')) {
baseFolderId = info.menuItemId.toString().replace('bagmark_target_', '');
const folderNodes = await browser.bookmarks.get(baseFolderId);
baseFolderTitle = folderNodes[0]?.title || 'Folder';
} else {
const rootNode = await ensureRootFolder(settings.defaultFolderName);
baseFolderId = rootNode.id;
baseFolderTitle = rootNode.title;
}

// Determine destination folder (auto-date subfolder if enabled)
let destFolderId = baseFolderId;
let destFolderTitle = baseFolderTitle;

if (settings.enableDateSubfolders) {
const dateNode = await ensureDateSubfolder(baseFolderId, new Date());
destFolderId = dateNode.id;
destFolderTitle = `${baseFolderTitle} / ${dateNode.title}`;
}

// Create Bookmark
const newBookmark = await browser.bookmarks.create({
parentId: destFolderId,
title: targetTitle,
url: targetUrl,
});

// Store Rich Metadata
const metadata: BookmarkMetadata = {
id: newBookmark.id,
url: targetUrl,
title: targetTitle,
dateAdded: newBookmark.dateAdded || Date.now(),
folderId: destFolderId,
folderTitle: destFolderTitle,
sourcePageUrl,
sourcePageTitle,
quote,
tags: [],
};
await saveMetadata(metadata);

// Notification confirmation
if (settings.showNotifications) {
browser.notifications.create({
type: 'basic',
iconUrl: 'assets/icon-48.png',
title: 'Bagged Successfully! 🎒',
message: `Saved "${targetTitle}" to ${destFolderTitle}`,
});
}
} catch (error) {
console.error('Failed to save bookmark:', error);
Expand All @@ -142,7 +99,7 @@ async function handleSaveAction(
type: 'basic',
iconUrl: 'assets/icon-48.png',
title: 'BagMark Save Failed',
message: 'Could not save bookmark. Target folder may no longer exist.',
message: 'Could not save bookmark or metadata. Check the destination folder before retrying.',
});
}
}
Expand All @@ -162,10 +119,15 @@ browser.storage.onChanged.addListener((changes, area) => {
}
});

browser.menus.onClicked.addListener((info, tab) => {
handleSaveAction(info, tab);
browser.contextMenus.onClicked.addListener((info, tab) => {
return handleSaveAction(info, tab);
});

// Call immediately on background script execution
updateContextMenus();

browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message?.type !== 'save-open-tabs' || sender.id !== browser.runtime.id) return false;
saveOpenTabs(message).then(sendResponse, (error) => {
sendResponse({ error: error instanceof Error ? error.message : 'Could not save open tabs.' });
});
// Keep the response channel open on Chromium versions without async listener support.
return true;
});
Loading
Loading