From a5ea0ce882032cab49847dfb4a048d5572f2b4bd Mon Sep 17 00:00:00 2001 From: bunjik Date: Sat, 3 Jun 2023 23:27:00 +0900 Subject: [PATCH] update regions --- README.md | 4 +++ _locales/ja/messages.json | 48 ++++++++++++++------------ extension.js | 71 ++++++++++++++++++++++++--------------- js/options.js | 12 +++++-- manifest.json | 4 +-- 5 files changed, 86 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index e97e33a..2476078 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/_locales/ja/messages.json b/_locales/ja/messages.json index 17b9700..216c244 100644 --- a/_locales/ja/messages.json +++ b/_locales/ja/messages.json @@ -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": "中国 (寧夏)" } } \ No newline at end of file diff --git a/extension.js b/extension.js index 3a44ee0..2bc5305 100644 --- a/extension.js +++ b/extension.js @@ -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 @@ -23,6 +26,7 @@ function getStorage() { } } + function applyRule(rule) { // header $('header > nav').css('background-color', rule.color); @@ -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); }); diff --git a/js/options.js b/js/options.js index c9971ed..f0759bd 100644 --- a/js/options.js +++ b/js/options.js @@ -39,6 +39,9 @@ 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)" }, @@ -46,16 +49,19 @@ app.controller('appCtrl', ['$scope', '$filter', function ($scope, $filter) { { 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 diff --git a/manifest.json b/manifest.json index 083ad9e..c7234b4 100644 --- a/manifest.json +++ b/manifest.json @@ -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": [ {