Skip to content

Commit 1a3ee42

Browse files
committed
新增移除CSS功能
1 parent 657239a commit 1a3ee42

File tree

8 files changed

+1691
-1195
lines changed

8 files changed

+1691
-1195
lines changed

作夥直排/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<setting name="Batch_ConvertMobi" serializeAs="String">
6969
<value>False</value>
7070
</setting>
71+
<setting name="Batch_RemoveCss" serializeAs="String">
72+
<value>False</value>
73+
</setting>
7174
</ChoHoe.Properties.Settings>
7275
<作夥直排.Properties.Settings>
7376
<setting name="CalibrePath" serializeAs="String">

作夥直排/Book.cs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class Book
3232

3333
List<string> css = new List<string>(), xHtml = new List<string>();
3434
Dictionary<string, List<string>> imgpath = new Dictionary<string, List<string>>();
35+
bool isRemoveCss=false;
3536

3637

3738

@@ -112,6 +113,10 @@ public void Load(string path, string pandoc)
112113
Load(path);
113114

114115
}
116+
public void IsRemoveCss(bool removeCss)
117+
{
118+
isRemoveCss = removeCss;
119+
}
115120
public string PathEditor()
116121
{
117122

@@ -648,9 +653,14 @@ private void HtmlEdit(string path, bool DoTransfer, bool ToTraidional)
648653
}
649654
if (bodynode.Name == "body")
650655
{
651-
foreach (HtmlNode item in bodynode.ChildNodes)
656+
foreach (HtmlNode body_child_Node in bodynode.ChildNodes)
652657
{
653-
RecursivelyReplaceText(item, ToTraidional, DoTransfer);
658+
RecursivelyReplaceText(body_child_Node, ToTraidional, DoTransfer);
659+
if (isRemoveCss)
660+
{
661+
RemoveHtmlStyle(body_child_Node);
662+
}
663+
654664
}
655665
}
656666
@@ -676,6 +686,27 @@ private void HtmlEdit(string path, bool DoTransfer, bool ToTraidional)
676686
677687
sw.Close();
678688
}
689+
private void RemoveHtmlStyle(HtmlNode subBodyNode)
690+
{
691+
692+
foreach (HtmlNode childInnerNode in subBodyNode.ChildNodes)
693+
{
694+
foreach (var attribute in childInnerNode.Attributes )
695+
{
696+
if (attribute.Name=="style")
697+
{
698+
//attribute.Value = "";
699+
attribute.Remove();
700+
break;
701+
}
702+
703+
}
704+
if (childInnerNode.ChildNodes.Count!=0)
705+
{
706+
RemoveHtmlStyle(childInnerNode);
707+
}
708+
}
709+
}
679710
private void RecursivelyReplaceText(HtmlNode innernode, bool toTraditional, bool doTransfer)
680711
{
681712
foreach (HtmlNode childinnenode in innernode.ChildNodes)

作夥直排/Main.Designer.cs

Lines changed: 226 additions & 215 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

作夥直排/Main.cs

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Form1()
3939
Logger.logger.Info("🦄//////////////////🦄 - App Started - 🦄///////////////////////🦄");
4040

4141
const string Caption = "預設會強制指定為由右而左,直排小說的翻頁方向。";
42-
toolTip.SetToolTip(chkbModifyPageDirection, Caption);
42+
toolTip.SetToolTip(cbModifyPageDirection, Caption);
4343
SetInitialValue();
4444

4545
//呼叫語言func
@@ -56,13 +56,13 @@ public Form1()
5656

5757
private void SetInitialValue()
5858
{
59-
chkbToChinese.Checked = ChoHoe.Properties.Settings.Default.ChineseConvert;
60-
chkbModifyPageDirection.Checked = ChoHoe.Properties.Settings.Default.IfChangePageDirection;
59+
cbToChinese.Checked = ChoHoe.Properties.Settings.Default.ChineseConvert;
60+
cbModifyPageDirection.Checked = ChoHoe.Properties.Settings.Default.IfChangePageDirection;
6161
rdoPageRTL.Checked = ChoHoe.Properties.Settings.Default.PageDirection;
6262
rdoPageLTR.Checked = !ChoHoe.Properties.Settings.Default.PageDirection;
63-
chkbReplacePicture.Checked = ChoHoe.Properties.Settings.Default.ReplaceImg;
64-
chkbConvertMobi.Checked = ChoHoe.Properties.Settings.Default.ConvertMobi;
65-
chkbEmbdedFont.Checked = ChoHoe.Properties.Settings.Default.EmbedFont;
63+
cbReplacePicture.Checked = ChoHoe.Properties.Settings.Default.ReplaceImg;
64+
cbConvertMobi.Checked = ChoHoe.Properties.Settings.Default.ConvertMobi;
65+
cbEmbdedFont.Checked = ChoHoe.Properties.Settings.Default.EmbedFont;
6666
btnToTraditionValue.Text = ChoHoe.Properties.Settings.Default.ToTriditional ? ">" : "<";
6767
ToTradictional = ChoHoe.Properties.Settings.Default.ToTriditional;
6868

@@ -194,7 +194,7 @@ private void btnConvert_Click(object sender, EventArgs e)
194194

195195
btnConvert.Enabled = false;
196196

197-
bwConvert.RunWorkerAsync(argument: chkbModifyPageDirection.Checked);
197+
bwConvert.RunWorkerAsync(argument: cbModifyPageDirection.Checked);
198198

199199

200200
}
@@ -288,8 +288,9 @@ private void btnConvertBatch_Click(object sender, EventArgs e)
288288

289289
Logger.logger.Info("開始轉檔");
290290

291+
Tuple<bool, bool> variables = new Tuple<bool, bool> ( cbModifyPageDirection.Checked, cbRemoveCss.Checked );
291292

292-
bwConvertBatch.RunWorkerAsync(argument: chkbModifyPageDirection.Checked);
293+
bwConvertBatch.RunWorkerAsync(argument: variables);
293294
}
294295

