Skip to content

Commit

Permalink
Initial checkin of Query AMO ID
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaply committed Jun 26, 2020
1 parent 685f4c6 commit 23f5e69
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
16 changes: 16 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"manifest_version": 2,
"name": "Query AMO Addon ID",
"version": "0.1",
"browser_action": {
"default_title": "Click here",
"default_popup": "popup.html"
},
"permissions": ["tabs"],
"browser_specific_settings": {
"gecko": {
"id": "queryamoid@kaply.com",
"update_url": "https://raw.githubusercontent.com/mkaply/queryamoid/main/updates.json"
}
}
}
35 changes: 35 additions & 0 deletions extension/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: sans-serif;
}
#message {
display: none;
}
#clipboard {
position: absolute;
left: 0;
top:0;
opacity: 0;
}
button {
margin: 5px;
}
</style>
</head>
<body>
<div id="message"></div>
<div id="addon">
<div>
<span id="guid"></span><button id="copy_guid">Copy</button>
</div>
<div>
<span id="url"></span><button id="copy_url">Copy</button>
</div>
<input type="text" id="clipboard">
</div>
</body>
<script src="popup.js"></script>
</html>
44 changes: 44 additions & 0 deletions extension/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
browser.tabs.query({
active: true,
lastFocusedWindow: true
}).then(function(tabs) {
let url = new URL(tabs[0].url);
if (url.host != "addons.mozilla.org") {
showMessage("This extension only works on addons.mozilla.org.");
return;
}
let splitPath = url.pathname.split("/");
if (splitPath[3] != "addon") {
showMessage("This extension only works on addon pages.");
return;
}
let slug = splitPath[4];
fetch(`https://addons.mozilla.org/api/v4/addons/addon/${slug}/`)
.then((response) => {
return response.json();
})
.then((data) => {
document.getElementById("guid").textContent = data.guid;
document.getElementById("url").textContent = `https://addons.mozilla.org/firefox/downloads/latest/${slug}/latest.xpi`;
});})

document.getElementById("copy_guid").addEventListener("click", function() {
var copyText = document.getElementById("clipboard");
copyText.value = document.getElementById("guid").textContent;
copyText.select();
document.execCommand("copy");
});

document.getElementById("copy_url").addEventListener("click", function() {
var copyText = document.getElementById("clipboard");
copyText.value = document.getElementById("url").textContent;
copyText.select();
document.execCommand("copy");
});

function showMessage(message) {
let messageElement = document.getElementById("message");
messageElement.style.display = "block";
messageElement.textContent = message;
document.getElementById("addon").style.display = "none";
}
12 changes: 12 additions & 0 deletions updates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"addons": {
"queryamoid@kaply.com": {
"updates": [
{
"version": "0.1",
"update_link": "https://github.com/mkaply/queryamoid/releases/download/0.1/queryamoid-0.1.xpi"
}
]
}
}
}

0 comments on commit 23f5e69

Please sign in to comment.