Skip to content

feat: add X (Twitter) as a new search engine option#218

Open
XimilalaXiang wants to merge 2 commits into
prem-k-r:mainfrom
XimilalaXiang:feature/add-x-search-engine
Open

feat: add X (Twitter) as a new search engine option#218
XimilalaXiang wants to merge 2 commits into
prem-k-r:mainfrom
XimilalaXiang:feature/add-x-search-engine

Conversation

@XimilalaXiang

@XimilalaXiang XimilalaXiang commented May 21, 2026

Copy link
Copy Markdown

📌 Description

Add X (formerly Twitter) as a new search engine option, allowing users to search directly on X from the new tab page.

Changes:

  • scripts/search.js: Added engine10 with URL https://x.com/search?q=
  • index.html: Added X logo SVG icon (<symbol id="x-engine-icon">), dropdown item, and radio button option in settings
  • scripts/languages.js: Registered xEngine in both translationMap and elementsMap
  • 26 locale files: Added xEngine: "X" translation key (brand name, kept as "X" across all languages)
  • CHANGELOG.md: Updated under Added section

How it works:

  • X appears as a selectable search engine in both the search bar dropdown and the settings panel
  • Selecting X and entering a search term redirects to x.com/search?q={query}
  • Search suggestions fall back to Google suggestions (same behavior as Quora, Bing, and Google Images which also don't have dedicated suggestion APIs)
  • Full localization support across all 26 languages

🎨 Visual Changes (Screenshots / Videos)

The X search engine appears with the official X logo icon in:

  1. The search engine dropdown (click the engine icon next to the search bar)
image
  1. The settings panel under "Search On" category
image

🔗 Related Issues

  • No related issues (new feature proposal)

✅ Checklist

  • I have read and followed the Contributing Guidelines.
  • My code follows the project's coding style and conventions.
  • I have tested my changes thoroughly to ensure expected behavior.
  • I have verified compatibility across Chrome and Firefox (additional browsers if applicable).
  • I have attached relevant visual evidence (screenshots/videos) if applicable.
  • I have updated the CHANGELOG.md under the appropriate categories with all my changes in this PR.

🤖 AI Assistance (Coding)

  • None
  • Ideas / planning
  • Debugging / review help
  • Small code snippets
  • Partial implementation
  • Major implementation help
  • Mostly AI-generated
  • Full vibe coded

Overview

Adds X (formerly Twitter) as a new search engine option available in the search dropdown and settings panel. Users can select X and search queries redirect to https://x.com/search?q={query}.

Changes Made

Core Functionality

  • scripts/search.js
    • Added engine10 entry to searchQueryURLs mapping with X search URL (https://x.com/search?q=).
    • Fixed engine ID parsing for multi-digit engines by replacing charAt(...) extraction with replace("engine", "") across selection/restore/switch flows (resolves engine10 parsing).

UI & Markup

  • index.html
    • Added X logo SVG icon (#x-engine-icon).
    • Added "X" dropdown item in the search engine selection.
    • Added "X" radio button option in settings ("search with" list).

Localization

  • scripts/languages.js
    • Registered xEngine in the translation mapping and added xEngineDD element mapping for dropdown text translation.
  • 26 locale files (ar_SA, bn, cs, de, el, en, es, fa, fr, hi, hu, idn, it, ja, ko, mr, pl, pt, ru, sv, ta, th, uk, uz, zh, zh_TW)
    • Added xEngine: "X" translation entry to each locale's translations object (kept as "X" across languages).

Documentation

  • CHANGELOG.md
    • Updated "Added" section noting X (Twitter) as a new search engine option with full localization support.

Visuals & Testing

  • PR includes screenshots showing X in the dropdown and in the settings panel.
  • Checklist indicates testing and cross-browser verification completed (Chrome and Firefox).

Search Behavior

  • X appears in the search bar dropdown and in the settings engine list.
  • Selecting X and submitting a query navigates to https://x.com/search?q={query}.
  • Search suggestion fallback uses Google suggestions (same fallback used for Quora, Bing, Google Images).

Notes

  • Commit includes a parsing bug fix to correctly handle multi-digit engine IDs (important for engine10).

Review Change Stack

- Add X search URL (x.com/search?q=) as engine10 in search.js
- Add X logo SVG icon in index.html
- Add dropdown item and radio button option for X in settings
- Register xEngine in translationMap and elementsMap in languages.js
- Add xEngine translation key to all 26 locale files
- Update CHANGELOG.md

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings May 21, 2026 04:43
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds X (Twitter) as a supported search engine option. The implementation includes UI components, complete localization across 25+ languages, translation wiring, search URL routing, and changelog documentation.

Changes

X Search Engine Addition

Layer / File(s) Summary
UI Components & Icon Definition
index.html
Adds dropdown option for X (data-engine="10"), hidden SVG sprite #x-engine-icon, and a search-on radio card (value="engine10") for engine selection.
Localization Translations Across Locales
locales/*.js
Adds xEngine: "X" translation entry to each locale file so the X label is available in all supported languages.
Translation Mapping & Element Wiring
scripts/languages.js
Registers xEngine in the translation map and maps the xEngineDD element to that key so the dropdown label is localized.
Search Logic & URL Routing
scripts/search.js
Adds engine10 → X/Twitter search URL to searchQueryURLs and updates engine-id extraction to strip the engine prefix across click, restore, shortcut-switch, and swipe switching flows.
Changelog Documentation
CHANGELOG.md
Documents the X search engine addition under Unreleased → Added, noting full localization support.

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs:

  • prem-k-r/MaterialYouNewTab#145: Modifies scripts/search.js engine identifier/index handling and engine switching logic, related to adding new search engines.

Suggested labels:
enhancement, ui/ux

Suggested reviewers:

  • itz-rj-here
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add X (Twitter) as a new search engine option' directly and clearly summarizes the main change in the PR, which is adding X/Twitter as a new selectable search engine across all UI elements and locales.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering all template sections: clear description of changes, visual evidence with screenshots, checklist completion, and AI assistance disclosure. All required information is present and detailed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds X (Twitter) as an additional “search with” engine across the UI and translations.

Changes:

  • Added an engine10 URL entry for X in the search engine URL map.
  • Extended language application logic and locale dictionaries with xEngine / xEngineDD.
  • Updated the UI to include X in both the engine dropdown and the radio list, plus an SVG icon.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
scripts/search.js Adds X search URL mapping (engine10).
scripts/languages.js Wires new localization keys into language application flow.
locales/*.js Adds xEngine translation strings across multiple locales.
index.html Adds X option to dropdown and engine list; introduces X SVG symbol.
CHANGELOG.md Documents the newly added X search engine option.
Comments suppressed due to low confidence (1)

index.html:865

  • This introduces a second hidden <svg> sprite block right after an existing one ends. To keep the DOM simpler and avoid duplicating hidden sprite containers, add the new <symbol id=\"x-engine-icon\"> into the existing hidden <svg> sprite instead of creating a new <svg style=\"display: none;\"> container.
            </svg>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread index.html
Comment on lines +874 to +879
<svg style="display: none;">
<symbol id="x-engine-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path style="transform: scale(0.75); transform-origin: center;"
d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
</symbol>
</svg>
Comment thread index.html
Comment on lines +874 to +879
<svg style="display: none;">
<symbol id="x-engine-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path style="transform: scale(0.75); transform-origin: center;"
d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
</symbol>
</svg>
Comment thread scripts/languages.js
Comment on lines 192 to 198
"redditEngine",
"wikipediaEngine",
"quoraEngine",
"xEngine",
"chatGPT",
"gemini",
"copilot",
Comment thread scripts/languages.js
Comment on lines 269 to 273
{ id: "redditEngineDD", key: "redditEngine" },
{ id: "wikipediaEngineDD", key: "wikipediaEngine" },
{ id: "quoraEngineDD", key: "quoraEngine" },
{ id: "xEngineDD", key: "xEngine" },
{ id: "bookmarksHover", key: "bookmarksHeading" },

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/search.js`:
- Around line 22-23: The new key "engine10" exposes that selection code slices
only the last character (e.g., id.slice(-1) or equivalent) to get the engine
number; locate the selection/restore logic that derives the numeric id from keys
like "engineX" (the code that references engine10) and replace the
single-character extraction with a full numeric parse (e.g., use a regex
/engine(\d+)/ and parseInt(match[1]) or parseInt(id.replace(/^engine/, ''))) so
the dropdown swap and restore use the full engine index rather than only the
last digit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6880baee-0e6b-4e93-a42a-3eee3fee2204

📥 Commits

Reviewing files that changed from the base of the PR and between 6db3db4 and 7015e3e.

📒 Files selected for processing (30)
  • CHANGELOG.md
  • index.html
  • locales/ar_SA.js
  • locales/bn.js
  • locales/cs.js
  • locales/de.js
  • locales/el.js
  • locales/en.js
  • locales/es.js
  • locales/fa.js
  • locales/fr.js
  • locales/hi.js
  • locales/hu.js
  • locales/idn.js
  • locales/it.js
  • locales/ja.js
  • locales/ko.js
  • locales/mr.js
  • locales/pl.js
  • locales/pt.js
  • locales/ru.js
  • locales/sv.js
  • locales/ta.js
  • locales/th.js
  • locales/uk.js
  • locales/uz.js
  • locales/zh.js
  • locales/zh_TW.js
  • scripts/languages.js
  • scripts/search.js

Comment thread scripts/search.js
Fix single-character engine ID extraction that breaks engine10.
The previous code used charAt(value.length - 1) which only reads
the last character, causing engine10 to be parsed as "0" instead
of "10". Replace all 4 occurrences with replace("engine", "") to
correctly handle multi-digit engine numbers.

Co-authored-by: Cursor <cursoragent@cursor.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/search.js (1)

370-377: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard storedSearchEngine before dereference in shortcut-switch flow.

Line 374 and Line 376 can throw when selectedSearchEngine-${activeSearchMode} is absent (null from localStorage). Add a null guard before using selectedRadioButton.checked and .replace(...).

Proposed fix
     const storedSearchEngine = localStorage.getItem(`selectedSearchEngine-${activeSearchMode}`);
+    if (!storedSearchEngine) return;

     // Find the corresponding radio button
     const selectedRadioButton = document.querySelector(`input[name="search-engine"][value="${storedSearchEngine}"]`);
-    selectedRadioButton.checked = true;
+    if (!selectedRadioButton) return;
+    selectedRadioButton.checked = true;

     const storedSearchEngineSN = storedSearchEngine.replace("engine", "");
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/search.js` around lines 370 - 377, storedSearchEngine can be null
when localStorage lacks selectedSearchEngine-${activeSearchMode}, so guard its
use before dereferencing: check that storedSearchEngine is truthy before calling
document.querySelector(...) and before calling storedSearchEngine.replace(...);
also null-check the resulting selectedRadioButton before setting .checked, and
compute selector only when storedSearchEngine exists (or fall back to a safe
default engine id); update references to storedSearchEngine,
selectedRadioButton, activeSearchMode, and selector accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@scripts/search.js`:
- Around line 370-377: storedSearchEngine can be null when localStorage lacks
selectedSearchEngine-${activeSearchMode}, so guard its use before dereferencing:
check that storedSearchEngine is truthy before calling
document.querySelector(...) and before calling storedSearchEngine.replace(...);
also null-check the resulting selectedRadioButton before setting .checked, and
compute selector only when storedSearchEngine exists (or fall back to a safe
default engine id); update references to storedSearchEngine,
selectedRadioButton, activeSearchMode, and selector accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4fc39d2-4a67-4d88-8b27-ed7b87761e1e

📥 Commits

Reviewing files that changed from the base of the PR and between 7015e3e and 08ee1c7.

📒 Files selected for processing (1)
  • scripts/search.js

@itz-rj-here itz-rj-here added enhancement New feature or request invalid This doesn't seem right labels May 21, 2026
@itz-rj-here

Copy link
Copy Markdown
Collaborator

Well. Basically X is not a search engine. So I don't agree with it actually.

@prem-k-r

Copy link
Copy Markdown
Owner

Well. Basically X is not a search engine. So I don't agree with it actually.

It is on "Search On", not on "Search With", so it's fine..
I've planned for custom search engine feature.. but this one is small name, occupy less space.. maybe I'll consider this PR adding

@itz-rj-here itz-rj-here removed the invalid This doesn't seem right label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants