Tweak CSS injector for darkmode
This commit is contained in:
parent
b4dfce8e80
commit
a271bf05d5
2 changed files with 44 additions and 24 deletions
22
Form1.Designer.cs
generated
22
Form1.Designer.cs
generated
|
@ -53,6 +53,7 @@
|
||||||
groupBox3 = new GroupBox();
|
groupBox3 = new GroupBox();
|
||||||
button2 = new Button();
|
button2 = new Button();
|
||||||
textBox2 = new TextBox();
|
textBox2 = new TextBox();
|
||||||
|
fullUIToolStripMenuItem = new ToolStripMenuItem();
|
||||||
menuStrip1.SuspendLayout();
|
menuStrip1.SuspendLayout();
|
||||||
groupBox4.SuspendLayout();
|
groupBox4.SuspendLayout();
|
||||||
groupBox3.SuspendLayout();
|
groupBox3.SuspendLayout();
|
||||||
|
@ -78,30 +79,29 @@
|
||||||
// openDevToolsToolStripMenuItem
|
// openDevToolsToolStripMenuItem
|
||||||
//
|
//
|
||||||
openDevToolsToolStripMenuItem.Name = "openDevToolsToolStripMenuItem";
|
openDevToolsToolStripMenuItem.Name = "openDevToolsToolStripMenuItem";
|
||||||
openDevToolsToolStripMenuItem.Size = new Size(180, 22);
|
openDevToolsToolStripMenuItem.Size = new Size(154, 22);
|
||||||
openDevToolsToolStripMenuItem.Text = "Open DevTools";
|
openDevToolsToolStripMenuItem.Text = "Open DevTools";
|
||||||
openDevToolsToolStripMenuItem.Click += openDevToolsToolStripMenuItem_Click_1;
|
openDevToolsToolStripMenuItem.Click += openDevToolsToolStripMenuItem_Click_1;
|
||||||
//
|
//
|
||||||
// exitToolStripMenuItem
|
// exitToolStripMenuItem
|
||||||
//
|
//
|
||||||
exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||||
exitToolStripMenuItem.Size = new Size(180, 22);
|
exitToolStripMenuItem.Size = new Size(154, 22);
|
||||||
exitToolStripMenuItem.Text = "Exit";
|
exitToolStripMenuItem.Text = "Exit";
|
||||||
exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
|
exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// renderToolStripMenuItem
|
// renderToolStripMenuItem
|
||||||
//
|
//
|
||||||
renderToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { fontFamilyToolStripMenuItem, colorThemeToolStripMenuItem });
|
renderToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { fontFamilyToolStripMenuItem, colorThemeToolStripMenuItem, fullUIToolStripMenuItem });
|
||||||
renderToolStripMenuItem.Name = "renderToolStripMenuItem";
|
renderToolStripMenuItem.Name = "renderToolStripMenuItem";
|
||||||
renderToolStripMenuItem.Size = new Size(56, 20);
|
renderToolStripMenuItem.Size = new Size(56, 20);
|
||||||
renderToolStripMenuItem.Text = "Render";
|
renderToolStripMenuItem.Text = "Render";
|
||||||
renderToolStripMenuItem.Click += renderToolStripMenuItem_Click;
|
|
||||||
//
|
//
|
||||||
// fontFamilyToolStripMenuItem
|
// fontFamilyToolStripMenuItem
|
||||||
//
|
//
|
||||||
fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem });
|
fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem });
|
||||||
fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem";
|
fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem";
|
||||||
fontFamilyToolStripMenuItem.Size = new Size(180, 22);
|
fontFamilyToolStripMenuItem.Size = new Size(140, 22);
|
||||||
fontFamilyToolStripMenuItem.Text = "Font Family";
|
fontFamilyToolStripMenuItem.Text = "Font Family";
|
||||||
//
|
//
|
||||||
// serifToolStripMenuItem
|
// serifToolStripMenuItem
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
//
|
//
|
||||||
colorThemeToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { systemToolStripMenuItem, lightToolStripMenuItem, darkToolStripMenuItem });
|
colorThemeToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { systemToolStripMenuItem, lightToolStripMenuItem, darkToolStripMenuItem });
|
||||||
colorThemeToolStripMenuItem.Name = "colorThemeToolStripMenuItem";
|
colorThemeToolStripMenuItem.Name = "colorThemeToolStripMenuItem";
|
||||||
colorThemeToolStripMenuItem.Size = new Size(180, 22);
|
colorThemeToolStripMenuItem.Size = new Size(140, 22);
|
||||||
colorThemeToolStripMenuItem.Text = "Color theme";
|
colorThemeToolStripMenuItem.Text = "Color theme";
|
||||||
//
|
//
|
||||||
// systemToolStripMenuItem
|
// systemToolStripMenuItem
|
||||||
|
@ -272,6 +272,15 @@
|
||||||
textBox2.TabIndex = 2;
|
textBox2.TabIndex = 2;
|
||||||
textBox2.TextChanged += textBox2_TextChanged;
|
textBox2.TextChanged += textBox2_TextChanged;
|
||||||
//
|
//
|
||||||
|
// fullUIToolStripMenuItem
|
||||||
|
//
|
||||||
|
fullUIToolStripMenuItem.Checked = true;
|
||||||
|
fullUIToolStripMenuItem.CheckOnClick = true;
|
||||||
|
fullUIToolStripMenuItem.CheckState = CheckState.Checked;
|
||||||
|
fullUIToolStripMenuItem.Name = "fullUIToolStripMenuItem";
|
||||||
|
fullUIToolStripMenuItem.Size = new Size(140, 22);
|
||||||
|
fullUIToolStripMenuItem.Text = "Full UI";
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
@ -322,5 +331,6 @@
|
||||||
private ToolStripMenuItem serifToolStripMenuItem;
|
private ToolStripMenuItem serifToolStripMenuItem;
|
||||||
private ToolStripMenuItem sansSerifToolStripMenuItem;
|
private ToolStripMenuItem sansSerifToolStripMenuItem;
|
||||||
private ToolStripMenuItem forceMonospaceToolStripMenuItem;
|
private ToolStripMenuItem forceMonospaceToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem fullUIToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
46
Form1.cs
46
Form1.cs
|
@ -10,8 +10,6 @@ namespace MintHTML
|
||||||
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
string appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||||
string markfile;
|
string markfile;
|
||||||
string htmlfile = "<h1>Welcome to MintHTML</h1><p>Open a markdown file and press \"Render preview\" to see the output here.</p>";
|
string htmlfile = "<h1>Welcome to MintHTML</h1><p>Open a markdown file and press \"Render preview\" to see the output here.</p>";
|
||||||
string csssuffix = @"
|
|
||||||
</style>";
|
|
||||||
string logo = @"<svg
|
string logo = @"<svg
|
||||||
width=""25mm""
|
width=""25mm""
|
||||||
height=""25mm""
|
height=""25mm""
|
||||||
|
@ -165,6 +163,7 @@ namespace MintHTML
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
";
|
";
|
||||||
|
string css2 = "\n</style>";
|
||||||
string css;
|
string css;
|
||||||
bool extraInstance = false;
|
bool extraInstance = false;
|
||||||
int extraNum = 0;
|
int extraNum = 0;
|
||||||
|
@ -173,6 +172,10 @@ namespace MintHTML
|
||||||
{
|
{
|
||||||
htmlfile = Markdown.ToHtml(markfile);
|
htmlfile = Markdown.ToHtml(markfile);
|
||||||
}
|
}
|
||||||
|
private void cssreload()
|
||||||
|
{
|
||||||
|
chromiumWebBrowser1.LoadHtml(css + css2 + htmlfile);
|
||||||
|
}
|
||||||
// Custom functions end
|
// Custom functions end
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
|
@ -205,9 +208,9 @@ namespace MintHTML
|
||||||
css = @"<style>
|
css = @"<style>
|
||||||
html{
|
html{
|
||||||
font-family: sans-serif
|
font-family: sans-serif
|
||||||
}" + csssuffix;
|
}";
|
||||||
htmlfile = "<center>" + logo + htmlfile;
|
htmlfile = "<center>" + logo + htmlfile;
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
cssreload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -223,7 +226,7 @@ font-family: sans-serif
|
||||||
{
|
{
|
||||||
markfile = File.ReadAllText(textBox2.Text);
|
markfile = File.ReadAllText(textBox2.Text);
|
||||||
convert();
|
convert();
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
cssreload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +243,7 @@ font-family: sans-serif
|
||||||
if (MessageBox.Show("Do you want to convert the rendering settings to CSS?", "Converter", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show("Do you want to convert the rendering settings to CSS?", "Converter", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
convert();
|
convert();
|
||||||
File.WriteAllText(Saver.FileName, css + htmlfile);
|
File.WriteAllText(Saver.FileName, "<style>\n" + css + css2 + htmlfile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -248,7 +251,7 @@ font-family: sans-serif
|
||||||
File.WriteAllText(Saver.FileName, htmlfile);
|
File.WriteAllText(Saver.FileName, htmlfile);
|
||||||
}
|
}
|
||||||
MessageBox.Show("Save complete.", "Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Save complete.", "Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
cssreload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,11 +290,12 @@ font-family: sans-serif
|
||||||
css = @"<style>
|
css = @"<style>
|
||||||
html{
|
html{
|
||||||
font-family: serif
|
font-family: serif
|
||||||
}" + csssuffix;
|
}
|
||||||
|
";
|
||||||
sansSerifToolStripMenuItem.Checked = false;
|
sansSerifToolStripMenuItem.Checked = false;
|
||||||
forceMonospaceToolStripMenuItem.Checked = false;
|
forceMonospaceToolStripMenuItem.Checked = false;
|
||||||
serifToolStripMenuItem.Checked = true;
|
serifToolStripMenuItem.Checked = true;
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
cssreload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void groupBox4_Enter(object sender, EventArgs e)
|
private void groupBox4_Enter(object sender, EventArgs e)
|
||||||
|
@ -304,11 +308,12 @@ font-family: serif
|
||||||
css = @"<style>
|
css = @"<style>
|
||||||
html{
|
html{
|
||||||
font-family: sans-serif
|
font-family: sans-serif
|
||||||
}" + csssuffix;
|
}
|
||||||
|
";
|
||||||
sansSerifToolStripMenuItem.Checked = true;
|
sansSerifToolStripMenuItem.Checked = true;
|
||||||
forceMonospaceToolStripMenuItem.Checked = false;
|
forceMonospaceToolStripMenuItem.Checked = false;
|
||||||
serifToolStripMenuItem.Checked = false;
|
serifToolStripMenuItem.Checked = false;
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
cssreload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forceMonospaceToolStripMenuItem_Click(object sender, EventArgs e)
|
private void forceMonospaceToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -316,11 +321,12 @@ font-family: sans-serif
|
||||||
css = @"<style>
|
css = @"<style>
|
||||||
html{
|
html{
|
||||||
font-family: monospace
|
font-family: monospace
|
||||||
}" + csssuffix;
|
}
|
||||||
|
";
|
||||||
sansSerifToolStripMenuItem.Checked = false;
|
sansSerifToolStripMenuItem.Checked = false;
|
||||||
forceMonospaceToolStripMenuItem.Checked = true;
|
forceMonospaceToolStripMenuItem.Checked = true;
|
||||||
serifToolStripMenuItem.Checked = false;
|
serifToolStripMenuItem.Checked = false;
|
||||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
cssreload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
@ -333,10 +339,6 @@ font-family: monospace
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderToolStripMenuItem_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
|
private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!(chromiumWebBrowser1.Address.Substring(0, 5) == "data:"))
|
if (!(chromiumWebBrowser1.Address.Substring(0, 5) == "data:"))
|
||||||
|
@ -352,7 +354,15 @@ font-family: monospace
|
||||||
|
|
||||||
private void darkToolStripMenuItem_Click(object sender, EventArgs e)
|
private void darkToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
chromiumWebBrowser1.GetDevToolsClient().Emulation.SetAutoDarkModeOverrideAsync(true);
|
css2 = @"
|
||||||
|
html{
|
||||||
|
color-scheme: dark;
|
||||||
|
}
|
||||||
|
</style>";
|
||||||
|
lightToolStripMenuItem.Checked = false;
|
||||||
|
systemToolStripMenuItem.Checked = false;
|
||||||
|
darkToolStripMenuItem.Checked = true;
|
||||||
|
cssreload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue