Skip to content

Commit

Permalink
Add a browseraction menuitem that allows switching to the review page…
Browse files Browse the repository at this point in the history
… from anywhere with a slug
  • Loading branch information
kewisch committed Feb 1, 2017
1 parent 30d68b7 commit c875dbb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "AMO Review Helper",
"name": "amoqueue",
"version": "3.9.1",
"version": "4.0.0",
"description": "Enhancements to the AMO review experience",
"main": "shim/background.js",
"author": "Philipp Kewisch",
Expand Down
12 changes: 12 additions & 0 deletions webextension/background/browseraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ function setupQueueRefresh() {
});
}

function switchToReviewPage() {
let RE_ADDON_LINKS = /https:\/\/addons.mozilla.org\/([^\/]*)\/(editors\/review|admin\/addon\/manage|[^\/]*\/addon|developers\/feed)\/([^\/#?]*)(\/edit)?/;
chrome.tabs.query({ active: true, currentWindow: true }, ([tab, ...rest]) => {
let match = tab.url.match(RE_ADDON_LINKS);
if (match) {
chrome.tabs.update(tab.id, { url: "https://addons.mozilla.org/en-US/editors/review/" + match[3] });
}
});
}

// -- main --

chrome.alarms.onAlarm.addListener((alarm) => {
Expand All @@ -103,6 +113,8 @@ chrome.storage.onChanged.addListener((changes, area) => {
chrome.runtime.onMessage.addListener((data, sender, sendReply) => {
if (data.action == "popup-action-refreshcount") {
updateQueueNumbers().then(updateBadge);
} else if (data.action == "popup-action-gotoreview") {
switchToReviewPage();
}
});

Expand Down
2 changes: 2 additions & 0 deletions webextension/content/browseraction/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<li class="separator"></li>
<li><a href="#refreshcount">Refresh Queue Badge</a></li>
-->
<li id="page-action-separator" class="separator"></li>
<li id="page-action-gotoreview"><a href="#gotoreview">Switch to Review Page</a></li>
</ul>
<script type="application/javascript" src="popup.js"></script>
</body>
Expand Down
28 changes: 26 additions & 2 deletions webextension/content/browseraction/popup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
window.addEventListener("DOMContentLoaded", () => {
let menu = document.getElementById("menu");
function hideElement(node, value=true) {
if (value) {
node.setAttribute("hidden", "true");
} else {
node.removeAttribute("hidden");
}
}

function setupMenuClick() {
let menu = document.getElementById("menu");
menu.addEventListener("click", (event) => {
if (event.target.localName != "a") {
return;
Expand All @@ -17,4 +24,21 @@ window.addEventListener("DOMContentLoaded", () => {

promise.then(() => window.close());
});
}

function setupMenuState() {
// set up switch action
browser.tabs.query({ active: true, currentWindow: true }).then(([tab, ...rest]) => {
let RE_ADDON_LINKS = /https:\/\/addons.mozilla.org\/([^\/]*)\/(editors\/review|admin\/addon\/manage|[^\/]*\/addon|developers\/feed)\/([^\/#?]*)(\/edit)?/;
hideElement(document.getElementById("page-action-gotoreview"), !tab.url.match(RE_ADDON_LINKS));
}).then(() => {
// Remove the separator if there are no remaining actions
let separator = document.getElementById("page-action-separator");
hideElement(separator, !document.querySelector("#page-action-separator ~ li:not([hidden])"));
});
}

window.addEventListener("DOMContentLoaded", () => {
setupMenuClick();
setupMenuState();
});
2 changes: 1 addition & 1 deletion webextension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "AMO Review Helper",
"short_name": "AMO Helper",
"version": "3.9.1",
"version": "4.0.0",
"icons": {
"16": "images/addon.svg",
"32": "images/addon.svg",
Expand Down

0 comments on commit c875dbb

Please sign in to comment.