diff --git a/manifest.json b/manifest.json index 5751808..5e810c9 100644 --- a/manifest.json +++ b/manifest.json @@ -11,7 +11,7 @@ } }, "description": "This extension looks at your current URL, and recommends BETTER product/service alternatives via an in-page pop-up.", - "permissions": ["storage"], + "permissions": ["storage", "tabs"], "background": { "scripts": ["background.js"], "persistent": false @@ -27,5 +27,10 @@ "page": "options.html", "open_in_tab": false }, + "browser_action": { + "default_icon": "images/48.png", + "default_title": "Better", + "default_popup": "toolbar/popup.html" + }, "web_accessible_resources": ["defaultlist.json", "lists/*"] } diff --git a/toolbar/popup.html b/toolbar/popup.html new file mode 100644 index 0000000..5fab566 --- /dev/null +++ b/toolbar/popup.html @@ -0,0 +1,48 @@ + + + + + + + + + + +
+
+
+

Better

+

Suggest an alternative service for this URL

+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+

This will take you to a GitHub issue page

+
+
+
+ + + + + diff --git a/toolbar/popup.js b/toolbar/popup.js new file mode 100644 index 0000000..6ee40f3 --- /dev/null +++ b/toolbar/popup.js @@ -0,0 +1,39 @@ +let currentURL = document.getElementById("currentURL"); + +chrome.tabs.query( + { + active: true, + currentWindow: true, + }, + function (tabs) { + var tabURL = tabs[0].url; + currentURL.textContent = tabURL; + } +); + +let betterForm = document.getElementById("betterForm"); +let betterName = document.getElementById("betterName"); +let betterURL = document.getElementById("betterURL"); +let betterDescription = document.getElementById("betterDescription"); + +function encodeQueryData(data) { + const ret = []; + for (let d in data) + ret.push(encodeURIComponent(d) + "=" + encodeURIComponent(data[d])); + return ret.join("&"); +} + +var submitSuggestion = function () { + const data = { + title: `Suggestion: ${currentURL.textContent}`, + body: `${betterURL.value}\n${betterName.value}\n${betterDescription.value}`, + }; + const queryString = encodeQueryData(data); + let suggestionUrl = `https://github.com/nileshtrivedi/better/issues/new?${queryString}`; + chrome.tabs.create({ url: suggestionUrl }); +}; + +betterForm.addEventListener("submit", function (e) { + e.preventDefault(); + submitSuggestion(); +});