fix: iframe theming

This commit is contained in:
SethBurkart123
2024-01-26 14:24:03 +11:00
parent 5e01611d7c
commit c11444a66f
5 changed files with 101 additions and 98 deletions
+2 -2
View File
@@ -15,10 +15,10 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@parcel/config-webextension": "^2.10.3", "@parcel/config-webextension": "^2.11.0",
"@parcel/optimizer-data-url": "^2.11.0", "@parcel/optimizer-data-url": "^2.11.0",
"@parcel/transformer-inline-string": "^2.11.0", "@parcel/transformer-inline-string": "^2.11.0",
"@parcel/transformer-sass": "^2.11.0", "@parcel/transformer-sass": "2.11.0",
"assert": "^2.0.0", "assert": "^2.0.0",
"browserify-zlib": "^0.2.0", "browserify-zlib": "^0.2.0",
"crypto-browserify": "^3.12.0", "crypto-browserify": "^3.12.0",
+8 -12
View File
@@ -24,10 +24,10 @@ import browser from 'webextension-polyfill'
import coursesicon from './seqta/icons/coursesIcon' import coursesicon from './seqta/icons/coursesIcon'
import { delay } from "./seqta/utils/delay" import { delay } from "./seqta/utils/delay"
import { enableCurrentTheme } from './seqta/ui/Themes' import { enableCurrentTheme } from './seqta/ui/Themes'
import iframeCSS from "url:./css/iframe.scss" import iframeCSS from "bundle-text:./css/iframe.scss"
import { onError } from './seqta/utils/onError' import { onError } from './seqta/utils/onError'
import stringToHTML from './seqta/utils/stringToHTML' import stringToHTML from './seqta/utils/stringToHTML'
import { updateAllColors } from './seqta/ui/colors/Manager' import { getDarkMode, updateAllColors } from './seqta/ui/colors/Manager'
import { updateBgDurations } from './seqta/ui/Animation' import { updateBgDurations } from './seqta/ui/Animation'
declare global { declare global {
@@ -413,6 +413,7 @@ function removeThemeTagsFromNotices () {
async function updateIframesWithDarkMode(): Promise<void> { async function updateIframesWithDarkMode(): Promise<void> {
// Load the CSS file to overwrite iFrame default CSS // Load the CSS file to overwrite iFrame default CSS
const cssLink = document.createElement('style') const cssLink = document.createElement('style')
cssLink.classList.add('iframecss')
const cssContent = document.createTextNode(iframeCSS) const cssContent = document.createTextNode(iframeCSS)
cssLink.appendChild(cssContent) cssLink.appendChild(cssContent)
@@ -423,16 +424,14 @@ async function updateIframesWithDarkMode(): Promise<void> {
const iframe = node as HTMLIFrameElement const iframe = node as HTMLIFrameElement
try { try {
const settings = await browser.storage.local.get('DarkMode') as SettingsState const settings = await browser.storage.local.get('DarkMode') as SettingsState
if (settings.DarkMode) { applyDarkModeToIframe(iframe, cssLink, settings.DarkMode);
applyDarkModeToIframe(iframe, cssLink)
}
} catch (error) { } catch (error) {
console.error('Error applying dark mode:', error) console.error('Error applying dark mode:', error)
} }
} }
} }
} }
}) });
if (document.body) { if (document.body) {
observer.observe(document.body, { observer.observe(document.body, {
@@ -449,17 +448,14 @@ async function updateIframesWithDarkMode(): Promise<void> {
} }
} }
function applyDarkModeToIframe(iframe: HTMLIFrameElement, cssLink: HTMLStyleElement): void { function applyDarkModeToIframe(iframe: HTMLIFrameElement, cssLink: HTMLStyleElement, DarkMode: boolean): void {
const iframeDocument = iframe.contentDocument const iframeDocument = iframe.contentDocument
if (!iframeDocument) return if (!iframeDocument) return
const body = iframeDocument.body if (DarkMode) iframeDocument.body.classList.add('dark')
if (body && body.style.color !== 'white') {
body.style.color = 'white'
}
const head = iframeDocument.head const head = iframeDocument.head
if (head && !head.innerHTML.includes('iframe.css')) { if (head && !head.innerHTML.includes('iframecss')) {
head.appendChild(cssLink) head.appendChild(cssLink)
} }
} }
+86 -76
View File
@@ -15,89 +15,99 @@
* along with EvenBetterSEQTA. If not, see <https://www.gnu.org/licenses/>. * along with EvenBetterSEQTA. If not, see <https://www.gnu.org/licenses/>.
*/ */
html, p, div, span { body {
color: white !important; background: transparent;
text-shadow: 1px 1px 2px #161616, 0 0 1em #161616;
} }
body { .dark {
background-color: transparent !important; p,
} div,
span {
color: white !important;
text-shadow: 1px 1px 2px #161616, 0 0 1em #161616;
}
blockquote.forward > .preamble { body {
color: rgba(255, 255, 255, 0.7) !important; background-color: transparent !important;
}
> .date > .value, blockquote.forward > .preamble > .sender > .value {
blockquote.forward > .preamble {
color: rgba(255, 255, 255, 0.7) !important;
> p,
div,
span {
background: transparent !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;
}
}
[bgcolor="#ffffff"] > * {
color: black !important;
text-shadow: none !important;
}
table th {
background-color: #161616;
}
::-webkit-scrollbar {
width: 10px;
height: 10px;
transition: 1s;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
::-webkit-scrollbar-thumb {
border-radius: 10rem !important;
}
::-webkit-scrollbar-corner {
background: none;
}
.forward {
border-radius: 1rem;
}
.preamble {
border-top-left-radius: 1rem;
border-top-right-radius: 1rem;
}
blockquote.forward > .preamble {
color: rgba(255, 255, 255, 0.7) !important; color: rgba(255, 255, 255, 0.7) !important;
} }
> .date > .label, blockquote.forward > .preamble > .sender > .label { blockquote.forward > .preamble > .date > .value,
blockquote.forward > .preamble > .sender > .value {
color: rgba(255, 255, 255, 0.7) !important;
}
blockquote.forward > .preamble > .date > .label,
blockquote.forward > .preamble > .sender > .label {
color: rgba(255, 255, 255, 0.7) !important; color: rgba(255, 255, 255, 0.7) !important;
} }
}
[bgcolor="#ffffff"] { #backgroundTable > * {
color: black; background-color: #161616;
} border: none;
}
table th { .userHTML > div > a:not(.resource) {
background-color: #161616; color: #06b4fc;
} text-decoration: underline;
transition: text-shadow 0.5s;
::-webkit-scrollbar { }
width: 10px;
height: 10px;
transition: 1s;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
::-webkit-scrollbar-thumb {
border-radius: 10rem !important;
}
::-webkit-scrollbar-corner {
background: none;
}
.forward {
border-radius: 1rem;
}
.preamble {
border-top-left-radius: 1rem;
border-top-right-radius: 1rem;
}
html, p, div, span {
color: white !important;
background-color: #232323
}
body {
background-color: #232323;
}
blockquote.forward > .preamble {
color: rgba(255, 255, 255, 0.7) !important;
}
blockquote.forward > .preamble > .date > .value,
blockquote.forward > .preamble > .sender > .value {
color: rgba(255, 255, 255, 0.7) !important;
}
blockquote.forward > .preamble > .date > .label,
blockquote.forward > .preamble > .sender > .label {
color: rgba(255, 255, 255, 0.7) !important;
}
#backgroundTable > * {
background-color: #161616;
border: none;
}
.userHTML>div>a:not(.resource) {
color: #06b4fc;
text-decoration: underline;
transition: text-shadow 0.5s;
} }
-1
View File
@@ -1 +0,0 @@
import './iframe.scss';
+5 -7
View File
@@ -6,7 +6,6 @@ import { SettingsState } from '../../../types/storage';
import darkLogo from 'url:../../../resources/icons/betterseqta-light-full.png'; import darkLogo from 'url:../../../resources/icons/betterseqta-light-full.png';
import lightLogo from 'url:../../../resources/icons/betterseqta-dark-full.png'; import lightLogo from 'url:../../../resources/icons/betterseqta-dark-full.png';
import iFrameCSS from 'url:../../../css/iframe.scss';
// Helper functions // Helper functions
const setCSSVar = (varName: any, value: any) => document.documentElement.style.setProperty(varName, value); const setCSSVar = (varName: any, value: any) => document.documentElement.style.setProperty(varName, value);
@@ -71,7 +70,6 @@ export function updateAllColors(storedSetting: any, newColor = null) {
} }
let alliframes = document.getElementsByTagName('iframe'); let alliframes = document.getElementsByTagName('iframe');
let fileref = iFrameCSS;
for (let i = 0; i < alliframes.length; i++) { for (let i = 0; i < alliframes.length; i++) {
const element = alliframes[i]; const element = alliframes[i];
@@ -80,11 +78,11 @@ export function updateAllColors(storedSetting: any, newColor = null) {
continue; continue;
} }
(element.contentDocument!.documentElement.childNodes[1] as HTMLIFrameElement).style.color = if (DarkMode) {
DarkMode ? 'white' : 'black'; element.contentDocument?.body.classList.add('dark');
element.contentDocument!.documentElement.firstChild!.appendChild( } else {
fileref, element.contentDocument?.body.classList.remove('dark');
); }
} }
} }