1
0
mirror of https://github.com/nileshtrivedi/better synced 2024-12-29 14:39:57 +01:00
migliori-alternative/toolbar/popup.js
2020-09-13 19:43:23 +05:30

40 lines
1.1 KiB
JavaScript

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();
});