Implement clickable plaintext links and dark mode fix (#488)
* Plaintext links are now clickable and fixes dark mode. - Change `AppxPackageDir` path from `C:\Users\bkaan\Desktop\Packages\` to `$(USERPROFILE)\Desktop\Packages\`, fixes error when building release. - Plaintext links are now clickable, and match the same subtle style as Windows Mail. - Remove `!important` from inline styles to allow Dark Reader to properly recolor the element. * Implement setting for clickable plaintext link
This commit is contained in:
1
Wino.Mail/JS/libs/linkify-element.min.js
vendored
Normal file
1
Wino.Mail/JS/libs/linkify-element.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var linkifyElement=function(e){"use strict";const t=1,n=3;function r(e,t,n){let r=n[n.length-1];e.replaceChild(r,t);for(let t=n.length-2;t>=0;t--)e.insertBefore(n[t],r),r=n[t]}function i(e,t,n){const r=[];for(let i=0;i<e.length;i++){const o=e[i];"nl"===o.t&&t.get("nl2br")?r.push(n.createElement("br")):o.isLink&&t.check(o)?r.push(t.render(o)):r.push(n.createTextNode(o.toString()))}return r}function o(l,a,c){if(!l||l.nodeType!==t)throw new Error(`Cannot linkify ${l} - Invalid DOM Node type`);if("A"===l.tagName||a.ignoreTags.indexOf(l.tagName)>=0)return l;let s=l.firstChild;for(;s;){let d,u,f;switch(s.nodeType){case t:o(s,a,c);break;case n:if(d=s.nodeValue,u=e.tokenize(d),0===u.length||1===u.length&&"text"===u[0].t)break;f=i(u,a,c),r(l,s,f),s=f[f.length-1]}s=s.nextSibling}return l}function l(e){return t=>{let{tagName:n,attributes:r,content:i,eventListeners:o}=t;const l=e.createElement(n);for(const e in r)l.setAttribute(e,r[e]);if(o&&l.addEventListener)for(const e in o)l.addEventListener(e,o[e]);return l.appendChild(e.createTextNode(i)),l}}function a(t,n,r){void 0===n&&(n=null),void 0===r&&(r=null);try{r=r||document||window&&window.document||global&&global.document}catch(e){}if(!r)throw new Error("Cannot find document implementation. If you are in a non-browser environment like Node.js, pass the document implementation as the third argument to linkifyElement.");return o(t,new e.Options(n,l(r)),r)}return a.helper=o,a.getDefaultRender=l,a.normalize=(t,n)=>new e.Options(t,l(n)),a}(linkify);
|
||||
1
Wino.Mail/JS/libs/linkify.min.js
vendored
Normal file
1
Wino.Mail/JS/libs/linkify.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,52 +1,111 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="./global.css" />
|
||||
<script src="./libs/darkreader.js"></script>
|
||||
<style>
|
||||
body {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
margin: 0px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
<head>
|
||||
<link rel="stylesheet" href="./global.css" />
|
||||
<script src="./libs/darkreader.js"></script>
|
||||
|
||||
#readerDiv {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: transparent !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<meta name="color-scheme" content="dark light">
|
||||
<script>
|
||||
function RenderHTML(htmlString) {
|
||||
window.scroll(0, 0);
|
||||
var containerDiv = document.getElementById("readerDiv");
|
||||
containerDiv.innerHTML = htmlString;
|
||||
}
|
||||
<script src="./libs/linkify.min.js"></script>
|
||||
<script src="./libs/linkify-element.min.js"></script>
|
||||
|
||||
function ChangeFontFamily(fontFamily) {
|
||||
var containerDiv = document.getElementById("readerDiv");
|
||||
containerDiv.style.fontFamily = fontFamily;
|
||||
}
|
||||
<style>
|
||||
body {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
padding-top: 8px;
|
||||
padding-bottom: 8px;
|
||||
margin: 0px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
function ChangeFontSize(size) {
|
||||
var containerDiv = document.getElementById("readerDiv");
|
||||
containerDiv.style.fontSize = size;
|
||||
}
|
||||
#readerDiv {
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
function SetLightEditor() {
|
||||
document.documentElement.setAttribute('data-theme', 'light');
|
||||
DarkReader.disable();
|
||||
}
|
||||
a.wino-plain-link {
|
||||
color: inherit !important;
|
||||
text-decoration: underline dotted !important;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<meta name="color-scheme" content="dark light" />
|
||||
<script>
|
||||
var _htmlString = "";
|
||||
var _shouldLinkifyText = true;
|
||||
|
||||
function SetDarkEditor() {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
DarkReader.enable();
|
||||
}
|
||||
</script>
|
||||
<div id="readerDiv"></div>
|
||||
</body>
|
||||
// Called when rendering a new email for the first time
|
||||
function RenderHTML(htmlString, shouldLinkifyText = true) {
|
||||
window.scroll(0, 0);
|
||||
|
||||
_htmlString = htmlString;
|
||||
_shouldLinkifyText = shouldLinkifyText;
|
||||
|
||||
internalRenderHTML(htmlString);
|
||||
}
|
||||
|
||||
// Called to render or refresh the email
|
||||
function internalRenderHTML(htmlString) {
|
||||
var containerDiv = document.getElementById("readerDiv");
|
||||
try {
|
||||
containerDiv.innerHTML = htmlString;
|
||||
|
||||
// Linkify plain text links if enabled
|
||||
if (_shouldLinkifyText) {
|
||||
linkifyElement(
|
||||
containerDiv,
|
||||
{ className: "wino-plain-link" },
|
||||
document
|
||||
);
|
||||
}
|
||||
|
||||
// Remove !important from inline styles if dark mode is enabled
|
||||
if (
|
||||
document.documentElement.getAttribute("data-theme") ===
|
||||
"dark"
|
||||
) {
|
||||
removeImportantFromInlineStyles();
|
||||
}
|
||||
} catch (e) {
|
||||
containerDiv.innerHTML = htmlString;
|
||||
}
|
||||
}
|
||||
|
||||
function ChangeFontFamily(fontFamily) {
|
||||
var containerDiv = document.getElementById("readerDiv");
|
||||
containerDiv.style.fontFamily = fontFamily;
|
||||
}
|
||||
|
||||
function ChangeFontSize(size) {
|
||||
var containerDiv = document.getElementById("readerDiv");
|
||||
containerDiv.style.fontSize = size;
|
||||
}
|
||||
|
||||
function SetLightEditor() {
|
||||
document.documentElement.setAttribute("data-theme", "light");
|
||||
DarkReader.disable();
|
||||
|
||||
internalRenderHTML(_htmlString);
|
||||
}
|
||||
|
||||
function SetDarkEditor() {
|
||||
document.documentElement.setAttribute("data-theme", "dark");
|
||||
DarkReader.enable();
|
||||
|
||||
internalRenderHTML(_htmlString);
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
function removeImportantFromInlineStyles() {
|
||||
var allElements = document.querySelectorAll("*");
|
||||
allElements.forEach(function (element) {
|
||||
var style = element.getAttribute("style");
|
||||
if (style) {
|
||||
var newStyle = style.replace(/!important/g, "");
|
||||
element.setAttribute("style", newStyle);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<div id="readerDiv"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user