295296
private void rdoPageRTL_CheckedChanged(object sender, EventArgs e)
@@ -310,9 +311,9 @@ private void rdoPageLTR_CheckedChanged(object sender, EventArgs e)
310311
}
311312
}
312313

313-
private void chkbToChinese_CheckChanged(object sender, EventArgs e)
314+
private void cbToChinese_CheckChanged(object sender, EventArgs e)
314315
{
315-
ChoHoe.Properties.Settings.Default.ChineseConvert = chkbToChinese.Checked;
316+
ChoHoe.Properties.Settings.Default.ChineseConvert = cbToChinese.Checked;
316317
ChoHoe.Properties.Settings.Default.Save();
317318
}
318319

@@ -321,27 +322,27 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
321322
ChoHoe.Properties.Settings.Default.Save();
322323
}
323324

324-
private void chkbModifyPageDirection_CheckedChanged(object sender, EventArgs e)
325+
private void cbModifyPageDirection_CheckedChanged(object sender, EventArgs e)
325326
{
326-
ChoHoe.Properties.Settings.Default.IfChangePageDirection = chkbModifyPageDirection.Checked;
327+
ChoHoe.Properties.Settings.Default.IfChangePageDirection = cbModifyPageDirection.Checked;
327328
ChoHoe.Properties.Settings.Default.Save();
328329
}
329330

330-
private void chkbReplacePicture_CheckedChanged(object sender, EventArgs e)
331+
private void cbReplacePicture_CheckedChanged(object sender, EventArgs e)
331332
{
332-
ChoHoe.Properties.Settings.Default.ReplaceImg = chkbReplacePicture.Checked;
333+
ChoHoe.Properties.Settings.Default.ReplaceImg = cbReplacePicture.Checked;
333334
ChoHoe.Properties.Settings.Default.Save();
334335
}
335336

336-
private void chkbConvertMobi_CheckedChanged(object sender, EventArgs e)
337+
private void cbConvertMobi_CheckedChanged(object sender, EventArgs e)
337338
{
338-
ChoHoe.Properties.Settings.Default.ConvertMobi = chkbConvertMobi.Checked;
339+
ChoHoe.Properties.Settings.Default.ConvertMobi = cbConvertMobi.Checked;
339340
ChoHoe.Properties.Settings.Default.Save();
340341
}
341342

342-
private void chkbEmbdedFont_CheckedChanged(object sender, EventArgs e)
343+
private void cbEmbdedFont_CheckedChanged(object sender, EventArgs e)
343344
{
344-
ChoHoe.Properties.Settings.Default.EmbedFont = chkbEmbdedFont.Checked;
345+
ChoHoe.Properties.Settings.Default.EmbedFont = cbEmbdedFont.Checked;
345346
ChoHoe.Properties.Settings.Default.Save();
346347
}
347348

@@ -408,11 +409,11 @@ private void Convert_Backgroundworker_DoWork(object sender, DoWorkEventArgs e)
408409

409410
if (Modifypage)
410411
{
411-
abook.Convert(chkbToChinese.Checked, ToTradictional, rdoPageRTL.Checked, chkbConvertMobi.Checked, chkbEmbdedFont.Checked, chkbReplacePicture.Checked, txtAuthor.Text, txtTittle.Text);
412+
abook.Convert(cbToChinese.Checked, ToTradictional, rdoPageRTL.Checked, cbConvertMobi.Checked, cbEmbdedFont.Checked, cbReplacePicture.Checked, txtAuthor.Text, txtTittle.Text);
412413
}
413414
else
414415
{
415-
abook.Convert(chkbToChinese.Checked, ToTradictional, true, chkbConvertMobi.Checked, chkbEmbdedFont.Checked, chkbReplacePicture.Checked, txtAuthor.Text, txtTittle.Text);
416+
abook.Convert(cbToChinese.Checked, ToTradictional, true, cbConvertMobi.Checked, cbEmbdedFont.Checked, cbReplacePicture.Checked, txtAuthor.Text, txtTittle.Text);
416417
}
417418
e.Cancel = true;
418419
return;
@@ -433,17 +434,23 @@ private void Convert_RunWorker_Completed(object sender, RunWorkerCompletedEventA
433434

434435
private void Convert_Batch_Backgroundworker_DoWork(object sender, DoWorkEventArgs e)
435436
{
436-
bool Modifypage = (bool)e.Argument;
437437

438+
Tuple<bool, bool> para = (Tuple<bool, bool>)e.Argument;
439+
bool Modifypage = para.Item1;
440+
bool RemoveCss = para.Item2;
441+
442+
443+
438444
foreach (Book item in batchBookList)
439445
{
446+
item.IsRemoveCss(RemoveCss);
440447
if (Modifypage)
441448
{
442-
item.Convert(chkbChineseBatch.Checked, BatchToTradictional, rdoPageRTLBatch.Checked, chkbConvertMobiBatch.Checked, chkbEmbdedFontBatch.Checked, chkbReplacePictureBatch.Checked, item.GetAuthor(), item.GetTitle());
449+
item.Convert(cbChineseBatch.Checked, BatchToTradictional, rdoPageRTLBatch.Checked, cbConvertMobiBatch.Checked, cbEmbdedFontBatch.Checked, cbReplacePictureBatch.Checked, item.GetAuthor(), item.GetTitle());
443450
}
444451
else
445452
{
446-
item.Convert(chkbChineseBatch.Checked, BatchToTradictional, true, chkbConvertMobiBatch.Checked, chkbEmbdedFontBatch.Checked, chkbReplacePictureBatch.Checked, item.GetAuthor(), item.GetTitle());
453+
item.Convert(cbChineseBatch.Checked, BatchToTradictional, true, cbConvertMobiBatch.Checked, cbEmbdedFontBatch.Checked, cbReplacePictureBatch.Checked, item.GetAuthor(), item.GetTitle());
447454
}
448455
}
449456
e.Cancel = true;
@@ -539,34 +546,34 @@ private void btnDelete_Click(object sender, EventArgs e)
539546

540547
}
541548

542-
private void chkbChineseBatch_CheckedChanged(object sender, EventArgs e)
549+
private void cbChineseBatch_CheckedChanged(object sender, EventArgs e)
543550
{
544-
ChoHoe.Properties.Settings.Default.Batch_ChineseConvert = chkbChineseBatch.Checked;
551+
ChoHoe.Properties.Settings.Default.Batch_ChineseConvert = cbChineseBatch.Checked;
545552
ChoHoe.Properties.Settings.Default.Save();
546553
}
547554

548-
private void chkbModifyPageDirectionBatch_CheckedChanged(object sender, EventArgs e)
555+
private void cbModifyPageDirectionBatch_CheckedChanged(object sender, EventArgs e)
549556
{
550-
ChoHoe.Properties.Settings.Default.Batch_IfChangePageDirection = chkbModifyPageDirectionBatch.Checked;
557+
ChoHoe.Properties.Settings.Default.Batch_IfChangePageDirection = cbModifyPageDirectionBatch.Checked;
551558
ChoHoe.Properties.Settings.Default.Save();
552559
}
553560

554-
private void chkbConvertMobiBatch_CheckedChanged(object sender, EventArgs e)
561+
private void cbConvertMobiBatch_CheckedChanged(object sender, EventArgs e)
555562
{
556-
ChoHoe.Properties.Settings.Default.Batch_ConvertMobi = chkbConvertMobiBatch.Checked;
563+
ChoHoe.Properties.Settings.Default.Batch_ConvertMobi = cbConvertMobiBatch.Checked;
557564
ChoHoe.Properties.Settings.Default.Save();
558565
}
559566

560-
private void chkbReplacePictureBatch_CheckedChanged(object sender, EventArgs e)
567+
private void cbReplacePictureBatch_CheckedChanged(object sender, EventArgs e)
561568
{
562-
ChoHoe.Properties.Settings.Default.Batch_ReplaceImg = chkbReplacePictureBatch.Checked;
569+
ChoHoe.Properties.Settings.Default.Batch_ReplaceImg = cbReplacePictureBatch.Checked;
563570
ChoHoe.Properties.Settings.Default.Save();
564571
}
565572

566-
private void chkbEmbdedFontBatch_CheckedChanged(object sender, EventArgs e)
573+
private void cbEmbdedFontBatch_CheckedChanged(object sender, EventArgs e)
567574
{
568575
ChoHoe.Properties.Settings.Default.Batch_EmbedFont
569-
= chkbEmbdedFontBatch.Checked;
576+
= cbEmbdedFontBatch.Checked;
570577
ChoHoe.Properties.Settings.Default.Save();
571578
}
572579

@@ -609,6 +616,12 @@ private void runningUi(string message, bool enabled)
609616

610617
}
611618

619+
private void cbRemoveCss_CheckedChanged(object sender, EventArgs e)
620+
{
621+
ChoHoe.Properties.Settings.Default.Batch_RemoveCss
622+
= cbRemoveCss.Checked;
623+
ChoHoe.Properties.Settings.Default.Save();
624+
}
612625
}
613626

614627
}

0 commit comments

Comments
 (0)