Skip to content

Fix/popup parsing caching#13

Open
PoyrazGoksel wants to merge 4 commits intokdemirel:mainfrom
PoyrazGoksel:fix/popup-parsing-caching
Open

Fix/popup parsing caching#13
PoyrazGoksel wants to merge 4 commits intokdemirel:mainfrom
PoyrazGoksel:fix/popup-parsing-caching

Conversation

@PoyrazGoksel
Copy link
Copy Markdown
Contributor

refactor: move Tureng fetch from content script to background service worker to avoid CORS dependency on host page origin
fix: resolve "Failed to fetch results" by using regex HTML parser in service worker (no DOMParser in MV3 workers), fix duplicate context menu error by creating menu items in onInstalled listener
feat: cache popup panel DOM element for reuse instead of recreating on every double-click

…h out changing pages

Introduce an inline settings panel in the popup with a toggle button and controls for popup modifier, max results and TTS rate. Added UI (popup.html) and styles (main.css) for the panel, wired load/save logic and visual feedback in popup.js (persisting to chrome.storage.sync), and updated options defaults (options.js). content.js now reads and responds to maxResults from storage (updates MAX_RESULTS and listens for changes) and popup TTS uses the stored ttsRate. Includes UX tweaks like a close button, status message and link to full settings.
… worker to avoid CORS dependency on host page origin fix: resolve "Failed to fetch results" by using regex HTML parser in service worker (no DOMParser in MV3 workers), fix duplicate context menu error by creating menu items in onInstalled listener feat: cache popup panel DOM element for reuse instead of recreating on every double-click

(cherry picked from commit f2c56cb)
@PoyrazGoksel
Copy link
Copy Markdown
Contributor Author

@kdemirel

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Tureng Chrome extension’s MV3 architecture by moving Tureng lookups into the background service worker (to avoid page-origin CORS/DOMParser constraints), adds an inline settings panel in the popup UI, and improves the in-page translation popup behavior by caching its DOM panel for reuse.

Changes:

  • Add an inline settings panel in the extension popup (modifier key, max results, TTS rate) and persist these via chrome.storage.sync.
  • Refactor the content-script selection popup to reuse a cached panel element and request translations through the background worker.
  • Implement a regex-based HTML parser in the background worker and adjust context menu creation to run in onInstalled.

Reviewed changes

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

Show a summary per file
File Description
Tureng/styles/main.css Adds styling for the new inline settings toggle button and panel in the popup.
Tureng/scripts/popup.js Implements settings panel logic + persisted TTS rate usage in popup TTS actions.
Tureng/scripts/options.js Extends defaults to include new settings keys (but options UI/save logic remains modifier-only).
Tureng/scripts/content.js Caches and reuses the selection popup panel; fetches results via background messaging; syncs maxResults.
Tureng/scripts/background.js Creates context menu on install; adds Tureng fetch + regex parsing endpoint for the content script.
Tureng/popup.html Adds the inline settings panel markup and settings toggle/close controls.
Comments suppressed due to low confidence (1)

Tureng/scripts/options.js:33

  • defaultSettings now includes maxResults and ttsRate, but this options page still only applies/saves modifier. Either remove the unused defaults here, or extend the options UI + save logic to manage the new settings as well so the settings surface is consistent.
  const defaultSettings = {
    modifier: 'alt',
    maxResults: 5,
    ttsRate: 0.8
  };

  const modifierSelect = document.getElementById('modifier-select');
  const statusEl = document.getElementById('options-status');

  function showSaved() {
    if (!statusEl) {
      return;
    }
    statusEl.style.display = 'block';
    clearTimeout(showSaved._timer);
    showSaved._timer = setTimeout(() => {
      statusEl.style.display = 'none';
    }, 1200);
  }

  function applySettings(settings) {
    if (modifierSelect) {
      modifierSelect.value = settings.modifier;
    }
  }

  function saveSettings() {
    const modifier = modifierSelect ? modifierSelect.value : defaultSettings.modifier;
    chrome.storage.sync.set({ modifier }, showSaved);
  }

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

Comment thread Tureng/popup.html Outdated
Comment thread Tureng/popup.html Outdated
Comment thread Tureng/scripts/content.js
Comment thread Tureng/scripts/background.js Outdated
- render selection popup content with DOM APIs instead of innerHTML
- encode selected text before building Tureng URLs
- fix Turkish labels in popup settings
- decode html entities from parsed background results
@PoyrazGoksel
Copy link
Copy Markdown
Contributor Author

@kdemirel revised

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants