Skip to content

Commit

Permalink
Example milestone cleanup (GoogleChrome#727)
Browse files Browse the repository at this point in the history
* Add README and screenshot
* Adjust variable name casing for clarity
* Add copyright headers
* Reformat with clang-format
* Adds the 'milestones' example to the index
* Clarify extension's name and description
  • Loading branch information
Simeon Vincent authored Jun 24, 2022
1 parent 73ef3a9 commit dcff87a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ Read more on [Getting Started](https://developer.chrome.com/extensions/getstarte
</ul>
</td>
</tr>
<tr>
<td style="vertical-align:top;">
Chromium Milestones<br>
<a href="examples/milestones"><code>examples/milestones</code></a>
</td>
<td style="vertical-align:top;">
<ul>
<li><a href="https://developer.chrome.com/docs/extensions/reference/action/#manifest">default_popup</a></li>
<li><a href="https://developer.chrome.com/docs/extensions/reference/tabs/#method-query">tabs.query</a></li>
</ul>
</td>
</tr>
<tr>
<td style="vertical-align:top;">
Cookie Clearer <br>
Expand Down
11 changes: 11 additions & 0 deletions examples/milestones/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Clicking this extension's action button while viewing a Chromium code review will open a small popup that shows what (if any) Chromium version the review was merged into. If the CR has not yet been merged or if the extension cannot find the version it was merged into, the action popup will automatically close itself.

# Demo

1. Install this extension
2. Visit https://chromium-review.googlesource.com/c/chromium/src/+/3635900
3. Click the extension's action icon

Once the extension retrieves the merged milestone information, it will appear in the extnesion's popup as shown below

![The extension's popup shows that this change request was merged in milestone 104](./screenshot.png)
4 changes: 2 additions & 2 deletions examples/milestones/manifest.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "Milestones",
"name": "Chromium Milestones",
"version": "1.0",
"manifest_version": 3,
"action": {"default_popup": "popup.html"},
"description": "Chromium Release Milestones",
"description": "Shows the Chromium release milestone a given code review was merged into.",
"host_permissions": [ "https://crrie.com/" ],
"permissions": [ "activeTab" ]
}
16 changes: 16 additions & 0 deletions examples/milestones/popup.html
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
<!DOCTYPE html>
<!--
Copyright 2022 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="popup.js"></script>
27 changes: 21 additions & 6 deletions examples/milestones/popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
chrome.tabs.query({active: true}).then(tabs => getMilestone(tabs));
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

chrome.tabs.query({active : true}).then(tabs => getMilestone(tabs));

function getMilestone(tabs) {
const div = document.createElement("div");
Expand All @@ -8,14 +22,15 @@ function getMilestone(tabs) {
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());
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());
async function getMilestoneForRevId(revId) {
const res = await fetch(`https://crrie.com/c/?r=${revId}`);
return await res.text();
}
Binary file added examples/milestones/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dcff87a

Please sign in to comment.