-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate out in-page-ui-injections CS from global CS
- Somehow this also resulted in the dropping of content_script.css from build, thus it's taken out of the manifest. - That seems correct as the global CS doesn't have any views.
- Loading branch information
Showing
14 changed files
with
142 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 63 additions & 4 deletions
67
src/content-scripts/content_script/in-page-ui-injections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,65 @@ | ||
import { initInPageUIInjections } from 'src/search-injection/content_script' | ||
import type { InPageUIInjectionsMain } from 'src/content-scripts/content_script/types' | ||
import * as constants from '../../search-injection/constants' | ||
import * as utils from '../../search-injection/utils' | ||
import { handleRenderSearchInjection } from '../../search-injection/searchInjection' | ||
import { handleRenderYoutubeInterface } from '../../search-injection/youtubeInterface' | ||
import { renderErrorDisplay } from '../../search-injection/error-display' | ||
import { renderSearchDisplay } from '../../search-injection/search-display' | ||
import type { ContentScriptRegistry, InPageUIInjectionsMain } from './types' | ||
|
||
export const main: InPageUIInjectionsMain = async (...options) => { | ||
initInPageUIInjections(...options) | ||
export const main: InPageUIInjectionsMain = async ({ | ||
inPageUI, | ||
annotationsFunctions, | ||
requestSearcher, | ||
searchDisplayProps, | ||
syncSettings, | ||
syncSettingsBG, | ||
}) => { | ||
inPageUI.events.on( | ||
'injectOnDemandInPageUI', | ||
async ({ component, options }) => { | ||
if (component === 'error-display') { | ||
if (options?.errorDisplayProps) { | ||
renderErrorDisplay(options.errorDisplayProps) | ||
} | ||
} else if (component === 'dashboard') { | ||
renderSearchDisplay(searchDisplayProps) | ||
} else if (component === 'youtube-integration') { | ||
const url = window.location.href | ||
if (url.includes('youtube.com')) { | ||
await handleRenderYoutubeInterface( | ||
syncSettings, | ||
syncSettingsBG, | ||
annotationsFunctions, | ||
) | ||
} | ||
} else if (component === 'search-engine-integration') { | ||
const url = window.location.href | ||
const matched = utils.matchURL(url) | ||
|
||
if (matched) { | ||
const searchInjection = | ||
(await syncSettings.searchInjection.get( | ||
'searchEnginesEnabled', | ||
)) ?? constants.SEARCH_INJECTION_DEFAULT | ||
if (searchInjection[matched]) { | ||
try { | ||
const query = utils.fetchQuery(url) | ||
|
||
await handleRenderSearchInjection( | ||
query, | ||
requestSearcher, | ||
matched, | ||
syncSettings, | ||
) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
) | ||
} | ||
|
||
const registry = globalThis['contentScriptRegistry'] as ContentScriptRegistry | ||
registry.registerInPageUIInjectionScript(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.