From cf00ca5245d76a08092bba7258de56be728f2326 Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 12:21:19 +0530 Subject: [PATCH 1/9] Add Google Meet regex --- background.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/background.js b/background.js index b21a5b4..036d8a9 100644 --- a/background.js +++ b/background.js @@ -42,6 +42,13 @@ chrome.commands.onCommand.addListener(function (command) { update_acc = "u/" + account_num } + // Google Meet + const meet_regex = "https:\/\/meet.google.com\/.+?authuser=[0-9].*"; + if (current_url.match(meet_regex)) { + update_url_regex = RegExp("authuser=[0-9]"); + update_acc = "authuser=" + account_num + } + if (update_acc && update_url_regex) { current_url = current_url.replace(update_url_regex, update_acc); console.log(current_url) From 0a0f405a19f0056589bfa7a62cd14dbd01eb8de3 Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 12:53:02 +0530 Subject: [PATCH 2/9] Update Google Meet regex --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index 036d8a9..f96092c 100644 --- a/background.js +++ b/background.js @@ -43,7 +43,7 @@ chrome.commands.onCommand.addListener(function (command) { } // Google Meet - const meet_regex = "https:\/\/meet.google.com\/.+?authuser=[0-9].*"; + const meet_regex = "https:\/\/meet.google.com\/.*\?authuser=[0-9].*"; if (current_url.match(meet_regex)) { update_url_regex = RegExp("authuser=[0-9]"); update_acc = "authuser=" + account_num From 28a39693e513f3ca973562aa2d6534876f4bb43c Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 13:41:46 +0530 Subject: [PATCH 3/9] Add Google Hangouts support --- background.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/background.js b/background.js index f96092c..31b0072 100644 --- a/background.js +++ b/background.js @@ -49,6 +49,14 @@ chrome.commands.onCommand.addListener(function (command) { update_acc = "authuser=" + account_num } + // Google Hangouts + const hangouts_regex1 = "https:\/\/hangouts.google.com\/.*\?authuser=[0-9].*"; + console.log(current_url, hangouts_regex1) + if (current_url.match(hangouts_regex1)) { + update_url_regex = RegExp("authuser=[0-9]"); + update_acc = "authuser=" + account_num + } + if (update_acc && update_url_regex) { current_url = current_url.replace(update_url_regex, update_acc); console.log(current_url) From a6fd34e6a9d355461c68a2cb9b109541075ed58c Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 13:46:38 +0530 Subject: [PATCH 4/9] Add Google Accounts support --- background.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/background.js b/background.js index 31b0072..a610595 100644 --- a/background.js +++ b/background.js @@ -57,6 +57,14 @@ chrome.commands.onCommand.addListener(function (command) { update_acc = "authuser=" + account_num } + // Google Accounts + const accounts_regex = "https:\/\/myaccount.google.com\/u\/[0-9].*"; + console.log(current_url, accounts_regex) + if (current_url.match(accounts_regex)) { + update_url_regex = RegExp("u\/[0-9]"); + update_acc = "u/" + account_num + } + if (update_acc && update_url_regex) { current_url = current_url.replace(update_url_regex, update_acc); console.log(current_url) From a1a8b62fbeaf25dfe278221dff854d6285c0c3f4 Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 13:48:02 +0530 Subject: [PATCH 5/9] Refactor background.js --- background.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index a610595..321f214 100644 --- a/background.js +++ b/background.js @@ -50,9 +50,9 @@ chrome.commands.onCommand.addListener(function (command) { } // Google Hangouts - const hangouts_regex1 = "https:\/\/hangouts.google.com\/.*\?authuser=[0-9].*"; - console.log(current_url, hangouts_regex1) - if (current_url.match(hangouts_regex1)) { + const hangouts_regex = "https:\/\/hangouts.google.com\/.*\?authuser=[0-9].*"; + console.log(current_url, hangouts_regex) + if (current_url.match(hangouts_regex)) { update_url_regex = RegExp("authuser=[0-9]"); update_acc = "authuser=" + account_num } From b212aa82d2b905f3087f03bb6bd19f5d7193a458 Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 14:42:02 +0530 Subject: [PATCH 6/9] Create common update logic for all google urls --- background.js | 91 +++++++++++---------------------------------------- 1 file changed, 20 insertions(+), 71 deletions(-) diff --git a/background.js b/background.js index 321f214..6cc9d8a 100644 --- a/background.js +++ b/background.js @@ -1,79 +1,28 @@ chrome.commands.onCommand.addListener(function (command) { - if (command.match("account-[0-9]") ) { + if (command.match("account-[0-9]")) { chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => { - var current_url = tabs[0].url; var account_num = command.substring(command.length - 1); - var update_url_regex = null; - var update_acc = null; - - // Gmail - const gmail_regex = "https:\/\/mail.google.com\/mail\/u\/[0-9].*"; - if (current_url.match(gmail_regex)) { - update_url_regex = RegExp("u\/[0-9]"); - update_acc = "u/" + account_num - } - - // Google Doc - const doc_regex = "https:\/\/docs.google.com\/document\/u\/[0-9].*"; - if (current_url.match(doc_regex)) { - update_url_regex = RegExp("u\/[0-9]"); - update_acc = "u/" + account_num - } - - // Google Drive - const drive_regex = "https:\/\/drive.google.com\/drive\/u\/[0-9].*"; - if (current_url.match(drive_regex)) { - update_url_regex = RegExp("u\/[0-9]"); - update_acc = "u/" + account_num - } - - // Google Play Music - const play_music_regex = "https:\/\/play.google.com\/music\/listen\\?u\=[0-9].*"; - if (current_url.match(play_music_regex)) { - update_url_regex = RegExp("\\?u\=[0-9]"); - update_acc = "?u=" + account_num - } - - // Google Classroom - const classroom_regex = "https:\/\/classroom.google.com\/u\/[0-9].*"; - if (current_url.match(classroom_regex)) { - update_url_regex = RegExp("u\/[0-9]"); - update_acc = "u/" + account_num - } - - // Google Meet - const meet_regex = "https:\/\/meet.google.com\/.*\?authuser=[0-9].*"; - if (current_url.match(meet_regex)) { - update_url_regex = RegExp("authuser=[0-9]"); - update_acc = "authuser=" + account_num - } - - // Google Hangouts - const hangouts_regex = "https:\/\/hangouts.google.com\/.*\?authuser=[0-9].*"; - console.log(current_url, hangouts_regex) - if (current_url.match(hangouts_regex)) { - update_url_regex = RegExp("authuser=[0-9]"); - update_acc = "authuser=" + account_num - } - - // Google Accounts - const accounts_regex = "https:\/\/myaccount.google.com\/u\/[0-9].*"; - console.log(current_url, accounts_regex) - if (current_url.match(accounts_regex)) { - update_url_regex = RegExp("u\/[0-9]"); - update_acc = "u/" + account_num + var possible_regex = ["u/", "u=", "authuser="] + + const google_regex = "https:\/\/.+.google.com.*" + if (current_url.match(google_regex)) { + let updated = false + for (let i = 0; i < possible_regex.length; i++) { + let curRegex = possible_regex[i] + if (current_url.search(curRegex + "[0-9]") >= 0) { + current_url = current_url.replace(RegExp(curRegex + "[0-9]"), curRegex + account_num); + chrome.tabs.update({ url: current_url }); + updated = true + break; + } + } + if (!updated) { + alert("Account switching is not supported on this page.") + } + } else { + alert("Account switching is not supported on this page.") } - - if (update_acc && update_url_regex) { - current_url = current_url.replace(update_url_regex, update_acc); - console.log(current_url) - chrome.tabs.update({ url: current_url }); - } - else { - console.log("Account switching is not supported on this page.") - } - }); } }); From a25b276d6d91f62198940daf99e60e33cb87db00 Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 14:47:20 +0530 Subject: [PATCH 7/9] Update user alerts --- background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background.js b/background.js index 6cc9d8a..eac7279 100644 --- a/background.js +++ b/background.js @@ -18,7 +18,7 @@ chrome.commands.onCommand.addListener(function (command) { } } if (!updated) { - alert("Account switching is not supported on this page.") + alert("Support for this page is under development.") } } else { alert("Account switching is not supported on this page.") From 8290faeba7af0460a7e33d967f014d48670ca1b0 Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 15:01:52 +0530 Subject: [PATCH 8/9] Add functionality to shift to user from base url --- background.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index eac7279..e47ad83 100644 --- a/background.js +++ b/background.js @@ -4,6 +4,7 @@ chrome.commands.onCommand.addListener(function (command) { var current_url = tabs[0].url; var account_num = command.substring(command.length - 1); var possible_regex = ["u/", "u=", "authuser="] + // var mapping = {"u/":[], "u=", "authuser="} const google_regex = "https:\/\/.+.google.com.*" if (current_url.match(google_regex)) { @@ -18,7 +19,9 @@ chrome.commands.onCommand.addListener(function (command) { } } if (!updated) { - alert("Support for this page is under development.") + addition = (current_url[-1] == '/') ? "u/" : "/u/"; + current_url = current_url + addition + account_num; + chrome.tabs.update({ url: current_url }); } } else { alert("Account switching is not supported on this page.") From a56aef2b19a04ccba2b3524ea3c0f2e03f78f18c Mon Sep 17 00:00:00 2001 From: Geetesh Gupta Date: Tue, 21 Apr 2020 15:12:04 +0530 Subject: [PATCH 9/9] Add support for Google Calendar --- background.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/background.js b/background.js index e47ad83..8c66509 100644 --- a/background.js +++ b/background.js @@ -3,7 +3,7 @@ chrome.commands.onCommand.addListener(function (command) { chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => { var current_url = tabs[0].url; var account_num = command.substring(command.length - 1); - var possible_regex = ["u/", "u=", "authuser="] + var possible_regex = ["u/", "u=", "authuser=", "b/"] // var mapping = {"u/":[], "u=", "authuser="} const google_regex = "https:\/\/.+.google.com.*" @@ -19,8 +19,12 @@ chrome.commands.onCommand.addListener(function (command) { } } if (!updated) { - addition = (current_url[-1] == '/') ? "u/" : "/u/"; - current_url = current_url + addition + account_num; + if (current_url.search("calendar.google.com") >= 0) + current_url = current_url.replace('/r', "/b/" + account_num + "/r"); + else{ + addition = (current_url[-1] == '/') ? "u/" : "/u/"; + current_url = current_url + addition + account_num; + } chrome.tabs.update({ url: current_url }); } } else {