Skip to content

Commit

Permalink
update regions
Browse files Browse the repository at this point in the history
  • Loading branch information
bunjik committed Jun 3, 2023
1 parent aa137e1 commit a5ea0ce
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 53 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

customize aws console chrome-extension

- Ver 1.0.4
- support AWS Management Console update.
- applying region changes.

- Ver 1.0.3
- fix show label bug.

Expand Down
48 changes: 27 additions & 21 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,33 @@
"TOOLTIP_AccountName": { "message": "アカウント名の部分一致(or 正規表現)" },

"all_region": { "message": "全リージョン" },
"us_east_1": { "message": "米国東部(バージニア北部)" },
"us_east_2": { "message": "米国東部 (オハイオ)" },
"us_west_1": { "message": "米国西部 (北カリフォルニア)" },
"us_west_2": { "message": "米国西部 (オレゴン)" },
"af_south_1": { "message": "アフリカ (ケープタウン)" },
"ap_east_1": { "message": "アジアパシフィック (香港)" },
"ap_south_1": { "message": "アジアパシフィック (ムンバイ)" },
"ap_northeast_1": { "message": "アジアパシフィック (東京)" },
"ap_northeast_2": { "message": "アジアパシフィック (ソウル)" },
"ap_northeast_3": { "message": "アジアパシフィック (大阪)" },
"ap_southeast_1": { "message": "アジアパシフィック (シンガポール)" },
"ap_southeast_2": { "message": "アジアパシフィック (シドニー)" },
"ca_central_1": { "message": "カナダ (中部)" },
"us_east_1": { "message": "米国東部 (バージニア北部)"},
"us_west_1": { "message": "米国西部 (北カリフォルニア)"},
"us_west_2": { "message": "米国西部 (オレゴン)"},
"af_south_1": { "message": "アフリカ (ケープタウン)"},
"ap_east_1": { "message": "アジアパシフィック (香港)"},
"ap_south_2": { "message": "アジアパシフィック (ハイデラバード)"},
"ap_southeast_3": { "message": "アジアパシフィック (ジャカルタ)"},
"ap_southeast_4": { "message": "アジアパシフィック (メルボルン)"},
"ap_south_1": { "message": "アジアパシフィック (ムンバイ)"},
"ap_northeast_3": { "message": "アジアパシフィック (大阪)"},
"ap_northeast_2": { "message": "アジアパシフィック (ソウル)"},
"ap_southeast_1": { "message": "アジアパシフィック (シンガポール)"},
"ap_southeast_2": { "message": "アジアパシフィック (シドニー)"},
"ap_northeast_1": { "message": "アジアパシフィック (東京)"},
"ca_central_1": { "message": "カナダ (中部)"},
"eu_central_1": { "message": "欧州 (フランクフルト)"},
"eu_west_1": { "message": "欧州 (アイルランド)"},
"eu_west_2": { "message": "欧州 (ロンドン)"},
"eu_south_1": { "message": "ヨーロッパ (ミラノ)"},
"eu_west_3": { "message": "欧州 (パリ)"},
"eu_south_2": { "message": "欧州 (スペイン)"},
"eu_north_1": { "message": "欧州 (ストックホルム)"},
"eu_central_2": { "message": "欧州 (チューリッヒ)"},
"me_south_1": { "message": "中東 (バーレーン)"},
"me_central_1": { "message": "中東 (アラブ首長国連邦)"},
"sa_east_1": { "message": "南米 (サンパウロ)"},
"cn_north_1": { "message": "中国 (北京)" },
"cn_northwest_1": { "message": "中国 (寧夏)" },
"eu_central_1": { "message": "欧州 (フランクフルト)" },
"eu_west_1": { "message": "欧州 (アイルランド)" },
"eu_west_2": { "message": "欧州 (ロンドン)" },
"eu_west_3": { "message": "欧州 (パリ)" },
"eu_south_1": { "message": "ヨーロッパ (ミラノ)" },
"eu_north_1": { "message": "欧州 (ストックホルム)" },
"me_south_1": { "message": "中東 (バーレーン)" },
"sa_east_1": { "message": "南米 (サンパウロ)" }
"cn_northwest_1": { "message": "中国 (寧夏)" }
}
71 changes: 44 additions & 27 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
const agent = window.navigator.userAgent.toLowerCase();
const SETTING_KEY = 'awsconsole';

var intervalId;
var retryLimit = 60

