-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (27 loc) · 922 Bytes
/
background.js
File metadata and controls
32 lines (27 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
chrome.action.onClicked.addListener((tab) => {
if (!tab.url) return;
const awsUrl = normalizeAwsUrl(tab.url);
if (awsUrl) {
copyToClipboard(awsUrl, tab.id);
} else {
alert("This extension only works on AWS Management Console pages.");
}
});
function normalizeAwsUrl(url) {
const awsPattern = /^(https:\/\/)([a-z0-9-]+\.)?([a-z0-9-]+)\.console\.aws\.amazon\.com(\/.*)?$/;
const match = url.match(awsPattern);
if (!match) return null; // AWSコンソールのURLでなければ処理しない
let baseUrl = match[1] + match[3] + ".console.aws.amazon.com" + (match[4] || "");
return baseUrl;
}
function copyToClipboard(text, tabId) {
chrome.scripting.executeScript({
target: { tabId: tabId },
func: (text) => {
navigator.clipboard.writeText(text).then(() => {
alert("Copied!");
}).catch(err => console.error("Copy Failed", err));
},
args: [text]
});
}