Browse Source

add context menu option to open shaarli UI

Andrew Dolgov 2 months ago
parent
commit
49a71c7feb
2 changed files with 27 additions and 1 deletions
  1. 26 0
      js/background.js
  2. 1 1
      manifest.json

+ 26 - 0
js/background.js

@@ -1,6 +1,11 @@
 'use strict'
 
 function post_to_shaarli(url, title) {
+
+	// no point trying to share chrome://newtab etc
+	/* if (url.indexOf("chrome://") != -1)
+		return open_shaarli(); */
+
 	chrome.storage.sync.get('settings', (rv) => {
 		if (typeof rv.settings !== "undefined") {
 			const settings = rv.settings;
@@ -32,6 +37,21 @@ function post_to_shaarli(url, title) {
 	});
 }
 
+function open_shaarli() {
+	chrome.storage.sync.get('settings', (rv) => {
+		if (typeof rv.settings !== "undefined") {
+			const settings = rv.settings;
+
+			if (settings.url) {
+				chrome.tabs.create({url: settings.url });
+			}
+
+		} else {
+			alert("Please configure the extension first.");
+		}
+	});
+}
+
 function post_clicked_url(info/*, tab*/) {
 	const url = info["srcUrl"] ? info["srcUrl"] : info["linkUrl"];
 	post_to_shaarli(url, "");
@@ -44,3 +64,9 @@ chrome.browserAction.onClicked.addListener((tab) => {
 chrome.contextMenus.create({"title": "Save to Shaarli",
 	"contexts":[ "link" ],
 	"onclick": post_clicked_url});
+
+chrome.contextMenus.create({
+		title: "Open Shaarli",
+		contexts: ["browser_action"],
+		onclick: open_shaarli
+});

+ 1 - 1
manifest.json

@@ -19,5 +19,5 @@
 		"page": "options.html"
 	},
    "permissions": [ "contextMenus", "storage", "activeTab" ],
-   "version": "0.5"
+   "version": "0.6"
 }