diff --git a/app/pages/popup.html b/app/pages/popup.html index c20a5b2..aaa7c9f 100644 --- a/app/pages/popup.html +++ b/app/pages/popup.html @@ -2,13 +2,10 @@ - Popup + SPDX-License-Diff - -

Popup

- - + diff --git a/app/scripts/background.js b/app/scripts/background.js index 1f99596..3926147 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -211,9 +211,11 @@ function handleMessage(request, sender, sendResponse) { ); browser.tabs.create({ url: newLicenseUrl }).then( () => { - browser.tabs.executeScript({ - code: injectCode, - }); + setTimeout(() => { + browser.tabs.executeScript({ + code: injectCode, + }); + }, 250); }, (error) => { console.log(`Error injecting code: ${error}`); @@ -221,6 +223,22 @@ function handleMessage(request, sender, sendResponse) { ); break; } + case "newTab": { + activeTabId = sender.tab.id; + console.log("tab %s: Creating new tab with %s:", activeTabId, request); + browser.tabs.create({ url: "/pages/popup.html" }).then( + (tab) => { + console.log("Tab %s created", tab.id); + setTimeout(() => { + chrome.tabs.sendMessage(tab.id, request); + }, 250); + }, + (error) => { + console.log(`Error starting new tab: ${error}`); + } + ); + break; + } default: // console.log("Proxying to worker", request); // chrome.tabs.sendMessage(activeTab.id, request); diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 1f801c9..37ab2bc 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -115,6 +115,20 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { updateBubbleText("Displaying diff"); } break; + case "newTab": + diffs = request.diffs; + spdxid = request.spdxid; + spdx = request.spdx; + console.log("Received newTab request", diffs, spdxid, spdx); + updateProgressBar(1, 1, false); + addSelectFormFromArray( + "licenses", + spdx, + options.showBest === 0 && spdx ? spdx.length : options.showBest, + options.minpercentage + ); + displayDiff(diffs[spdxid].html, diffs[spdxid].time); + break; case "alive?": console.log("Received ping request"); sendResponse({ status: "1" }); @@ -309,6 +323,7 @@ function showFilters(form) { if (document.getElementById("filters")) { return; } + if (window.location.href.endsWith("/popup.html")) return; var div = form.appendChild(document.createElement("div")); div.id = "filters"; var label = form.appendChild(document.createElement("label")); @@ -403,6 +418,7 @@ function addSelectFormFromArray(id, arr, number = arr.length, minimum = 0) { } } createNewLicenseButton(form); + createNewTabButton(form, option.value); } // Display helper functions for modifying the DOM @@ -450,8 +466,9 @@ document.addEventListener( // Add new license button. function createNewLicenseButton(form) { if ($("#newLicenseButton").length) return; + if (window.location.href.endsWith("/popup.html")) return; var button = document.createElement("button"); - button.innerHTML = "Submit selection as new license"; + button.innerHTML = "Submit new license"; button.type = "button"; button.id = "newLicenseButton"; form.appendChild(button); @@ -465,6 +482,27 @@ function createNewLicenseButton(form) { }); } +// Add new tab button. +function createNewTabButton(form, spdxid) { + if ($("#newTabButton").length) return; + if (window.location.href.endsWith("/popup.html")) return; + var button = document.createElement("button"); + button.innerHTML = + ''; + button.type = "button"; + button.id = "newTabButton"; + form.appendChild(button); + form.appendChild(document.createElement("br")); + button.addEventListener("click", function () { + chrome.runtime.sendMessage({ + command: "newTab", + diffs: diffs, + spdxid: spdxid, + spdx: spdx, + }); + }); +} + // Move that bubble to the appropriate location. function renderBubble(mouseX, mouseY, selection) { updateProgressBar(-1, 1, true); diff --git a/app/scripts/popup.js b/app/scripts/popup.js deleted file mode 100644 index 99e625f..0000000 --- a/app/scripts/popup.js +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-FileCopyrightText: Alan D. Tse -// SPDX-License-Identifier: (GPL-3.0-or-later AND Apache-2.0) -// Enable chromereload by uncommenting this line: -// import 'chromereload/devonly' - -console.log(`'Allo 'Allo! Popup`); diff --git a/app/styles/contentscript.css b/app/styles/contentscript.css index a1736e9..8f63701 100644 --- a/app/styles/contentscript.css +++ b/app/styles/contentscript.css @@ -13,3 +13,9 @@ progress { progress:after { content: attr(value) "/" attr(max); } + +#newTabButton { + position:absolute; + top:0; + right:0; +} \ No newline at end of file diff --git a/app/styles/popup.css b/app/styles/popup.css new file mode 100644 index 0000000..eba51f2 --- /dev/null +++ b/app/styles/popup.css @@ -0,0 +1,3 @@ +body { + font-size: 100%; +} \ No newline at end of file