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();
|
||||
button2 = new Button();
|
||||
textBox2 = new TextBox();
|
||||
fullUIToolStripMenuItem = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
groupBox4.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
|
@ -78,30 +79,29 @@
|
|||
// openDevToolsToolStripMenuItem
|
||||
//
|
||||
openDevToolsToolStripMenuItem.Name = "openDevToolsToolStripMenuItem";
|
||||
openDevToolsToolStripMenuItem.Size = new Size(180, 22);
|
||||
openDevToolsToolStripMenuItem.Size = new Size(154, 22);
|
||||
openDevToolsToolStripMenuItem.Text = "Open DevTools";
|
||||
openDevToolsToolStripMenuItem.Click += openDevToolsToolStripMenuItem_Click_1;
|
||||
//
|
||||
// exitToolStripMenuItem
|
||||
//
|
||||
exitToolStripMenuItem.Name = "exitToolStripMenuItem";
|
||||
exitToolStripMenuItem.Size = new Size(180, 22);
|
||||
exitToolStripMenuItem.Size = new Size(154, 22);
|
||||
exitToolStripMenuItem.Text = "Exit";
|
||||
exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
|
||||
//
|
||||
// renderToolStripMenuItem
|
||||
//
|
||||
renderToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { fontFamilyToolStripMenuItem, colorThemeToolStripMenuItem });
|
||||
renderToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { fontFamilyToolStripMenuItem, colorThemeToolStripMenuItem, fullUIToolStripMenuItem });
|
||||
renderToolStripMenuItem.Name = "renderToolStripMenuItem";
|
||||
renderToolStripMenuItem.Size = new Size(56, 20);
|
||||
renderToolStripMenuItem.Text = "Render";
|
||||
renderToolStripMenuItem.Click += renderToolStripMenuItem_Click;
|
||||
//
|
||||
// fontFamilyToolStripMenuItem
|
||||
//
|
||||
fontFamilyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { serifToolStripMenuItem, sansSerifToolStripMenuItem, forceMonospaceToolStripMenuItem });
|
||||
fontFamilyToolStripMenuItem.Name = "fontFamilyToolStripMenuItem";
|
||||
fontFamilyToolStripMenuItem.Size = new Size(180, 22);
|
||||
fontFamilyToolStripMenuItem.Size = new Size(140, 22);
|
||||
fontFamilyToolStripMenuItem.Text = "Font Family";
|
||||
//
|
||||
// serifToolStripMenuItem
|
||||
|
@ -131,7 +131,7 @@
|
|||
//
|
||||
colorThemeToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { systemToolStripMenuItem, lightToolStripMenuItem, darkToolStripMenuItem });
|
||||
colorThemeToolStripMenuItem.Name = "colorThemeToolStripMenuItem";
|
||||
colorThemeToolStripMenuItem.Size = new Size(180, 22);
|
||||
colorThemeToolStripMenuItem.Size = new Size(140, 22);
|
||||
colorThemeToolStripMenuItem.Text = "Color theme";
|
||||
//
|
||||
// systemToolStripMenuItem
|
||||
|
@ -272,6 +272,15 @@
|
|||
textBox2.TabIndex = 2;
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
|
@ -322,5 +331,6 @@
|
|||
private ToolStripMenuItem serifToolStripMenuItem;
|
||||
private ToolStripMenuItem sansSerifToolStripMenuItem;
|
||||
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 markfile;
|
||||
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
|
||||
width=""25mm""
|
||||
height=""25mm""
|
||||
|
@ -165,6 +163,7 @@ namespace MintHTML
|
|||
</g>
|
||||
</svg>
|
||||
";
|
||||
string css2 = "\n</style>";
|
||||
string css;
|
||||
bool extraInstance = false;
|
||||
int extraNum = 0;
|
||||
|
@ -173,6 +172,10 @@ namespace MintHTML
|
|||
{
|
||||
htmlfile = Markdown.ToHtml(markfile);
|
||||
}
|
||||
private void cssreload()
|
||||
{
|
||||
chromiumWebBrowser1.LoadHtml(css + css2 + htmlfile);
|
||||
}
|
||||
// Custom functions end
|
||||
|
||||
public Form1()
|
||||
|
@ -205,9 +208,9 @@ namespace MintHTML
|
|||
css = @"<style>
|
||||
html{
|
||||
font-family: sans-serif
|
||||
}" + csssuffix;
|
||||
}";
|
||||
htmlfile = "<center>" + logo + htmlfile;
|
||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
||||
cssreload();
|
||||
}
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -223,7 +226,7 @@ font-family: sans-serif
|
|||
{
|
||||
markfile = File.ReadAllText(textBox2.Text);
|
||||
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)
|
||||
{
|
||||
convert();
|
||||
File.WriteAllText(Saver.FileName, css + htmlfile);
|
||||
File.WriteAllText(Saver.FileName, "<style>\n" + css + css2 + htmlfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -248,7 +251,7 @@ font-family: sans-serif
|
|||
File.WriteAllText(Saver.FileName, htmlfile);
|
||||
}
|
||||
MessageBox.Show("Save complete.", "Converter", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
||||
cssreload();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,11 +290,12 @@ font-family: sans-serif
|
|||
css = @"<style>
|
||||
html{
|
||||
font-family: serif
|
||||
}" + csssuffix;
|
||||
}
|
||||
";
|
||||
sansSerifToolStripMenuItem.Checked = false;
|
||||
forceMonospaceToolStripMenuItem.Checked = false;
|
||||
serifToolStripMenuItem.Checked = true;
|
||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
||||
cssreload();
|
||||
}
|
||||
|
||||
private void groupBox4_Enter(object sender, EventArgs e)
|
||||
|
@ -304,11 +308,12 @@ font-family: serif
|
|||
css = @"<style>
|
||||
html{
|
||||
font-family: sans-serif
|
||||
}" + csssuffix;
|
||||
}
|
||||
";
|
||||
sansSerifToolStripMenuItem.Checked = true;
|
||||
forceMonospaceToolStripMenuItem.Checked = false;
|
||||
serifToolStripMenuItem.Checked = false;
|
||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
||||
cssreload();
|
||||
}
|
||||
|
||||
private void forceMonospaceToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
|
@ -316,11 +321,12 @@ font-family: sans-serif
|
|||
css = @"<style>
|
||||
html{
|
||||
font-family: monospace
|
||||
}" + csssuffix;
|
||||
}
|
||||
";
|
||||
sansSerifToolStripMenuItem.Checked = false;
|
||||
forceMonospaceToolStripMenuItem.Checked = true;
|
||||
serifToolStripMenuItem.Checked = false;
|
||||
chromiumWebBrowser1.LoadHtml(css + htmlfile);
|
||||
cssreload();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (!(chromiumWebBrowser1.Address.Substring(0, 5) == "data:"))
|
||||
|
@ -352,7 +354,15 @@ font-family: monospace
|
|||
|
||||
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