diff options
| author | Bobby <[email protected]> | 2025-12-29 10:46:00 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-12-29 10:46:00 +0530 |
| commit | f59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8 (patch) | |
| tree | 1123c3d0785a44261151bc46f2b38a4db9eb57b7 /static/js/shadow.js | |
| parent | cccf44496a056d15d5d86d9fbd74633f21e852bb (diff) | |
| download | lain-f59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8.tar.xz lain-f59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8.zip | |
feat: Enhance email viewer with new UI actions, sender profile pictures, and raw header display.
Diffstat (limited to 'static/js/shadow.js')
| -rw-r--r-- | static/js/shadow.js | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/static/js/shadow.js b/static/js/shadow.js index 03d23cf..20c35e1 100644 --- a/static/js/shadow.js +++ b/static/js/shadow.js @@ -1,5 +1,5 @@ const ShadowRenderer = { - render: function (hostElement, htmlContent, options = {}) { + render: function (hostElement, htmlContent) { let shadow = hostElement.shadowRoot; if (!shadow) { shadow = hostElement.attachShadow({ mode: 'open' }); @@ -8,40 +8,32 @@ const ShadowRenderer = { const parser = new DOMParser(); const doc = parser.parseFromString(htmlContent, 'text/html'); - const styles = doc.querySelectorAll('style'); - styles.forEach(style => { - style.textContent = style.textContent.replace(/(^|[\}\s,;])body(?=[\s,\.\{])/gi, '$1.mail-body-content'); - }); - - const wrapper = document.createElement('div'); - wrapper.className = 'mail-body-content'; + shadow.innerHTML = ''; - if (doc.body) { - Array.from(doc.body.attributes).forEach(attr => { - if (attr.name === 'class') { - if (attr.value) wrapper.classList.add(...attr.value.split(' ')); - } else { - wrapper.setAttribute(attr.name, attr.value); - } + if (doc.head) { + doc.head.querySelectorAll('style').forEach(style => { + const styleClone = style.cloneNode(true); + let css = styleClone.textContent; + css = css.replace(/\bbody\b/g, ':host'); + styleClone.textContent = css; + shadow.appendChild(styleClone); }); - if (doc.body.bgColor) wrapper.style.backgroundColor = doc.body.bgColor; - while (doc.body.firstChild) wrapper.appendChild(doc.body.firstChild); + doc.head.querySelectorAll('link[rel="stylesheet"]').forEach(link => { + shadow.appendChild(link.cloneNode(true)); + }); } - shadow.innerHTML = ''; - if (doc.head) { - while (doc.head.firstChild) shadow.appendChild(doc.head.firstChild); + if (doc.body) { + while (doc.body.firstChild) { + shadow.appendChild(doc.body.firstChild); + } } - shadow.appendChild(wrapper); - const defaultStyle = document.createElement('style'); - defaultStyle.textContent = ` - :host { display: block; overflow: auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } - img { max-width: 100%; height: auto; } - a { color: #1a73e8; } - `; - shadow.prepend(defaultStyle); + + setTimeout(() => { + EmailUtils.adjustContrast(shadow); + }, 100); return shadow; } -}; +};
\ No newline at end of file |
