Skip to content

Commit

Permalink
feat: Generalized Google URL patterns to support more services (#19)
Browse files Browse the repository at this point in the history
* refactor: generalize url patterns
  • Loading branch information
jaeyongjaykim authored Sep 1, 2022
1 parent a1235df commit df7991c
Showing 1 changed file with 4 additions and 107 deletions.
111 changes: 4 additions & 107 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,121 +5,18 @@ chrome.runtime.onMessage.addListener(function (command) {
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)) {
const google_regex_type1 = ".*.google.*\/u\/[0-9].*"
if (current_url.match(google_regex_type1)) {
update_url_regex = RegExp("u\/[0-9]");
update_acc = "u/" + account_num;
}

// Google Docs
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 Sheets
const sheets_regex = "https:\/\/docs.google.com\/spreadsheets\/u\/[0-9].*";
if (current_url.match(sheets_regex)) {
update_url_regex = RegExp("u\/[0-9]");
update_acc = "u/" + account_num;
}

// Google Slides
const slides_regex = "https:\/\/docs.google.com\/presentation\/u\/[0-9].*";
if (current_url.match(slides_regex)) {
update_url_regex = RegExp("u\/[0-9]");
update_acc = "u/" + account_num;
}

// Google Forms
const forms_regex = "https:\/\/docs.google.com\/forms\/u\/[0-9].*";
if (current_url.match(forms_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 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\/.*";
if (current_url.match(meet_regex)) {
if (!current_url.match("authuser=[0-9]")) {
current_url = current_url + "?authuser=0";
}
const google_regex_type2 = ".*.google.*\?authuser=[0-9].*"
if (current_url.match(google_regex_type2)) {
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;
}

// Google Duo web
const duo_regex = "https:\/\/duo.google.com\/u\/[0-9].*";
console.log(current_url, duo_regex);
if (current_url.match(duo_regex)) {
update_url_regex = RegExp("u\/[0-9]");
update_acc = "u/" + account_num;
}

// Google calendar
const calendar_regex = "https:\/\/calendar.google.com\/calendar\/u\/[0-9].*";
console.log(current_url, calendar_regex);
if (current_url.match(calendar_regex)) {
update_url_regex = RegExp("u\/[0-9]");
update_acc = "u/" + account_num;
}

// Google shopping
const shopping_regex = "https:\/\/www.google.co.in\/.*\?authuser=[0-9].*";
console.log(current_url, shopping_regex);
if (current_url.match(shopping_regex)) {
update_url_regex = RegExp("authuser=[0-9]");
update_acc = "authuser=" + account_num;
}

// Google translate
const translate_regex = "https:\/\/translate.google.co.in\/.*\?authuser=[0-9].*";
console.log(current_url, translate_regex);
if (current_url.match(translate_regex)) {
update_url_regex = RegExp("authuser=[0-9]");
update_acc = "authuser=" + account_num;
}

// Google Keep
const keep_regex = "https:\/\/keep.google.com\/u\/[0-9].*";
console.log(current_url, keep_regex);
if (current_url.match(keep_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);
Expand Down

0 comments on commit df7991c

Please sign in to comment.