function getStorage() {
if (agent.indexOf("chrome") != -1) {
// chrome extension
Expand All @@ -23,6 +26,7 @@ function getStorage() {
}
}


function applyRule(rule) {
// header
$('header > nav').css('background-color', rule.color);
Expand All @@ -38,39 +42,52 @@ function applyRule(rule) {
}


$(function() {
// get username, accountId, region
function findAccount() {
var name = $("span[data-testid='awsc-nav-account-menu-button'] span:first").text();
var acct = $("div[data-testid='account-detail-menu'] span:nth-child(2)").text();
acct = acct.replaceAll('-', '');
//console.log(name, accountId);
if (name != '') {
//console.log(name, acct);
acct = acct.replaceAll('-', '');
clearInterval(intervalId);

var regions = location.search.match(/region=(.*?)(&|$)/);
var region = "";
if (regions != null && regions.length > 1) {
region = regions[1];
}

// load setting.
getStorage().then(ruleList => {

var regions = location.search.match(/region=(.*?)(&|$)/);
var region = "";
if (regions != null && regions.length > 1) {
region = regions[1];
ruleList[SETTING_KEY].some(rule => {
var re = new RegExp(rule.user);
if (rule.enableRule && (re.test(name) || re.test(acct))) {
if (region == rule.region || "all-region" == rule.region) {
// apply rule.
applyRule(rule);
return true;
}
}
});
},
err => {
console.error(err);
});
}
if (--retryLimit <= 0) {
clearInterval(intervalId);
}

}

// main function
$(function() {
// show/hide label
$('#consoleNavHeader').hover(
() => $('#ruleLabel').css('visibility', 'hidden'),
() => $('#ruleLabel').css('visibility', '')
() => $('#ruleLabel').css('visibility', 'hidden'),
() => $('#ruleLabel').css('visibility', '')
);

// load setting.
getStorage().then(ruleList => {
ruleList[SETTING_KEY].some(rule => {
var re = new RegExp(rule.user);
if (rule.enableRule && (re.test(name) || re.test(acct))) {
if (region == rule.region || "all-region" == rule.region) {
// apply rule.
applyRule(rule);
return true;
}
}
});
},
err => {
console.error(err);
});

// waiting loading.
intervalId = setInterval(findAccount, 1000);
});
12 changes: 9 additions & 3 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,29 @@ app.controller('appCtrl', ['$scope', '$filter', function ($scope, $filter) {
{ value: "us-west-2", label: "US West (Oregon)" },
{ value: "af-south-1", label: "Africa (Cape Town)" },
{ value: "ap-east-1", label: "Asia Pacific (Hong Kong)" },
{ value: "ap-south-2", label: "Asia Pacific (Hyderabad)" },
{ value: "ap-southeast-3", label: "Asia Pacific (Jakarta)" },
{ value: "ap-southeast-4", label: "Asia Pacific (Melbourne)" },
{ value: "ap-south-1", label: "Asia Pacific (Mumbai)" },
{ value: "ap-northeast-3", label: "Asia Pacific (Osaka)" },
{ value: "ap-northeast-2", label: "Asia Pacific (Seoul)" },
{ value: "ap-southeast-1", label: "Asia Pacific (Singapore)" },
{ value: "ap-southeast-2", label: "Asia Pacific (Sydney)" },
{ value: "ap-northeast-1", label: "Asia Pacific (Tokyo)" },
{ value: "ca-central-1", label: "Canada (Central)" },
{ value: "cn-north-1", label: "China (Beijing)" },
{ value: "cn-northwest-1", label: "China (Ningxia)" },
{ value: "eu-central-1", label: "Europe (Frankfurt)" },
{ value: "eu-west-1", label: "Europe (Ireland)" },
{ value: "eu-west-2", label: "Europe (London)" },
{ value: "eu-south-1", label: "Europe (Milan)" },
{ value: "eu-west-3", label: "Europe (Paris)" },
{ value: "eu-south-2", label: "Europe (Spain)" },
{ value: "eu-north-1", label: "Europe (Stockholm)" },
{ value: "eu-central-2", label: "Europe (Zurich)" },
{ value: "me-south-1", label: "Middle East (Bahrain)" },
{ value: "sa-east-1", label: "South America (São Paulo)" }
{ value: "me-central-1", label: "Middle East (UAE)" },
{ value: "sa-east-1", label: "South America (São Paulo)" },
{ value: "cn-north-1", label: "China (Beijing)" },
{ value: "cn-northwest-1", label: "China (Ningxia)" }
];

// translate message
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"manifest_version": 3,
"name": "__MSG_ext_name__",
"description": "__MSG_ext_description__",
"version": "1.0.3",
"version": "1.0.4",
"default_locale": "en",
"content_scripts": [
{
Expand Down

0 comments on commit a5ea0ce

Please sign in to comment.