diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..0b8023b --- /dev/null +++ b/build.ps1 @@ -0,0 +1,19 @@ +# Install deps +npm install + +# Build +npm run build + +# Check if --firefox argument was passed +if ($args[0] -eq "--firefox") { + # Copy to firefox/manifest.json + Write-Host "Built for Firefox..." + Copy-Item -Path "firefox/manifest.json" -Destination "dist/manifest.json" +} else { + # Copy to dist/manifest.json + Write-Host "Built for Chrom(ium)e..." + Copy-Item -Path "src/manifest.json" -Destination "dist/manifest.json" +} + +# Done (for now...) +Write-Host "Done! " diff --git a/src/manifest.json b/src/manifest.json index b4b3c46..3bef170 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -18,6 +18,9 @@ "page": "./src/pages/Options/options.html", "browser_style": false }, + "side_panel": { + "default_path": "./index.html" + }, "icons": { "16": "./16.png", "32": "./32.png", @@ -30,14 +33,16 @@ "tabs", "bookmarks", "commands", - "contextMenus" + "contextMenus", + "sidePanel" + ], "background": { "service_worker": "./background.js", "type": "module" }, "omnibox": { - "keyword": "lk" + "keyword": "lw" }, "host_permissions": [ "*://*/*" diff --git a/src/pages/Background/index.ts b/src/pages/Background/index.ts index 19da667..247d25a 100644 --- a/src/pages/Background/index.ts +++ b/src/pages/Background/index.ts @@ -12,6 +12,7 @@ import OnClickData = chrome.contextMenus.OnClickData; import OnInputEnteredDisposition = chrome.omnibox.OnInputEnteredDisposition; const browser = getBrowser(); +let configuration = null; // this js needs init function which initializes the configuration variable thus solving many lines in this file which repeadiatly uses getConfig() it might be better // This is the main functions that will be called when a bookmark is created, update or deleted // Won't work with axios xhr or something not supported by the browser @@ -236,10 +237,12 @@ browser.omnibox.onInputEntered.addListener(async (content: string, disposition: return; } + configuration = await getConfig(); // code line waiting to be replaced by nothing once global init function is done until then mae do with this + const isUrl = /^http(s)?:\/\//.test(content); const url = isUrl ? content - : `lk`; + : `${configuration.baseUrl}/search?q=${encodeURIComponent(content)}`; // This part was taken https://github.com/sissbruecker/linkding-extension/blob/master/src/background.js // Edge doesn't allow updating the New Tab Page (tested with version 117). // Trying to do so will throw: "Error: Cannot update NTP tab." @@ -267,3 +270,26 @@ browser.omnibox.onInputEntered.addListener(async (content: string, disposition: }); +// refresh for sidepanel on tab change +chrome.tabs.onUpdated.addListener((tabId, changeInfo) => { + // if (changeInfo.url) { + console.log("Tab URL changed:", changeInfo.url, " Tab ID:", tabId); + + // Reload the side panel if needed + chrome.sidePanel.setOptions({ path: "./index.html" }); + // } +}); + +// Listen for tab changes +chrome.tabs.onActivated.addListener(async (activeInfo) => { + console.log("Tab changed:", activeInfo); + + try { + await chrome.sidePanel.setOptions({ + path: "./index.html" + }); + console.log("Side panel reloaded."); + } catch (error) { + console.error("Failed to reload the side panel:", error); + } +}); \ No newline at end of file