Skip to content

Commit

Permalink
feat: add Google Slides and Google Forms (#17)
Browse files Browse the repository at this point in the history
* chore: apply formatting

* feat: add Google Slides and Google Forms

* refactor: remove non-existing service

* fix: regex expression

* fix: regex expression
  • Loading branch information
jaeyongjaykim authored Apr 18, 2022
1 parent 8309e89 commit 0079382
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
chrome.runtime.onMessage.addListener(function (command) {
chrome.tabs.query({ active: true, lastFocusedWindow: true }, tabs => {

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;
Expand All @@ -10,42 +9,49 @@ chrome.runtime.onMessage.addListener(function (command) {
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
update_acc = "u/" + account_num;
}

// Google Doc
// 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
update_acc = "u/" + account_num;
}

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

// Google Drive
const drive_regex = "https:\/\/drive.google.com\/drive\/u\/[0-9].*";
if (current_url.match(drive_regex)) {
// 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
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 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
update_acc = "u/" + account_num;
}

// Google Meet
Expand All @@ -55,79 +61,75 @@ chrome.runtime.onMessage.addListener(function (command) {
current_url = current_url + "?authuser=0";
}
update_url_regex = RegExp("authuser=[0-9]");
update_acc = "authuser=" + account_num
update_acc = "authuser=" + account_num;
}

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

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

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

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

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

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

// Google Keep
const keep_regex = "https:\/\/keep.google.com\/u\/[0-9].*";
console.log(current_url, keep_regex)
console.log(current_url, keep_regex);
if (current_url.match(keep_regex)) {
update_url_regex = RegExp("u\/[0-9]");
update_acc = "u/" + account_num
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)
console.log(current_url);
if (command.substring(0, command.length - 1) == "alt") {
chrome.tabs.update({ url: current_url })
}
else {
chrome.tabs.create({ url: current_url })
chrome.tabs.update({ url: current_url });
} else {
chrome.tabs.create({ url: current_url });
}
} else {
console.log("Account switching is not supported on this page.");
}
else {
console.log("Account switching is not supported on this page.")
}

});
});

0 comments on commit 0079382

Please sign in to comment.