diff --git a/package.json b/package.json index adad037..554d8fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "amoqueue-wx", - "version": "10.4.5", + "version": "10.4.6", "author": "Philipp Kewisch ", "homepage": "https://github.com/kewisch/amo-helper#readme", "repository": { diff --git a/src/background/blocklist.js b/src/background/blocklist.js index 75b2a42..2b2b805 100644 --- a/src/background/blocklist.js +++ b/src/background/blocklist.js @@ -3,222 +3,59 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. * Portions Copyright (C) Philipp Kewisch, 2019 */ -let gBlocklist = []; -let gGatherGuids = []; - -/** - * This is taken from addons-server and should be rewritten to be pretty and accurate - * Copyright (c) 2010 - 2019, Mozilla Corporation - * All rights reserved. - */ -/* eslint-disable */ -var VersionCompare = { - /** - * Mozilla-style version numbers comparison in Javascript - * (JS-translated version of PHP versioncompare component) - * @return -1: ab - */ - compareVersions: function(a, b) { - var al = a.split("."), - bl = b.split("."), - ap, bp, r, i; - for (i=0; i bn) { - return 1; - } - return 0; - }, - - /** - * helper function: compare string version parts - */ - strcmp: function(as,bs) { - if (as == bs) { - return 0; - } - // any string comes *before* the empty string - if (as === "") { - return 1; - } - if (bs === "") { - return -1; - } - // normal string comparison for non-empty strings (like strcmp) - if (as < bs) { - return -1; - } else if(as > bs) { - return 1; - } else { - return 0; - } - } -}; -/* eslint-enable */ - -async function checkBlocklist(guid, version) { - function verifyVersionRange(entry) { - for (let range of entry.versionRange) { - if (VersionCompare.compareVersions(version, range.minVersion) > 0 && - (range.maxVersion == "*" || VersionCompare.compareVersions(version, range.maxVersion) < 0)) { - return { severity: range.severity == 3 ? "hard" : "soft" }; - } - } - - return null; - } +let gGatherGuids = new Set(); +async function fileBlocklistBug(guid, name, tabIndex) { + gGatherGuids.push(guid); - for (let entry of gBlocklist) { - let found = null; - if (entry.guid.startsWith("/")) { - let re = new RegExp(entry.guid.substring(1, entry.guid.length - 1)); - if (re.test(guid)) { - found = entry; - } - } else if (entry.guid == guid) { - found = entry; - } + let guids = [...gGatherGuids].join("\n"); - if (found) { - let result = verifyVersionRange(entry); - if (result) { - result.id = entry.id; - result.bug = entry.details.bug; - result.created = entry.details.created || new Date(entry.last_modified).toISOString(); - result.reason = entry.details.why; - return result; - } - } - } - - return null; -} + let addfile = await getStoragePreference("blocklist-addfile"); -async function downloadBlocklist() { - let resp = await fetch("https://firefox.settings.services.mozilla.com/v1/buckets/blocklists/collections/addons/records"); - let json = await resp.json(); + if (addfile) { + let tab = await browser.tabs.create({ + url: "http://bugzilla.mozilla.org/form.blocklist", + index: tabIndex + 1 + }); - if (json && json.data && Array.isArray(json.data)) { - gBlocklist = json.data; + await browser.tabs.executeScript(tab.id, { + code: ` + document.getElementById("blocklist_guids").value = ${JSON.stringify(guids)}; + document.getElementById("blocklist_name").value = ${JSON.stringify(name)}; + document.getElementById("blocklist_reason").focus(); + ` + }); } else { - console.error("Error loading blocklist"); + let params = new URLSearchParams({ guids: guids }); + browser.tabs.create({ + url: "https://addons-internal.prod.mozaws.net/en-US/admin/models/blocklist/blocklistsubmission/add/?" + params, + index: tabIndex + 1 + }); } -} - -async function fileBlocklistBug(guid, name) { - gGatherGuids.push(guid); - - let guids = [...new Set(gGatherGuids.filter(Boolean))].join("\n"); - let tab = await browser.tabs.create({ url: "http://bugzilla.mozilla.org/form.blocklist" }); - await browser.tabs.executeScript(tab.id, { - code: ` - document.getElementById("blocklist_guids").value = ${JSON.stringify(guids)}; - document.getElementById("blocklist_name").value = ${JSON.stringify(name)}; - document.getElementById("blocklist_reason").focus(); - ` - }); - - gGatherGuids = []; + gGatherGuids = new Set(); } async function gatherBlocklistBug(guid) { - gGatherGuids.push(guid); -} - -browser.alarms.create("blocklist", { periodInMinutes: 720 }); - -browser.alarms.onAlarm.addListener((alarm) => { - if (alarm.name != "blocklist") { - return; + if (guid) { + gGatherGuids.add(guid); } - downloadBlocklist(); -}); +} browser.runtime.onMessage.addListener((data, sender) => { if (data.action != "blocklist") { return undefined; } - if (data.method == "check") { - return checkBlocklist(data.guid, data.version); - } else if (data.method == "refresh") { - return downloadBlocklist(); - } else if (data.method == "file") { - return fileBlocklistBug(data.guid, data.name); + console.log(data); + + if (data.method == "file") { + return fileBlocklistBug(data.guid, data.name, sender.tab.index); } else if (data.method == "gather") { return gatherBlocklistBug(data.guid); + } else if (data.method == "get") { + return Promise.resolve([...gGatherGuids]); } return null; }); - -// Initial download -downloadBlocklist(); diff --git a/src/common/preferences.js b/src/common/preferences.js index f2b254d..057ef2c 100644 --- a/src/common/preferences.js +++ b/src/common/preferences.js @@ -53,7 +53,8 @@ const DEFAULT_PREFERENCES = { "tinderbar-approve-text": "", "tinderbar-preload-tabs": 3, "filewindow-enabled": false, - "filewindow-exclusive": false + "filewindow-exclusive": false, + "blocklist-addfile": false }; const HIDDEN_PREFERENCES = { diff --git a/src/content/queueinfo/review.js b/src/content/queueinfo/review.js index feb773f..6b8c10c 100644 --- a/src/content/queueinfo/review.js +++ b/src/content/queueinfo/review.js @@ -159,6 +159,7 @@ function getInfo(doc) { let versions = Array.from(doc.querySelectorAll(".review-files .listing-body, #review-files .listing-body")).map((listbody, idx) => { let headerparts = listbody.previousElementSibling.firstElementChild.textContent.match(/Version ([^·]+)· ([^·]+)· (.*)/); + let blocked = !!listbody.previousElementSibling.querySelector(".blocked-version"); let submissiondate = floatingtime(headerparts[2].trim(), true); let hasAutoApproval = false; let hasConfirmApproval = false; @@ -218,6 +219,7 @@ function getInfo(doc) { version: headerparts[1].trim(), date: submissiondate, status: status, + blocked: blocked, installurl: installanchor ? (new URL(installanchor.getAttribute("href"), location.href)).href : null, sourceurl: sourceanchor ? (new URL(sourceanchor.getAttribute("href"), location.href)).href : null, @@ -284,29 +286,8 @@ async function updateSize(info) { // Check the blocklist let lastVersion = info.versions[info.latest_idx]; - let blocked = await browser.runtime.sendMessage({ action: "blocklist", method: "check", guid: info.guid, version: lastVersion ? lastVersion.version : "0" }); - if (blocked) { - document.getElementById("main-wrapper").classList.add("amoqueue-striped-background", "amoqueue-blocklisted-" + blocked.severity); - - let bugspan = document.createElement("span"); - - let buglink = bugspan.appendChild(document.createElement("a")); - buglink.href = blocked.bug; - buglink.target = "_blank"; - buglink.textContent = blocked.bug.replace("https://bugzilla.mozilla.org/show_bug.cgi?id=", "bug "); - - - bugspan.appendChild(document.createTextNode(` on ${blocked.created.substr(0, 10)} (kinto `)); - console.log(blocked); - - let kintolink = bugspan.appendChild(document.createElement("a")); - kintolink.href = `https://settings-writer.prod.mozaws.net/v1/admin/#/buckets/staging/collections/addons/records/${blocked.id}/attributes`; - kintolink.target = "_blank"; - kintolink.textContent = blocked.id; - - bugspan.appendChild(document.createTextNode(")")); - - createSummaryRow("amoqueue-blocklist-bug", "Blocklisted", [bugspan, blocked.reason]); + if (lastVersion?.blocked) { + document.getElementById("main-wrapper").classList.add("amoqueue-striped-background", "amoqueue-blocklisted"); } await browser.runtime.sendMessage({ action: "infostorage", op: "set", storage: "slug", keys: { ["slugInfo." + info.slug]: info.id } }); diff --git a/src/content/reviewinfo/review.css b/src/content/reviewinfo/review.css index d844ffd..f1c1ff6 100644 --- a/src/content/reviewinfo/review.css +++ b/src/content/reviewinfo/review.css @@ -62,12 +62,9 @@ margin-bottom: 2em; } -#main-wrapper.amoqueue-blocklisted-hard { +#main-wrapper.amoqueue-blocklisted { background: repeating-linear-gradient(45deg, #fff, #fff 10px, #fbd4dc 10px, #fbd4dc 20px); } -#main-wrapper.amoqueue-blocklisted-soft { - background: repeating-linear-gradient(45deg, #fff, #fff 10px, #f2eca2 10px, #f2eca2 20px); -} #main-wrapper.amoqueue-blocklisted #addon { padding: 10px; diff --git a/src/content/reviewinfo/review.js b/src/content/reviewinfo/review.js index 67b68e1..7362f6f 100644 --- a/src/content/reviewinfo/review.js +++ b/src/content/reviewinfo/review.js @@ -50,6 +50,21 @@ function markVIP() { } function addBlocklistButton() { + function updateSize() { + browser.runtime.sendMessage({ + action: "blocklist", + method: "get" + }).then((guids) => { + if (guids.length == 0) { + button.textContent = "Block add-on"; + button.title = ""; + } else { + button.textContent = `Block ${count + 1} add-on(s)`; + button.title = guids.join("\n"); + } + }); + } + let area = document.querySelector("#extra-review-actions > .more-actions-inner > ul"); if (!area) { // This doesn't exist on delete add-ons pages @@ -67,32 +82,29 @@ function addBlocklistButton() { area = div.appendChild(document.createElement("ul")); } - let button = document.createElement("button"); - button.id = "amoqueue_blocklist_addon"; - button.type = "button"; - button.textContent = "File Blocklisting Bug"; - - button.addEventListener("click", (event) => { - browser.runtime.sendMessage({ - action: "blocklist", - method: event.ctrlKey || event.metaKey ? "gather" : "file", - guid: document.querySelector(".addon-guid > td").textContent, - name: document.title.split(" – ")[0], + let button = document.getElementById("block_addon"); + if (button) { + button.addEventListener("click", (event) => { + browser.runtime.sendMessage({ + action: "blocklist", + method: event.ctrlKey || event.metaKey ? "gather" : "file", + guid: document.querySelector(".addon-guid > td").textContent, + name: document.title.split(" – ")[0], + }).then(updateSize); + event.preventDefault(); }); - }); - document.addEventListener("keydown", (event) => { - if (event.key == "Control" || event.key == "Meta") { - button.textContent = "Gather ID for Blocklisting"; - } - }); - document.addEventListener("keyup", (event) => { - if (event.key == "Control" || event.key == "Meta") { - button.textContent = "File Blocklisting Bug"; - } - }); - - area.appendChild(button); + document.addEventListener("keydown", (event) => { + if (event.key == "Control" || event.key == "Meta") { + button.textContent = "Gather ID for Blocklisting"; + } + }); + document.addEventListener("keyup", (event) => { + if (event.key == "Control" || event.key == "Meta") { + updateSize(); + } + }); + } } function addScrollToButtons() { diff --git a/src/manifest.json b/src/manifest.json index 929e388..39e2b50 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "AMO Review Helper", "short_name": "AMO Helper", - "version": "10.4.5", + "version": "10.4.6", "applications": { "gecko": { "id": "@amoqueue", @@ -38,7 +38,6 @@ "https://addons.cdn.mozilla.net/*", "https://api.cognitive.microsoft.com/*", "https://api.microsofttranslator.com/*", - "https://firefox.settings.services.mozilla.com/*/buckets/blocklists/collections/addons/records", "https://bugzilla.mozilla.org/form.blocklist" ], "options_ui": { diff --git a/src/options/options.html b/src/options/options.html index d4549be..7f75248 100644 --- a/src/options/options.html +++ b/src/options/options.html @@ -174,11 +174,10 @@

Review Page Tweaks

Automatically redirect to unlisted page if listed is empty - -
- - -
+ diff --git a/src/options/options.js b/src/options/options.js index 7053b12..9c6063e 100644 --- a/src/options/options.js +++ b/src/options/options.js @@ -49,7 +49,6 @@ function setup_listeners() { setup_canned_listeners(); setup_filewindow_listeners(); setup_import_export_listeners(); - setup_blocklist_listeners(); } /* --- canned responses --- */ @@ -254,32 +253,6 @@ function setup_import_export_listeners() { }); } -function setup_blocklist_listeners() { - let blocklistButton = document.getElementById("reload-blocklist-button"); - let blocklistState = document.getElementById("blocklist-state"); - blocklistButton.addEventListener("click", async (event) => { - blocklistState.classList.remove("complete"); - blocklistState.classList.remove("error"); - blocklistButton.setAttribute("disabled", "true"); - - try { - blocklistState.classList.add("loading"); - await browser.runtime.sendMessage({ action: "blocklist", method: "refresh" }); - blocklistState.classList.add("complete"); - } catch (e) { - blocklistState.classList.add("error"); - } - - blocklistState.classList.remove("loading"); - blocklistButton.removeAttribute("disabled"); - - setTimeout(() => { - blocklistState.classList.remove("error"); - blocklistState.classList.remove("complete"); - }, 3000); - }); -} - document.addEventListener("DOMContentLoaded", setup_listeners); document.addEventListener("DOMContentLoaded", restore_options); document.body.addEventListener("change", change_options);