Skip to content

Commit

Permalink
Fix file viewer and port close-to-return feature to new file viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
kewisch committed Jun 15, 2020
1 parent 618321a commit 9f73c6e
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amoqueue-wx",
"version": "10.4.1",
"version": "10.4.2",
"author": "Philipp Kewisch <[email protected]>",
"homepage": "https://github.com/kewisch/amo-helper#readme",
"repository": {
Expand Down
12 changes: 9 additions & 3 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ const FILEBROWSER_URL = "https://{instance}/{product}/files/{action}/{versions}/

const API_BASE_URL = "https://reviewers.{instance}/api/v4/{path}";

const REVIEW_RE = /https:\/\/reviewers\.(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/reviewers\/review(|-listed|-unlisted|-content)\/(.*)/;
// 1 = addons.mozilla.org, 2 = en-US, 3 = -listed/-unlisted/-content, 4 = slug
const REVIEW_RE = /https:\/\/reviewers\.(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/(?:([^/]+)\/)?reviewers\/review(|-listed|-unlisted|-content)\/(.*)/;
const QUEUE_RE = /https:\/\/reviewers\.(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/reviewers\/queue\/(.*)/;
const ADDON_LINKS_RE = /https:\/\/(?:reviewers\.)?(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]*)\/(reviewers\/review(|-listed|-unlisted|-content)|admin\/addon\/manage|[^/]*\/addon|developers\/feed)\/([^/#?]*)(\/edit)?/;

// 1 = addons.mozilla.org, 2 = en-US, 3 = browse, 4 = id1, 5 = id2, 6 = filepath
const FILEBROWSER_RE = /https:\/\/reviewers\.(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/(?:firefox|thunderbird)\/files\/(compare|browse)\/(\d+)(?:\.\.\.)?(\d+)?\/(?:file\/([^#]*))?/;
const FILEBROWSER_RE = /https:\/\/(?:reviewers|code)\.(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/(?:(?:firefox|thunderbird)\/files\/)?(compare|browse)\/(?:\d+\/versions\/)?(\d+)(?:\.\.\.)?(\d+)?\/(?:(?:file\/|\?path=)([^#]*))?/;
const USER_RE = /https:\/\/(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/(?:firefox|thunderbird)\/user\/([^#/]*)/;
const USER_EDIT_RE = /https:\/\/(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/(?:firefox|thunderbird)\/users\/edit\/([^#/]*)/;
const CONTENT_REVIEW_RE = /https:\/\/reviewers\.(addons\.mozilla\.org|addons\.allizom\.org|addons-dev\.allizom\.org|addons\.thunderbird\.net)\/([^/]+)\/reviewers\/review-content\/(.*)/;
Expand Down Expand Up @@ -95,8 +96,13 @@ const AMO_HOSTS = [
"reviewers.addons.allizom.org",
"reviewers.addons-dev.allizom.org",

"code.addons.mozilla.org",
"code.addons.allizom.org",
"code.addons-dev.allizom.org",

"addons.thunderbird.net",
"reviewers.addons.thunderbird.net"
"reviewers.addons.thunderbird.net",
"code.addons.thunderbird.net"
];

const AMO_EDITORS_PATTERNS = [
Expand Down
17 changes: 16 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/* exported debounce, replacePattern */
/* exported debounce, replacePattern, waitForElement */

// https://davidwalsh.name/javascript-debounce-function
function debounce(func, wait) {
Expand All @@ -23,3 +23,18 @@ function debounce(func, wait) {
function replacePattern(str, replacements) {
return str.replace(/{([a-z]+)}/g, (match, key) => replacements[key] || "");
}

// I mainly need this for waiting for elements to appear in react. I'm not a fan of this code, but I
// haven't found out if there are any DOM events when the react app has finished rendering.
async function waitForElement(document, selector, timeout=0, max=Infinity) {
for (;max > 0; max--) {
let elem = document.querySelector(selector);
if (elem) {
return elem;
}

await new Promise(resolve => setTimeout(resolve, timeout));
}

return null;
}
2 changes: 1 addition & 1 deletion src/content/downloads/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// Make editors install link trigger a download
document.querySelector(".review-files, #review-files").addEventListener("click", (event) => {
if (event.target.classList.contains("editors-install")) {
if (event.target.classList.contains("reviewers-install")) {
let listbody = findParent(event.target, "listing-body");
let headerparts = listbody.previousElementSibling.firstElementChild.textContent.match(/Version ([^·]+)· ([^·]+)· (.*)/);
let version = headerparts[1].trim();
Expand Down
15 changes: 8 additions & 7 deletions src/content/tabclose/filebrowser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* Portions Copyright (C) Philipp Kewisch, 2017 */
* Portions Copyright (C) Philipp Kewisch, 2017-2020 */

document.querySelector("a.command[href*='reviewers/review']").addEventListener("click", (event) => {
let slug = event.target.getAttribute("href").split("/")[4];

browser.runtime.sendMessage({ action: "tabclose-backtoreview", slug: slug });
event.preventDefault();
event.stopPropagation();
waitForElement(document, "a[href*='reviewers/review']").then(reviewlink => {
reviewlink.addEventListener("click", (event) => {
let review = event.target.getAttribute("href").match(REVIEW_RE);
browser.runtime.sendMessage({ action: "tabclose-backtoreview", slug: review[4] });
event.preventDefault();
event.stopPropagation();
});
});
20 changes: 19 additions & 1 deletion src/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": "10.4.1",
"version": "10.4.2",
"applications": {
"gecko": {
"id": "@amoqueue",
Expand Down Expand Up @@ -111,6 +111,24 @@
],
"run_at": "document_end"
},
{
"matches": [
"https://code.addons.mozilla.org/*/browse/*",
"https://code.addons.mozilla.org/*/compare/*",
"https://code.addons.allizom.org/*/browse/*",
"https://code.addons.allizom.org/*/compare/*",
"https://code.addons-dev.allizom.org/*/browse/*",
"https://code.addons-dev.allizom.org/*/compare/*",
"https://code.addons.thunderbird.net/*/browse/*",
"https://code.addons.thunderbird.net/*/compare/*"
],
"js": [
"common/constants.js",
"common/helper.js",
"content/tabclose/filebrowser.js"
],
"run_at": "document_end"
},
{
"matches": [
"https://reviewers.addons.mozilla.org/*/reviewers/review/*",
Expand Down

0 comments on commit 9f73c6e

Please sign in to comment.