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

Redirect to last query after login #49

Merged
merged 1 commit into from Feb 23, 2021
Merged
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -90,9 +90,49 @@ const lookForAccessToken = async () => {
};
}

function redirectToLastQuery() {
let lastQuery;

browser.webRequest.onBeforeRedirect.addListener((details) => {
if (details.redirectUrl.startsWith(`https://signon${AUTH_DOMAIN}/`)) {
const originalUrl = new URL(details.url);
lastQuery = originalUrl.searchParams.get('q');
}
}, {
urls: [
`${SERP_BASE_URL}/search*`,
`${SERP_BASE_URL}/images/search*`,
`${SERP_BASE_URL}/videos/search*`,
USE_STAGING ? 'https://staging.ghosterysearch.com/' : 'https://ghosterysearch.com/search*',
USE_STAGING ? 'https://staging.ghosterysearch.com/images/search*' : 'https://ghosterysearch.com/images/search*',
USE_STAGING ? 'https://staging.ghosterysearch.com/videos/search*' : 'https://ghosterysearch.com/videos/search*',
],
}, []);

browser.webRequest.onBeforeSendHeaders.addListener(async (details) => {
const url = new URL(details.url);
const searchParams = url.searchParams;
if (lastQuery) {;
searchParams.set('q', lastQuery);
lastQuery = null;
url.pathname = 'search/';
url.searchParams = searchParams;
return {
redirectUrl: url.toString(),
};
}
}, {
urls: [
`${SERP_BASE_URL}/`,
USE_STAGING ? 'https://staging.ghosterysearch.com/' : 'https://ghosterysearch.com/',
],
}, ['blocking']);
}

async function start() {
await setupEndpoints;
lookForAccessToken();
redirectToLastQuery();

browser.webRequest.onBeforeSendHeaders.addListener(async (details) => {
const { requestHeaders } = details;
ProTip! Use n and p to navigate between commits in a pull request.