From ed45ec12709646473b0a3a0d36619b8eb2aaee33 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Sun, 4 Jan 2026 15:28:14 -0400 Subject: [PATCH] Initial commit --- .gitignore | 25 +++ LICENSE | 373 +++++++++++++++++++++++++++++++++++++++++++ README.md | 40 +++++ background.js | 164 +++++++++++++++++++ icons/ember-48.svg | 31 ++++ icons/ember-96.svg | 32 ++++ manifest.json | 33 ++++ options/options.html | 285 +++++++++++++++++++++++++++++++++ options/options.js | 64 ++++++++ popup/popup.html | 46 ++++++ popup/popup.js | 14 ++ shared/styles.css | 182 +++++++++++++++++++++ shared/ui.js | 116 ++++++++++++++ 13 files changed, 1405 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 background.js create mode 100644 icons/ember-48.svg create mode 100644 icons/ember-96.svg create mode 100644 manifest.json create mode 100644 options/options.html create mode 100644 options/options.js create mode 100644 popup/popup.html create mode 100644 popup/popup.js create mode 100644 shared/styles.css create mode 100644 shared/ui.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dae6a69 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Build artifacts +web-ext-artifacts/ +*.xpi +*.zip + +# Dependencies +node_modules/ + +# npm +package-lock.json + +# OS files +.DS_Store +Thumbs.db + +# Editor files +*.swp +*.swo +*~ +.idea/ +.vscode/ + +# Logs +*.log +npm-debug.log* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d0a1fa1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at https://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cf64ce6 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Embermarks + +A Firefox extension that surfaces your forgotten bookmarks — the ones you saved but never visit. + +## Installation + +### From Firefox Add-ons (recommended) + +[Install from AMO](https://addons.mozilla.org/firefox/addon/embermarks/) + +### Manual Install + +Download the latest `.xpi` from [Releases](https://github.com/gruberb/embermarks/releases) and drag it into Firefox. + +## Features + +- **Discover forgotten bookmarks** — Shows bookmarks you've rarely or never visited +- **Configurable criteria** — Set maximum visit count and minimum age for "forgotten" status +- **Exclude folders** — Keep certain bookmark folders out of suggestions +- **Quick actions** — Visit, skip, or delete bookmarks directly from the popup + +## Building from Source + +```sh +git clone https://github.com/gruberb/embermarks.git +cd embermarks +npx web-ext build +``` + +The extension will be built to `web-ext-artifacts/`. + +To run in development mode: + +```sh +npx web-ext run +``` + +## License + +Mozilla Public License Version 2.0 diff --git a/background.js b/background.js new file mode 100644 index 0000000..f639a42 --- /dev/null +++ b/background.js @@ -0,0 +1,164 @@ +// Embermarks - Background Script +// Handles bookmark analysis and forgotten bookmark detection + +// Minimum valid timestamp (Jan 1, 2010) - older dates are likely corrupted imports +const MIN_VALID_TIMESTAMP = 1262304000000; + +const DEFAULT_SETTINGS = { + excludedFolders: [], + numBookmarks: 5, + maxVisitCount: 2, // Consider "forgotten" if visited 2 or fewer times + minAgeDays: 7, // Only show bookmarks older than 7 days +}; + +// Get user settings +async function getSettings() { + const result = await browser.storage.local.get("settings"); + return { ...DEFAULT_SETTINGS, ...result.settings }; +} + +// Save settings +async function saveSettings(settings) { + await browser.storage.local.set({ + settings: { ...DEFAULT_SETTINGS, ...settings }, + }); +} + +// Get all bookmarks recursively, respecting excluded folders +async function getAllBookmarks(excludedFolderIds = []) { + const tree = await browser.bookmarks.getTree(); + const bookmarks = []; + + function traverse(nodes, currentPath = "") { + for (const node of nodes) { + // Skip excluded folders and their children + if (excludedFolderIds.includes(node.id)) { + continue; + } + + if (node.url) { + // It's a bookmark + bookmarks.push({ + id: node.id, + title: node.title || "Untitled", + url: node.url, + dateAdded: node.dateAdded, + path: currentPath, + }); + } + + if (node.children) { + const folderName = node.title || ""; + const newPath = currentPath + ? `${currentPath} / ${folderName}` + : folderName; + traverse(node.children, newPath); + } + } + } + + traverse(tree); + return bookmarks; +} + +// Get visit count for a URL +async function getVisitCount(url) { + try { + const visits = await browser.history.getVisits({ url }); + return visits.length; + } catch (e) { + return 0; + } +} + +// Get forgotten bookmarks (low visit count, old enough) +async function getForgottenBookmarks() { + const settings = await getSettings(); + const bookmarks = await getAllBookmarks(settings.excludedFolders); + + const now = Date.now(); + const minAgeMs = settings.minAgeDays * 24 * 60 * 60 * 1000; + + // Filter by age and get visit counts + const candidates = []; + + for (const bookmark of bookmarks) { + // Skip if too new + if (bookmark.dateAdded && now - bookmark.dateAdded < minAgeMs) { + continue; + } + + // Skip non-http(s) URLs + if ( + !bookmark.url.startsWith("http://") && + !bookmark.url.startsWith("https://") + ) { + continue; + } + + const visitCount = await getVisitCount(bookmark.url); + + if (visitCount <= settings.maxVisitCount) { + // Check if dateAdded is valid (not corrupted/too old) + const hasValidDate = + bookmark.dateAdded && bookmark.dateAdded >= MIN_VALID_TIMESTAMP; + + candidates.push({ + ...bookmark, + visitCount, + daysSinceAdded: hasValidDate + ? Math.floor((now - bookmark.dateAdded) / (24 * 60 * 60 * 1000)) + : null, + }); + } + } + + // Shuffle and pick random ones + const shuffled = candidates.sort(() => Math.random() - 0.5); + return shuffled.slice(0, settings.numBookmarks); +} + +// Get all bookmark folders for settings UI +async function getBookmarkFolders() { + const tree = await browser.bookmarks.getTree(); + const folders = []; + + function traverse(nodes, depth = 0) { + for (const node of nodes) { + if (node.children) { + folders.push({ + id: node.id, + title: node.title || "Root", + depth, + }); + traverse(node.children, depth + 1); + } + } + } + + traverse(tree); + return folders; +} + +// Handle messages from popup/newtab/options +browser.runtime.onMessage.addListener((message, sender, sendResponse) => { + switch (message.action) { + case "getForgottenBookmarks": + return getForgottenBookmarks(); + + case "getBookmarkFolders": + return getBookmarkFolders(); + + case "getSettings": + return getSettings(); + + case "saveSettings": + return saveSettings(message.settings); + + case "deleteBookmark": + return browser.bookmarks.remove(message.bookmarkId); + + default: + return Promise.resolve(null); + } +}); diff --git a/icons/ember-48.svg b/icons/ember-48.svg new file mode 100644 index 0000000..058e861 --- /dev/null +++ b/icons/ember-48.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/icons/ember-96.svg b/icons/ember-96.svg new file mode 100644 index 0000000..0a8cfff --- /dev/null +++ b/icons/ember-96.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..df24ab9 --- /dev/null +++ b/manifest.json @@ -0,0 +1,33 @@ +{ + "manifest_version": 2, + "name": "Embermarks", + "version": "1.0.0", + "description": "Rediscover your forgotten bookmarks. Surface the ones you never visit.", + "author": "Bastian Gruber", + "homepage_url": "https://github.com/gruberb/embermarks", + + "icons": { + "48": "icons/ember-48.svg", + "96": "icons/ember-96.svg" + }, + + "permissions": ["bookmarks", "history", "storage"], + + "browser_action": { + "default_icon": { + "48": "icons/ember-48.svg" + }, + "default_title": "Embermarks", + "default_popup": "popup/popup.html" + }, + + "options_ui": { + "page": "options/options.html", + "browser_style": true + }, + + "background": { + "scripts": ["background.js"], + "persistent": false + } +} diff --git a/options/options.html b/options/options.html new file mode 100644 index 0000000..248332f --- /dev/null +++ b/options/options.html @@ -0,0 +1,285 @@ + + + + + + Embermarks Settings + + + +
+

