From 6e738dd8c7cad6f1de33564aedb54a3ae84a143d Mon Sep 17 00:00:00 2001 From: Andreas Molnar Date: Fri, 3 Jul 2026 23:16:45 +0000 Subject: [PATCH] Fix link routing and new tab settings --- newtab.html | 14 +----------- newtab.js | 17 ++++++-------- options.html | 27 ++++++++++++++++++---- options.js | 37 ++++++++++++++++++++++++------ popup.html | 25 +++++++++++++++----- popup.js | 64 +++++++++++++++++++++++----------------------------- 6 files changed, 107 insertions(+), 77 deletions(-) diff --git a/newtab.html b/newtab.html index 574ac75..97cda5b 100644 --- a/newtab.html +++ b/newtab.html @@ -40,15 +40,6 @@ left: 0; display: none; } - .toolbar { - position: fixed; - top: 18px; - right: 18px; - z-index: 3; - display: flex; - gap: 8px; - } - .toolbar button, .fallback button { border: 1px solid rgba(255,255,255,0.14); border-radius: 999px; @@ -80,12 +71,9 @@

Loading Dashwise...

-
- -

Dashwise is ready

-

This Dashwise server cannot be embedded in the new tab page. Use the search mode button to open it with search enabled.

+

This Dashwise server cannot be embedded in the new tab page.

diff --git a/newtab.js b/newtab.js index db539d6..a8d7566 100644 --- a/newtab.js +++ b/newtab.js @@ -1,5 +1,4 @@ let dashwiseUrl = 'https://www.google.com'; -let searchMode = false; function normalizeUrl(url) { if (!url) return dashwiseUrl; @@ -32,20 +31,18 @@ function loadFrame(url) { }, 5000); } -function toggleSearchMode() { - searchMode = !searchMode; - document.getElementById('search-toggle').textContent = searchMode ? 'Exit search mode' : 'Search mode'; - loadFrame(setSearchMode(dashwiseUrl, searchMode)); -} - function loadDashwise() { - chrome.storage.sync.get({ newTabUrl: 'https://www.google.com' }, (items) => { + chrome.storage.sync.get({ replaceNewTab: true, newTabUrl: 'https://www.google.com', newTabOpenSearch: false }, (items) => { + if (!items.replaceNewTab) { + document.body.classList.add('frame-failed'); + document.getElementById('fallback-message').textContent = 'Dashwise new tab replacement is disabled in extension settings.'; + return; + } dashwiseUrl = normalizeUrl(items.newTabUrl); - loadFrame(setSearchMode(dashwiseUrl, searchMode)); + loadFrame(setSearchMode(dashwiseUrl, !!items.newTabOpenSearch)); }); } document.addEventListener('DOMContentLoaded', () => { - document.getElementById('search-toggle').addEventListener('click', toggleSearchMode); loadDashwise(); }); diff --git a/options.html b/options.html index b048018..2ccc3c4 100644 --- a/options.html +++ b/options.html @@ -23,7 +23,7 @@ letter-spacing: 0.5px; margin-bottom: 4px; } - input { + input, select { width: 100%; padding: 10px 12px; background: rgba(255,255,255,0.04); @@ -33,7 +33,8 @@ font-size: 14px; outline: none; } - input:focus { border-color: #6c5ce7; } + input[type="checkbox"] { width: auto; } + input:focus, select:focus { border-color: #6c5ce7; } .btn { border: none; border-radius: 8px; @@ -54,10 +55,26 @@

Dashwise Settings

- - +
- +
+
+ + +
+
+ +
+
+

diff --git a/options.js b/options.js index 1867d09..31b2897 100644 --- a/options.js +++ b/options.js @@ -1,16 +1,38 @@ (function () { + function buildPageUrl(page, baseUrl) { + const root = (baseUrl || '').replace(/\/+$/, ''); + return page && page !== 'home' ? root + '/' + page.replace(/^\/+/, '') : root; + } + + function updateNewTabOptionsVisibility() { + document.getElementById('new-tab-options').style.display = document.getElementById('replace-new-tab').checked ? 'block' : 'none'; + } + function saveOptions() { - const url = document.getElementById('new-tab-url').value; - chrome.storage.sync.set({ newTabUrl: url }, () => { - const status = document.getElementById('status'); - status.textContent = 'Settings saved.'; - setTimeout(() => { status.textContent = ''; }, 2000); + const replaceNewTab = document.getElementById('replace-new-tab').checked; + const newTabPage = document.getElementById('new-tab-page').value || 'home'; + const newTabOpenSearch = document.getElementById('new-tab-open-search').checked; + + chrome.storage.local.get({ dashwiseBaseUrl: '' }, (auth) => { + chrome.storage.sync.set({ + replaceNewTab, + newTabPage, + newTabOpenSearch, + newTabUrl: buildPageUrl(newTabPage, auth.dashwiseBaseUrl), + }, () => { + const status = document.getElementById('status'); + status.textContent = 'Settings saved.'; + setTimeout(() => { status.textContent = ''; }, 2000); + }); }); } function restoreOptions() { - chrome.storage.sync.get({ newTabUrl: 'https://www.google.com' }, (items) => { - document.getElementById('new-tab-url').value = items.newTabUrl; + chrome.storage.sync.get({ replaceNewTab: true, newTabPage: 'home', newTabOpenSearch: false }, (items) => { + document.getElementById('replace-new-tab').checked = !!items.replaceNewTab; + document.getElementById('new-tab-page').value = items.newTabPage || 'home'; + document.getElementById('new-tab-open-search').checked = !!items.newTabOpenSearch; + updateNewTabOptionsVisibility(); }); } @@ -24,6 +46,7 @@ document.addEventListener('DOMContentLoaded', () => { restoreOptions(); + document.getElementById('replace-new-tab').addEventListener('change', updateNewTabOptionsVisibility); document.getElementById('save').addEventListener('click', saveOptions); document.getElementById('logout-btn').addEventListener('click', handleLogout); }); diff --git a/popup.html b/popup.html index 20af78f..43f7120 100644 --- a/popup.html +++ b/popup.html @@ -314,15 +314,12 @@ Add to Links -
- - Save to Read Later -
Generate QR Code
+
@@ -340,8 +337,24 @@

Settings

- - + +
+
+
+ + +
+
+ +
diff --git a/popup.js b/popup.js index b02c1f0..cbdf323 100644 --- a/popup.js +++ b/popup.js @@ -179,31 +179,6 @@ } } - async function saveReadLater() { - const tab = await getActiveTab(); - if (!tab || !tab.url) { showToast('No active tab'); return; } - - const item = { - title: tab.title || tab.url, - url: tab.url, - savedAt: new Date().toISOString(), - }; - - try { - await apiFetch('/links/items', { - method: 'POST', - body: JSON.stringify({ title: item.title, url: item.url, tags: ['read-later'] }), - }); - showToast('Saved to read later'); - } catch (err) { - const existing = await storageGet({ dashwiseReadLater: [] }); - const items = existing.dashwiseReadLater.filter((saved) => saved.url !== item.url); - items.unshift(item); - await storageSet({ dashwiseReadLater: items.slice(0, 250) }); - showToast('Saved locally for read later'); - } - } - // ---- Add Link Screen ---- let addLinkTab = null; @@ -317,7 +292,7 @@ const payload = { title: name, url: url }; if (icon) payload.iconUrl = icon; - if (collection) payload.linkGroup = collection; + if (collection) payload.collection = collection; if (tagsRaw) payload.tags = tagsRaw.split(',').map((t) => t.trim()).filter(Boolean); console.log('[Dashwise] submit payload:', JSON.stringify(payload)); @@ -356,19 +331,36 @@ function generateQR() { getActiveTab().then((tab) => { const url = tab ? encodeURIComponent(tab.url) : ''; - chrome.tabs.create({ url: 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + url }); + const preview = document.getElementById('qr-preview'); + if (!url) { showToast('No active tab'); return; } + preview.style.display = 'block'; + preview.innerHTML = 'QR code'; }); } // ---- Settings ---- - async function loadNewTabUrl() { - const items = await syncGet({ newTabUrl: 'https://www.google.com' }); - document.getElementById('new-tab-url').value = items.newTabUrl; + function buildPageUrl(page) { + const root = baseUrl.replace(/\/+$/, ''); + return page && page !== 'home' ? root + '/' + page.replace(/^\/+/, '') : root; + } + + function updateNewTabOptionsVisibility() { + document.getElementById('new-tab-options').style.display = document.getElementById('replace-new-tab').checked ? 'block' : 'none'; + } + + async function loadNewTabSettings() { + const items = await syncGet({ replaceNewTab: true, newTabPage: 'home', newTabOpenSearch: false }); + document.getElementById('replace-new-tab').checked = !!items.replaceNewTab; + document.getElementById('new-tab-page').value = items.newTabPage || 'home'; + document.getElementById('new-tab-open-search').checked = !!items.newTabOpenSearch; + updateNewTabOptionsVisibility(); } - async function saveNewTabUrl() { - const url = document.getElementById('new-tab-url').value.trim(); - await syncSet({ newTabUrl: url || 'https://www.google.com' }); + async function saveNewTabSettings() { + const replaceNewTab = document.getElementById('replace-new-tab').checked; + const newTabPage = document.getElementById('new-tab-page').value || 'home'; + const newTabOpenSearch = document.getElementById('new-tab-open-search').checked; + await syncSet({ replaceNewTab, newTabPage, newTabOpenSearch, newTabUrl: buildPageUrl(newTabPage) }); const status = document.getElementById('settings-status'); status.textContent = 'Saved'; status.style.color = '#2ecc71'; @@ -395,18 +387,18 @@ document.getElementById('login-btn').addEventListener('click', handleLogin); document.getElementById('settings-btn').addEventListener('click', () => { - loadNewTabUrl(); + loadNewTabSettings(); showScreen('settings'); }); document.getElementById('settings-back').addEventListener('click', () => { showScreen('main'); }); - document.getElementById('save-url-btn').addEventListener('click', saveNewTabUrl); + document.getElementById('replace-new-tab').addEventListener('change', updateNewTabOptionsVisibility); + document.getElementById('save-url-btn').addEventListener('click', saveNewTabSettings); document.getElementById('logout-btn').addEventListener('click', handleLogout); document.getElementById('action-home-link').addEventListener('click', addToHomeLinks); document.getElementById('action-add-link').addEventListener('click', openAddLink); - document.getElementById('action-read-later').addEventListener('click', saveReadLater); document.getElementById('action-qr').addEventListener('click', generateQR); document.getElementById('add-link-back').addEventListener('click', closeAddLink);