Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force feature #3

Merged
merged 2 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.crx
*.pem
.idea
43 changes: 33 additions & 10 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
var authUser;
var authUser, force;

chrome.storage.sync.get({
authuser: '',
force: false,
}, function(result) {
authUser = result.authuser;
force = result.force;
});

chrome.webRequest.onBeforeRequest.addListener(function (details) {
if (details.url.toLowerCase().indexOf('authuser') == -1 &&
/meet.google.com\/.*-.*-.*/.test(details.url) &&
details.method == "GET") {
var _redirectUrl = details.url;
var newArg = 'authuser=' + authUser;
_redirectUrl = _redirectUrl + (_redirectUrl.indexOf('?') == -1 ? '?' : '&') + newArg;
return {
redirectUrl: _redirectUrl
};
if( details.method === "GET" ) {
var loweredUrl = details.url.toLowerCase();

var authUserExists = loweredUrl.indexOf('authuser') >= 0;
var authUserIsSame = loweredUrl.indexOf('authuser=' + authUser) >= 0;

var shouldRedirect = ( !authUserExists || (!authUserIsSame && force ) ) && parseInt(authUser) > 0;
var isRedirectUriCorrect = ( /meet.google.com\/.*-.*-.*/.test(details.url) || details.url === 'https://meet.google.com/' || 'https://meet.google.com/landing' || 'https://meet.google.com/new' );

if ( shouldRedirect && isRedirectUriCorrect ) {
var _redirectUrl = details.url;

var params = new URLSearchParams(_redirectUrl.split('?')[1]);

for (var pair of params.entries()) {
if( pair[0].toLowerCase() === "authuser" ) {
params.delete(pair[0]);
}
}

params.set('authuser', authUser);

_redirectUrl = _redirectUrl.split('?')[0] + "?" + params.toString();

return {
redirectUrl: _redirectUrl
};
}
}
}, {
urls: ["https://meet.google.com/*"]
Expand Down
19 changes: 13 additions & 6 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@
<body>
<div class="container">
<h3>Default Google Meet account Configuration</h3>
<p class="grouped">
<p>
<input type="text" id="authuser" placeholder="Set the AuthUser">
</p>
<p>
<input type="checkbox" id="force" /> Force Redirect?
</p>
<p>
<button id="save">Save</button>
</p>
<h3>What is an AuthUser ID?</h3>
<p>To find the authUser ID for the Google account you want to set as default:
<p>To find the authUser ID for the Google account you want to set as default:</p>
<ul>
<li>Go to meet.google.com</li>
<li>Using the account switcher in the top right, switch to the google account you want as your default</li>
<li>After the page reloads with the desired account active, there will be a <em>authuser=</em> section added
to
the url. The number that follows this is your authUser ID</li>
the url. The number that follows this is your AuthUser ID</li>
</ul>
If the first account that Google Meet opened is your desired account, your authUser ID is 0 (and you probably
don't need this extension)
</p>
<p>If the first account that Google Meet opened is your desired account, your authUser ID is 0 (and you probably
don't need this extension)</p>
<h3>What is an Force Redirect?</h3>
<p>This option is required in order to handle invalid links with incorrect AuthUser inside it.</p>
<p>This option start to redirect you into AuthUser ID, no matter which AuthUse ID selected</p>

</div>
<script src="options.js"></script>
Expand Down
10 changes: 9 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
saveButton = document.getElementById('save');
authuserInput = document.getElementById('authuser');
forceInput = document.getElementById('force');

function saveConfig() {
chrome.storage.sync.set({
authuser: authuserInput.value,
force: forceInput.checked === true
}, function() {
saveButton.setAttribute('class', 'button success');
saveButton.innerHTML = "Saved";

chrome.extension.getBackgroundPage().authUser = authuserInput.value;
chrome.extension.getBackgroundPage().force = forceInput.checked === true;

setTimeout(function() {
saveButton.removeAttribute('class');
window.close();
Expand All @@ -27,10 +32,13 @@ function validateInput() {
}

function loadConfig() {
var initialValue = chrome.storage.sync.get({
chrome.storage.sync.get({
authuser: '',
force: false
}, function(result) {
authuserInput.value = result.authuser;
forceInput.checked = result.force;

validateInput();
});
}
Expand Down