refactoring, using different pattern for page injection and reusing same pattern for both popup and content scripts

This commit is contained in:
Sriram Hariharan
2023-03-03 21:13:43 -06:00
parent 4ed52a3c9f
commit beb61176c1
18 changed files with 120 additions and 95 deletions

37
src/views/index.tsx Normal file
View File

@@ -0,0 +1,37 @@
import React from 'react';
import { render } from 'react-dom';
import { ContextInvalidated, createShadowDOM, isExtensionPopup, onContextInvalidated } from 'chrome-extension-toolkit';
import CourseCatalogMain from './components/CourseCatalogMain';
import colors from './styles/colors.module.scss';
import getSiteSupport, { SiteSupport } from './lib/getSiteSupport';
import PopupMain from './components/PopupMain';
const support = getSiteSupport(window.location.href);
if (isExtensionPopup()) {
render(<PopupMain />, document.getElementById('root'));
}
if (support.includes(SiteSupport.COURSE_CATALOG)) {
const shadowDom = createShadowDOM('ut-registration-plus-dom-container');
render(<CourseCatalogMain support={support} />, shadowDom.shadowRoot);
shadowDom.addStyle('static/css/content.css');
}
if (support.includes(SiteSupport.WAITLIST)) {
// TODO: Implement waitlist support
}
if (support.includes(SiteSupport.UT_PLANNER)) {
// TODO: Implement ut planner support
}
onContextInvalidated(() => {
const div = document.createElement('div');
div.id = 'context-invalidated-container';
document.body.appendChild(div);
render(
<ContextInvalidated fontFamily='monospace' color={colors.WHITE} backgroundColor={colors.BURNT_ORANGE} />,
div
);
});