+ Embermarks Settings +

+

+ Configure how forgotten bookmarks are discovered +

+ +
+

Display

+ +
+
+ Number of bookmarks to show + How many forgotten bookmarks to display at + once +
+ +
+
+ +
+

Forgotten Criteria

+ +
+
+ Maximum visit count + Bookmarks with this many visits or fewer are + considered "forgotten" +
+ +
+ +
+
+ Minimum age (days) + Only show bookmarks older than this many days +
+ +
+
+ +
+

Excluded Folders

+

+ Check folders you want to exclude from suggestions +

+
+
+ Loading folders... +
+
+
+ + +
✓ Settings saved!
+
+ + + + diff --git a/options/options.js b/options/options.js new file mode 100644 index 0000000..c2263a1 --- /dev/null +++ b/options/options.js @@ -0,0 +1,64 @@ +// Embermarks - Options Script + +document.addEventListener("DOMContentLoaded", async () => { + const numBookmarksInput = document.getElementById("numBookmarks"); + const maxVisitCountInput = document.getElementById("maxVisitCount"); + const minAgeDaysInput = document.getElementById("minAgeDays"); + const folderList = document.getElementById("folderList"); + const saveBtn = document.getElementById("saveBtn"); + const saveStatus = document.getElementById("saveStatus"); + + // Load current settings + const settings = await browser.runtime.sendMessage({ action: "getSettings" }); + + numBookmarksInput.value = settings.numBookmarks; + maxVisitCountInput.value = settings.maxVisitCount; + minAgeDaysInput.value = settings.minAgeDays; + + // Load folder list + const folders = await browser.runtime.sendMessage({ + action: "getBookmarkFolders", + }); + + folderList.innerHTML = ""; + + for (const folder of folders) { + const item = document.createElement("div"); + item.className = `folder-item folder-depth-${Math.min(folder.depth, 3)}`; + + const isExcluded = settings.excludedFolders.includes(folder.id); + + item.innerHTML = ` + + + `; + + folderList.appendChild(item); + } + + // Save settings + saveBtn.addEventListener("click", async () => { + const excludedFolders = []; + folderList.querySelectorAll("input:checked").forEach((checkbox) => { + excludedFolders.push(checkbox.value); + }); + + const newSettings = { + numBookmarks: parseInt(numBookmarksInput.value, 10), + maxVisitCount: parseInt(maxVisitCountInput.value, 10), + minAgeDays: parseInt(minAgeDaysInput.value, 10), + excludedFolders, + }; + + await browser.runtime.sendMessage({ + action: "saveSettings", + settings: newSettings, + }); + + // Show save confirmation + saveStatus.classList.add("visible"); + setTimeout(() => { + saveStatus.classList.remove("visible"); + }, 2000); + }); +}); diff --git a/popup/popup.html b/popup/popup.html new file mode 100644 index 0000000..86816bb --- /dev/null +++ b/popup/popup.html @@ -0,0 +1,46 @@ + + + + + Embermarks + + + + +
+

