Skip to content

Commit

Permalink
Add testUrlWithRegex()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 30, 2024
1 parent fe14f8f commit 5098c8d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,30 @@ function getManagedAccounts(tabId) {
});
}

function testUrlWithRegex(url, regexPattern) {
try {
const regex = new RegExp(regexPattern);
return regex.test(url);
} catch (error) {
alert(`testUrlWithRegex() error, the regex pattern: "${regexPattern}" is invalid`);
return false;
}
}

async function autoLogin(tabId, url) {
const managedAccounts = await getManagedAccounts(tabId);
if (managedAccounts) {
for (const managedAccount of managedAccounts) {
if (managedAccount && url.includes(managedAccount.signinUrl)) {
autoLoginTabs.add(tabId);
chrome.tabs.sendMessage(tabId, {
action: "autoLogin",
managedAccount: managedAccount,
});
break;
if (managedAccount && managedAccount.signinUrl && url) {
const isMatch = testUrlWithRegex(url, managedAccount.signinUrl);
if (isMatch) {
autoLoginTabs.add(tabId);
chrome.tabs.sendMessage(tabId, {
action: "autoLogin",
managedAccount: managedAccount,
});
break;
}
}
}
}
Expand Down

0 comments on commit 5098c8d

Please sign in to comment.