From 73ef3a90c753abdff3f31e3ccf6a484dc8848aab Mon Sep 17 00:00:00 2001 From: Solomon Kinard Date: Tue, 21 Jun 2022 18:51:28 -0700 Subject: [PATCH] Get the milestone when a merged Chromium Gerrit tab is active (#722) --- examples/milestones/manifest.json | 9 +++++++++ examples/milestones/popup.html | 1 + examples/milestones/popup.js | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 examples/milestones/manifest.json create mode 100644 examples/milestones/popup.html create mode 100644 examples/milestones/popup.js diff --git a/examples/milestones/manifest.json b/examples/milestones/manifest.json new file mode 100644 index 00000000..a273d2a7 --- /dev/null +++ b/examples/milestones/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "Milestones", + "version": "1.0", + "manifest_version": 3, + "action": {"default_popup": "popup.html"}, + "description": "Chromium Release Milestones", + "host_permissions": [ "https://crrie.com/" ], + "permissions": [ "activeTab" ] +} diff --git a/examples/milestones/popup.html b/examples/milestones/popup.html new file mode 100644 index 00000000..b08f3533 --- /dev/null +++ b/examples/milestones/popup.html @@ -0,0 +1 @@ + diff --git a/examples/milestones/popup.js b/examples/milestones/popup.js new file mode 100644 index 00000000..0c8997c0 --- /dev/null +++ b/examples/milestones/popup.js @@ -0,0 +1,21 @@ +chrome.tabs.query({active: true}).then(tabs => getMilestone(tabs)); + +function getMilestone(tabs) { + const div = document.createElement("div"); + document.body.appendChild(div); + const url = tabs[0].url; + const origin = 'https://chromium-review.googlesource.com'; + const search = `^${origin}/c/chromium/src/\\+/(\\d+)`; + const match = url.match(search); + if (match != undefined && match.length == 2) { + getMilestoneForRevid(match[1]).then((milestone) => + milestone != '' ? (div.innerText = `m${milestone}`) : window.close()); + } else { + window.close(); + } +} + +function getMilestoneForRevid(revid) { + return fetch(`https://crrie.com/c/?r=${revid}`) + .then((res) => res.text()); +}