generated from chibat/chrome-extension-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: using shadow DOM to prevent style pollution issues
- Loading branch information
Showing
7 changed files
with
125 additions
and
89 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const zIndex = '2147483647' | ||
export const popupThumbID = '__yetone-openai-translator-popup-thumb' | ||
export const popupCardID = '__yetone-openai-translator-popup-card' | ||
export const containerTagName = 'yetone-openai-translator' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { containerTagName, popupCardID, popupThumbID, zIndex } from './consts' | ||
|
||
export async function getContainer(): Promise<HTMLElement> { | ||
let $container: HTMLElement | null = document.querySelector(containerTagName) | ||
if (!$container) { | ||
$container = document.createElement(containerTagName) | ||
$container.style.zIndex = zIndex | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
const $container_: HTMLElement | null = document.querySelector(containerTagName) | ||
if ($container_) { | ||
resolve($container_) | ||
return | ||
} | ||
const $html = document.body.parentElement | ||
if ($html) { | ||
$html.appendChild($container as HTMLElement) | ||
} else { | ||
document.appendChild($container as HTMLElement) | ||
} | ||
resolve($container as HTMLElement) | ||
}, 100) | ||
}) | ||
} | ||
return new Promise((resolve) => { | ||
resolve($container as HTMLElement) | ||
}) | ||
} | ||
|
||
export async function queryPopupThumbElement(): Promise<HTMLDivElement | null> { | ||
const $container = await getContainer() | ||
return $container.shadowRoot?.getElementById(popupThumbID) as HTMLDivElement | null | ||
} | ||
|
||
export async function queryPopupCardElement(): Promise<HTMLDivElement | null> { | ||
const $container = await getContainer() | ||
return $container.shadowRoot?.getElementById(popupCardID) as HTMLDivElement | null | ||
} |
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 |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
"jsx": "react", | ||
"typeRoots": [ "node_modules/@types" ] | ||
} | ||
} | ||
} |
Oops, something went wrong.