+ + Embermarks +

+
+ +
+
+
+ + + + + + + diff --git a/popup/popup.js b/popup/popup.js new file mode 100644 index 0000000..c79e629 --- /dev/null +++ b/popup/popup.js @@ -0,0 +1,14 @@ +// Embermarks - Popup Script + +document.addEventListener('DOMContentLoaded', async () => { + const container = document.getElementById('bookmarks'); + const refreshBtn = document.getElementById('refresh'); + + // Load bookmarks + await loadBookmarks(container); + + // Refresh button + refreshBtn.addEventListener('click', async () => { + await loadBookmarks(container); + }); +}); diff --git a/shared/styles.css b/shared/styles.css new file mode 100644 index 0000000..677bb00 --- /dev/null +++ b/shared/styles.css @@ -0,0 +1,182 @@ +/* Embermarks - Shared Styles */ + +:root { + --bg-primary: #2a2a2a; + --bg-card: #333333; + --bg-hover: #3a3a3a; + --text-primary: #e0e0e0; + --text-secondary: #888888; + --border-color: #444444; +} + +* { + box-sizing: border-box; + margin: 0; + padding: 0; +} + +body { + font-family: + -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; + background: var(--bg-primary); + color: var(--text-primary); + min-height: 100vh; +} + +/* Header */ +.header { + text-align: center; + padding: 1rem 1rem 0.5rem; +} + +.header h1 { + font-size: 1.1rem; + font-weight: 500; + color: var(--text-primary); +} + +.header p { + color: var(--text-secondary); + font-size: 0.8rem; +} + +/* Bookmark Cards Container */ +.bookmarks-container { + display: flex; + flex-direction: column; + gap: 2px; + padding: 0.5rem 0.75rem; +} + +/* Individual Bookmark Card */ +.bookmark-card { + display: flex; + align-items: center; + gap: 12px; + background: var(--bg-card); + padding: 10px 12px; + border-radius: 8px; + text-decoration: none; + color: inherit; + cursor: pointer; + transition: background 0.1s ease; +} + +.bookmark-card:hover { + background: var(--bg-hover); +} + +.bookmark-favicon { + width: 40px; + height: 40px; + border-radius: 8px; + background: var(--bg-hover); + flex-shrink: 0; + display: flex; + align-items: center; + justify-content: center; + font-size: 1rem; + color: var(--text-secondary); +} + +.bookmark-favicon img { + width: 24px; + height: 24px; + border-radius: 4px; +} + +.bookmark-info { + flex: 1; + min-width: 0; +} + +.bookmark-title { + font-size: 1rem; + font-weight: 500; + color: var(--text-primary); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + margin-bottom: 2px; +} + +.bookmark-meta { + font-size: 0.8rem; + color: var(--text-secondary); + margin-bottom: 2px; +} + +.bookmark-folder { + font-size: 0.75rem; + color: var(--text-secondary); + opacity: 0.7; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +/* Empty State */ +.empty-state { + text-align: center; + padding: 3rem 1rem; + color: var(--text-secondary); +} + +.empty-state .icon { + font-size: 1.75rem; + margin-bottom: 0.5rem; + opacity: 0.5; +} + +.empty-state h2 { + font-size: 1rem; + font-weight: 500; + margin-bottom: 0.25rem; + color: var(--text-secondary); +} + +.empty-state p { + font-size: 0.85rem; +} + +/* Loading State */ +.loading { + display: flex; + justify-content: center; + align-items: center; + padding: 3rem; + color: var(--text-secondary); + font-size: 0.9rem; +} + +.loading::after { + content: "Loading..."; +} + +/* Footer Actions */ +.footer-actions { + display: flex; + gap: 8px; + padding: 0.75rem; + border-top: 1px solid var(--border-color); +} + +.footer-btn { + flex: 1; + display: block; + text-align: center; + padding: 0.5rem 1rem; + background: var(--bg-card); + border: none; + border-radius: 6px; + color: var(--text-secondary); + text-decoration: none; + font-size: 0.85rem; + cursor: pointer; + transition: background 0.1s ease; +} + +.footer-btn:hover { + background: var(--bg-hover); + color: var(--text-primary); +} diff --git a/shared/ui.js b/shared/ui.js new file mode 100644 index 0000000..26bdb5b --- /dev/null +++ b/shared/ui.js @@ -0,0 +1,116 @@ +// Embermarks - Shared UI Logic + +// Get favicon URL for a bookmark +function getFaviconUrl(url) { + try { + const urlObj = new URL(url); + return `https://www.google.com/s2/favicons?domain=${urlObj.hostname}&sz=32`; + } catch { + return null; + } +} + +// Format days ago +function formatDaysAgo(days) { + if (days === null) return "Unknown"; + if (days === 0) return "Today"; + if (days === 1) return "Yesterday"; + if (days < 30) return `${days}d ago`; + if (days < 365) return `${Math.floor(days / 30)}mo ago`; + return `${Math.floor(days / 365)}y ago`; +} + +// Escape HTML +function escapeHtml(text) { + const div = document.createElement("div"); + div.textContent = text; + return div.innerHTML; +} + +// Create a bookmark card element +function createBookmarkCard(bookmark) { + const card = document.createElement("a"); + card.className = "bookmark-card"; + card.href = bookmark.url; + card.target = "_blank"; + card.rel = "noopener"; + + const faviconUrl = getFaviconUrl(bookmark.url); + + card.innerHTML = ` +
+ ${faviconUrl ? `` : "🔖"} +
+
+
${escapeHtml(bookmark.title)}
+
+ ${bookmark.visitCount} visit${bookmark.visitCount !== 1 ? "s" : ""} · Added ${formatDaysAgo(bookmark.daysSinceAdded)} +
+ ${bookmark.path ? `
${escapeHtml(bookmark.path)}
` : ""} +
+ `; + + return card; +} + +// Show empty state +function showEmptyState(container, reason = "none") { + const messages = { + none: { + icon: "✓", + title: "No forgotten bookmarks", + text: "You're on top of things!", + }, + allDismissed: { + icon: "✓", + title: "All caught up", + text: "Refresh to see more", + }, + }; + + const msg = messages[reason] || messages.none; + + container.innerHTML = ` +
+
${msg.icon}
+

${msg.title}

+

${msg.text}

+
+ `; +} + +// Show loading state +function showLoading(container) { + container.innerHTML = '
'; +} + +// Load and display bookmarks +async function loadBookmarks(container) { + showLoading(container); + + try { + const bookmarks = await browser.runtime.sendMessage({ + action: "getForgottenBookmarks", + }); + + container.innerHTML = ""; + + if (!bookmarks || bookmarks.length === 0) { + showEmptyState(container, "none"); + return; + } + + for (const bookmark of bookmarks) { + container.appendChild(createBookmarkCard(bookmark)); + } + } catch (error) { + console.error("Failed to load bookmarks:", error); + container.innerHTML = ` +
+
!
+

Oops

+

Failed to load bookmarks

+
+ `; + } +}