Skip to content

Commit

Permalink
Init repo, first commit with v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prvashisht committed May 26, 2024
0 parents commit 91dcbeb
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 0 deletions.
35 changes: 35 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Code of Conduct

## Introduction

We, as contributors and maintainers, pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Expected Behavior

We expect all contributors and community members to:

- Be respectful and considerate towards others.
- Use inclusive language and avoid derogatory or offensive comments.
- Be open to constructive feedback and ideas.
- Exercise empathy and understanding towards others' perspectives.
- Be mindful of the impact of your words and actions on others.

## Unacceptable Behavior

The following behaviors are considered unacceptable and will not be tolerated:

- Harassment, discrimination, or any form of offensive behavior.
- Personal attacks or insults.
- Trolling, flaming, or derogatory comments.
- Intimidation or threats.
- Any other behavior that creates an unwelcoming or hostile environment.

## Reporting and Enforcement

If you witness or experience any behavior that violates this code of conduct, please report it to the project maintainers at [email address]. All reports will be reviewed and investigated promptly and confidentially. The project maintainers are committed to maintaining the anonymity and privacy of the reporter.

Anyone who violates this code of conduct may be temporarily or permanently banned from the project's community spaces, as determined by the project maintainers.

## Attribution

This code of conduct is adapted from the Contributor Covenant, version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html).
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Web Only (Legacy) Google Search Chrome Extension

[![Version](https://img.shields.io/badge/Version-1.0-blue.svg)]()

This Chrome extension automatically redirects your Google searches to the legacy web only version of Google Search.

## Features

- **Web Only Google Search:** Automatically redirects your Google searches to the legacy web only version.
- **Dynamic Search:** The extension only works when the search query changes, allowing the user to switch to any other search type within the same query.
- **Toggle Feature:** Easily enable or disable the extension with a single click from the extension icon.

## Installation

You can install the extension from the [Chrome Web Store](https://pratyushvashisht.com/legacywebsearch) or follow these steps for local development:

1. Clone the repository:
```
git clone
```

2. Open Chrome and navigate to `chrome://extensions/`.

3. Enable `Developer mode` in the top right corner.

4. Click on `Load unpacked` and select the cloned repository folder.

## Files

- **`manifest.json`**: Contains metadata about the extension, including permissions, icons, and scripts.
- **`content.js`**: Handles the content script that interacts with Google Search pages.
- **`service_worker.js`**: Manages the extension behavior in the background, including badge text and color.

## How to Contribute

Contributions are welcome! Here's how you can get involved:

1. Fork the repository and create your branch from `master`.
2. Make your changes and test thoroughly.
3. Open a pull request, describing the changes you made.
4. Discuss your changes with the community.

Please follow our [Code of Conduct](CODE_OF_CONDUCT.md) when contributing.
10 changes: 10 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === "clickWebSearch") {
document.querySelectorAll('div[role="navigation"] div[role="listitem"]').forEach(async item => {
if (item.textContent.trim() === "Web" && item.querySelector('a')) {
await sendResponse({ success: true });
item.querySelector('a').click();
}
});
}
});
Binary file added icons/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"manifest_version": 3,
"name": "Web Only (Legacy) Google Search",
"version": "1.0",
"description": "This extension automatically redirects your Google searches to the legacy web only version of Google Search.",
"author": "Pratyush Vashisht",
"background": {
"service_worker": "service_worker.js"
},
"content_scripts": [
{
"js": ["content.js"],
"matches": ["*://*.google.com/*"]
}
],
"host_permissions": [
"*://*.google.com/*"
],
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"action": {
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"default_title": "Enable / Disable Web Only Google Search"
},
"permissions": [
"storage",
"tabs"
]
}
100 changes: 100 additions & 0 deletions service_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
let legacyWebSearchSettings = {
isWebSearchEnabled: false,
lastChangedSearch: "",
};

let setExtensionUninstallURL = (settings) => {
const encodedDebugData = encodeURIComponent(
Object.keys(settings)
.sort()
.map((key) => `${key}: ${settings[key]}`)
.join("\n")
);
chrome.runtime.setUninstallURL(
`https://pratyushvashisht.com/legacywebsearch/uninstall?utm_source=browser&utm_medium=extension&utm_campaign=uninstall&debugData=${encodedDebugData}`
);
};

let saveAndApplyExtensionDetails = details => {
legacyWebSearchSettings = { ...legacyWebSearchSettings, ...details };

chrome.storage.sync.set({ legacyWebSearchSettings });
setExtensionUninstallURL(legacyWebSearchSettings);
chrome.action.setBadgeText({
text: legacyWebSearchSettings.isWebSearchEnabled ? "on" : "off",
});

chrome.action.setBadgeBackgroundColor({
color: legacyWebSearchSettings.isWebSearchEnabled ? "#00FF00" : "#F00000",
});
};

chrome.action.onClicked.addListener(() => {
saveAndApplyExtensionDetails({
isWebSearchEnabled: !legacyWebSearchSettings.isWebSearchEnabled,
});
});

chrome.runtime.onInstalled.addListener(async installInfo => {
let installDate, updateDate;
if (installInfo.reason === "install") {
installDate = new Date().toISOString();
} else {
updateDate = new Date().toISOString();
}
const platformInfo = await chrome.runtime.getPlatformInfo();
let debugData = {
...platformInfo,
agent: navigator.userAgent,
locale: navigator.language,
platform: navigator.platform,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
version: chrome.runtime.getManifest().version,
};
if (installDate) debugData.installDate = installDate;
if (updateDate) debugData.updateDate = updateDate;
const data = await chrome.storage.sync.get("legacyWebSearchSettings");
if (!data.legacyWebSearchSettings) {
saveAndApplyExtensionDetails(debugData);
return;
}
saveAndApplyExtensionDetails({
...data.legacyWebSearchSettings,
...debugData,
num_changes: data.legacyWebSearchSettings.num_changes || 0,
});
});

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete') {
const url = new URL(tab.url);
if (url.pathname === '/search') {
const query = url.searchParams.get('q');
const udm = url.searchParams.get('udm');
// If there is a query, it's different from the last one, web search is enabled, and udm is not set.
// This doesn't switch to web search if the user clicks on another search type or
// switches back to default search with the same query.

// udm parameter is set for different types of searches like image search, etc
// for image search: udm is 2
// for web search: udm is 14
if (
query
&& query !== legacyWebSearchSettings.lastChangedSearch
&& legacyWebSearchSettings.isWebSearchEnabled
&& !udm
) {
chrome.tabs.sendMessage(tab.id, { action: "clickWebSearch", query }, (response) => {
if (response && response.success) {
saveAndApplyExtensionDetails({
lastChangedSearch: query,
num_changes: legacyWebSearchSettings.num_changes + 1,
});
}
});
} else if (query && query !== legacyWebSearchSettings.lastChangedSearch) {
saveAndApplyExtensionDetails({ lastChangedSearch: query });
}
}
}
});

0 comments on commit 91dcbeb

Please sign in to comment.