Skip to content

Commit

Permalink
feat: add fullscreen button
Browse files Browse the repository at this point in the history
This will open result in a new tab

Signed-off-by: Alan D. Tse <alandtse@gmail.com>
  • Loading branch information
alandtse committed Mar 3, 2021
1 parent 8830931 commit dcacd9d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
7 changes: 2 additions & 5 deletions app/pages/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
<html>
<head>
<meta charset="utf-8" />
<title>Popup</title>
<title>SPDX-License-Diff</title>
<link rel="stylesheet" type="text/css" href="../styles/popup.css">
</head>
<body>

<h1>Popup</h1>

<script src="../scripts/popup.js"></script>
<script src="../scripts/contentscript.js"></script>
</body>
</html>
24 changes: 21 additions & 3 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,34 @@ 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}`);
}
);
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);
Expand Down
40 changes: 39 additions & 1 deletion app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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 =
'<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M4.5 11H3v4h4v-1.5H4.5V11zM3 7h1.5V4.5H7V3H3v4zm10.5 6.5H11V15h4v-4h-1.5v2.5zM11 3v1.5h2.5V7H15V3h-4z"/></svg>';
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);
Expand Down
6 changes: 0 additions & 6 deletions app/scripts/popup.js

This file was deleted.

6 changes: 6 additions & 0 deletions app/styles/contentscript.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ progress {
progress:after {
content: attr(value) "/" attr(max);
}

#newTabButton {
position:absolute;
top:0;
right:0;
}
3 changes: 3 additions & 0 deletions app/styles/popup.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
font-size: 100%;
}

0 comments on commit dcacd9d

Please # to comment.