fix css not being applied to iframes

This commit is contained in:
SethBurkart123
2023-12-20 15:01:48 +11:00
parent 4d143992ef
commit af5bf969f9
2 changed files with 50 additions and 72 deletions
+40 -66
View File
@@ -402,74 +402,47 @@ function removeThemeTagsFromNotices () {
} }
} }
function CheckiFrameItems() { async function updateIframesWithDarkMode(): Promise<void> {
// Injecting CSS File to the webpage to overwrite iFrame default CSS // Load the CSS file to overwrite iFrame default CSS
const fileref = document.createElement('link') const cssLink = document.createElement('style');
fileref.setAttribute('rel', 'stylesheet') const cssContent = document.createTextNode(iframeCSS);
fileref.setAttribute('type', 'text/css') cssLink.appendChild(cssContent);
fileref.innerHTML = iframeCSS
const observer = new MutationObserver(function (mutations_list) { const observer = new MutationObserver(async (mutationsList) => {
mutations_list.forEach(function (mutation) { for (const mutation of mutationsList) {
mutation.addedNodes.forEach(function (added_node) { for (const node of mutation.addedNodes) {
const node = added_node as HTMLElement if (node.nodeName === 'IFRAME') {
if (node.tagName == 'IFRAME') { const iframe = node as HTMLIFrameElement;
const result = browser.storage.local.get('DarkMode') as Promise<SettingsState>; try {
function open (result: any) { const settings = await browser.storage.local.get('DarkMode') as SettingsState;
DarkMode = result.DarkMode; if (settings.DarkMode) {
const node = added_node as HTMLIFrameElement //await delay(1);
if (DarkMode) { applyDarkModeToIframe(iframe, cssLink);
RunColourCheck(node);
const childNode = node.contentDocument!.documentElement.childNodes[1] as HTMLElement
if (
childNode.style
.color != 'white'
) {
childNode.style.color =
'white';
}
const innerHTMLNode = node.contentDocument!.documentElement.firstChild! as HTMLElement
if (
!innerHTMLNode.innerHTML.includes(
'iframe.css',
)
) {
innerHTMLNode.append(
fileref,
);
}
node.addEventListener('load', function () {
const childNode = node.contentDocument!.documentElement.childNodes[1] as HTMLElement
const innerHTMLNode = node.contentDocument!.documentElement.firstChild! as HTMLElement
if (
childNode.style
.color != 'white'
) {
childNode.style.color =
'white';
}
if (
!innerHTMLNode.innerHTML.includes(
'iframe.css',
)
) {
innerHTMLNode.append(
fileref,
);
}
});
} }
} catch (error) {
console.error('Error applying dark mode:', error);
} }
result.then(open, onError)
} }
}); }
}); }
}); });
observer.observe(document.body, { observer.observe(document.body, { subtree: true, childList: true });
subtree: true, }
childList: true,
}); function applyDarkModeToIframe(iframe: HTMLIFrameElement, cssLink: HTMLStyleElement): void {
const iframeDocument = iframe.contentDocument;
if (!iframeDocument) return;
const body = iframeDocument.body;
if (body && body.style.color !== 'white') {
body.style.color = 'white';
}
const head = iframeDocument.head;
if (head && !head.innerHTML.includes('iframe.css')) {
head.appendChild(cssLink);
}
} }
function SortMessagePageItems(messagesParentElement: any) { function SortMessagePageItems(messagesParentElement: any) {
@@ -612,7 +585,7 @@ export function tryLoad() {
document.addEventListener( document.addEventListener(
'load', 'load',
function () { function () {
CheckiFrameItems(); updateIframesWithDarkMode();
removeThemeTagsFromNotices(); removeThemeTagsFromNotices();
documentTextColor(); documentTextColor();
}, },
@@ -1639,14 +1612,15 @@ function callHomeTimetable(date: string, change?: any) {
}); });
} }
} else { } else {
if (DayContainer.innerHTML || change) { console.log(DayContainer);
DayContainer.innerHTML = ''; if (DayContainer.innerText || change) {
DayContainer.innerText = '';
var dummyDay = document.createElement('div'); var dummyDay = document.createElement('div');
dummyDay.classList.add('day-empty'); dummyDay.classList.add('day-empty');
let img = document.createElement('img'); let img = document.createElement('img');
img.src = browser.runtime.getURL('icons/betterseqta-light-icon.png'); img.src = browser.runtime.getURL('icons/betterseqta-light-icon.png');
let text = document.createElement('p'); let text = document.createElement('p');
text.innerHTML = 'No lessons available.'; text.innerText = 'No lessons available.';
dummyDay.append(img); dummyDay.append(img);
dummyDay.append(text); dummyDay.append(text);
DayContainer.append(dummyDay); DayContainer.append(dummyDay);
+10 -6
View File
@@ -26,14 +26,18 @@ body {
blockquote.forward > .preamble { blockquote.forward > .preamble {
color: rgba(255, 255, 255, 0.7) !important; color: rgba(255, 255, 255, 0.7) !important;
> .date > .value, blockquote.forward > .preamble > .sender > .value {
color: rgba(255, 255, 255, 0.7) !important;
}
> .date > .label, blockquote.forward > .preamble > .sender > .label {
color: rgba(255, 255, 255, 0.7) !important;
}
} }
blockquote.forward > .preamble > .date > .value, blockquote.forward > .preamble > .sender > .value { [bgcolor="#ffffff"] {
color: rgba(255, 255, 255, 0.7) !important; color: black;
}
blockquote.forward > .preamble > .date > .label, blockquote.forward > .preamble > .sender > .label {
color: rgba(255, 255, 255, 0.7) !important;
} }
table th { table th {