SenY commited on
Commit
885aa07
·
1 Parent(s): fdb8bf0

字下げボタン追加

Browse files
Files changed (1) hide show
  1. index.html +65 -53
index.html CHANGED
@@ -92,6 +92,14 @@
92
  <button class="btn btn-secondary" id="deprocessBtn">
93
  <i class="fas fa-undo me-2"></i>Deprocess
94
  </button>
 
 
 
 
 
 
 
 
95
  </div>
96
  <div class="accordion" id="textEditorAccordion">
97
  <!-- 上部テキストエリア -->
@@ -116,13 +124,7 @@
116
  <button class="btn btn-outline-danger btn-sm" onclick="clearTextarea('topText')" title="クリア">
117
  <i class="fas fa-trash"></i>
118
  </button>
119
- <button class="btn btn-outline-info btn-sm" onclick="applyIndent('topText')" title="字下げ">
120
- <i class="fas fa-indent"></i>
121
- </button>
122
- <button class="btn btn-outline-warning btn-sm" onclick="applySpaces('topText')" title="スペース処理">
123
- <i class="fas fa-space-shuttle"></i>
124
- </button>
125
- <button class="btn btn-outline-secondary btn-sm" onclick="applyNovelFormat('topText')" title="小説フォーマット統一">
126
  <i class="fas fa-book"></i>
127
  </button>
128
  </div>
@@ -153,13 +155,7 @@
153
  <button class="btn btn-outline-danger btn-sm" onclick="clearTextarea('bottomText')" title="クリア">
154
  <i class="fas fa-trash"></i>
155
  </button>
156
- <button class="btn btn-outline-info btn-sm" onclick="applyIndent('bottomText')" title="字下げ">
157
- <i class="fas fa-indent"></i>
158
- </button>
159
- <button class="btn btn-outline-warning btn-sm" onclick="applySpaces('bottomText')" title="スペース処理">
160
- <i class="fas fa-space-shuttle"></i>
161
- </button>
162
- <button class="btn btn-outline-secondary btn-sm" onclick="applyNovelFormat('bottomText')" title="小説フォーマット統一">
163
  <i class="fas fa-book"></i>
164
  </button>
165
  </div>
@@ -191,13 +187,7 @@
191
  <button class="btn btn-outline-danger btn-sm" onclick="clearTextarea('memoArea')" title="クリア">
192
  <i class="fas fa-trash"></i>
193
  </button>
194
- <button class="btn btn-outline-info btn-sm" onclick="applyIndent('memoArea')" title="字下げ">
195
- <i class="fas fa-indent"></i>
196
- </button>
197
- <button class="btn btn-outline-warning btn-sm" onclick="applySpaces('memoArea')" title="スペース処理">
198
- <i class="fas fa-space-shuttle"></i>
199
- </button>
200
- <button class="btn btn-outline-secondary btn-sm" onclick="applyNovelFormat('memoArea')" title="小説フォーマット統一">
201
  <i class="fas fa-book"></i>
202
  </button>
203
  </div>
@@ -382,6 +372,7 @@
382
  document.getElementById('bottomText').value = textUtilData['bottomText'] || '';
383
  document.getElementById('topText').value = textUtilData['topText'] || '';
384
  document.getElementById('memoArea').value = textUtilData['memoArea'] || '';
 
385
  }
386
 
387
  document.querySelectorAll("#bottomText, #topText").forEach(el => {
@@ -394,6 +385,11 @@
394
  saveToUserStorage(true);
395
  });
396
  });
 
 
 
 
 
397
 
398
  document.addEventListener('DOMContentLoaded', function () {
399
  // ページ読み込み時にデータを復元
@@ -481,14 +477,6 @@
481
  return processedLines.join('\n');
482
  }
483
 
484
- // 字下げボタンのクリックイベントハンドラー
485
- function applyIndent(textareaId) {
486
- const textarea = document.getElementById(textareaId);
487
- const originalText = textarea.value;
488
- const indentedText = applyJapaneseIndent(originalText);
489
- textarea.value = indentedText;
490
- saveToUserStorage(true); // 字下げ後に自動保存
491
- }
492
 
493
  // 感嘆符・ハートマーク後のスペース処理関数
494
  function addSpacesAfterMarks(text) {
@@ -496,34 +484,44 @@
496
 
497
  // 感嘆符・ハートマークの後に全角スペースを追加
498
  // 既にスペースがある場合は重複しないよう処理
 
499
  let processedText = text;
500
 
501
- // 感嘆符・ハートマークのパターン
502
- const markPattern = /([!?!?♡♥❤]+)(\s*)/g;
 
503
 
504
- processedText = processedText.replace(markPattern, function(match, marks, existingSpaces) {
505
- // 既存のスペースを全角スペースに統一
506
- const normalizedSpaces = existingSpaces.replace(/[ \u00A0]/g, ' ');
507
 
508
- // 全角スペースが既に1つ以上ある場合はそのまま、ない場合は1つ追加
509
- if (normalizedSpaces.length >= 1) {
510
- return marks + normalizedSpaces;
511
- } else {
512
- return marks + ' ';
513
- }
514
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
 
516
- return processedText;
517
  }
518
 
519
- // スペース処理ボタンのクリックイベントハンドラー
520
- function applySpaces(textareaId) {
521
- const textarea = document.getElementById(textareaId);
522
- const originalText = textarea.value;
523
- const spacedText = addSpacesAfterMarks(originalText);
524
- textarea.value = spacedText;
525
- saveToUserStorage(true); // スペース処理後に自動保存
526
- }
527
 
528
  // 三点リーダーとダッシュの統一関数
529
  function unifyEllipsisAndDash(text) {
@@ -601,15 +599,29 @@
601
  const textarea = document.getElementById(textareaId);
602
  let processedText = textarea.value;
603
 
604
- // 1. 三点リーダーとダッシュの統一
 
 
 
605
  processedText = unifyEllipsisAndDash(processedText);
606
 
607
- // 2. かぎ括弧内の句点削除
608
  processedText = removePeriodInQuotes(processedText);
609
 
610
- // 3. 感嘆符・ハートマーク後のスペース処理
611
  processedText = addSpacesAfterMarks(processedText);
612
 
 
 
 
 
 
 
 
 
 
 
 
613
  textarea.value = processedText;
614
  saveToUserStorage(true); // フォーマット統一後に自動保存
615
  }
 
92
  <button class="btn btn-secondary" id="deprocessBtn">
93
  <i class="fas fa-undo me-2"></i>Deprocess
94
  </button>
95
+ <div class="form-group">
96
+ <label for="numberFormatSelect" class="form-label">数字表記:</label>
97
+ <select class="form-select" id="numberFormatSelect">
98
+ <option value="none">None(変更なし)</option>
99
+ <option value="kanji">漢数字に統一</option>
100
+ <option value="arabic">算用数字に統一</option>
101
+ </select>
102
+ </div>
103
  </div>
104
  <div class="accordion" id="textEditorAccordion">
105
  <!-- 上部テキストエリア -->
 
124
  <button class="btn btn-outline-danger btn-sm" onclick="clearTextarea('topText')" title="クリア">
125
  <i class="fas fa-trash"></i>
126
  </button>
127
+ <button class="btn btn-outline-secondary btn-sm" onclick="applyNovelFormat('topText')" title="小説フォーマット統一(字下げ・スペース・三点リーダー・句点削除)">
 
 
 
 
 
 
128
  <i class="fas fa-book"></i>
129
  </button>
130
  </div>
 
155
  <button class="btn btn-outline-danger btn-sm" onclick="clearTextarea('bottomText')" title="クリア">
156
  <i class="fas fa-trash"></i>
157
  </button>
158
+ <button class="btn btn-outline-secondary btn-sm" onclick="applyNovelFormat('bottomText')" title="小説フォーマット統一(字下げ・スペース・三点リーダー・句点削除)">
 
 
 
 
 
 
159
  <i class="fas fa-book"></i>
160
  </button>
161
  </div>
 
187
  <button class="btn btn-outline-danger btn-sm" onclick="clearTextarea('memoArea')" title="クリア">
188
  <i class="fas fa-trash"></i>
189
  </button>
190
+ <button class="btn btn-outline-secondary btn-sm" onclick="applyNovelFormat('memoArea')" title="小説フォーマット統一(字下げ・スペース・三点リーダー・句点削除)">
 
 
 
 
 
 
191
  <i class="fas fa-book"></i>
192
  </button>
193
  </div>
 
372
  document.getElementById('bottomText').value = textUtilData['bottomText'] || '';
373
  document.getElementById('topText').value = textUtilData['topText'] || '';
374
  document.getElementById('memoArea').value = textUtilData['memoArea'] || '';
375
+ document.getElementById('numberFormatSelect').value = textUtilData['numberFormatSelect'] || 'none';
376
  }
377
 
378
  document.querySelectorAll("#bottomText, #topText").forEach(el => {
 
385
  saveToUserStorage(true);
386
  });
387
  });
388
+ document.querySelectorAll("#numberFormatSelect").forEach(el => {
389
+ el.addEventListener('change', () => {
390
+ saveToUserStorage(true);
391
+ });
392
+ });
393
 
394
  document.addEventListener('DOMContentLoaded', function () {
395
  // ページ読み込み時にデータを復元
 
477
  return processedLines.join('\n');
478
  }
479
 
 
 
 
 
 
 
 
 
480
 
481
  // 感嘆符・ハートマーク後のスペース処理関数
482
  function addSpacesAfterMarks(text) {
 
484
 
485
  // 感嘆符・ハートマークの後に全角スペースを追加
486
  // 既にスペースがある場合は重複しないよう処理
487
+ // ただし、行末の閉じ括弧の直前にはスペースを置かない
488
  let processedText = text;
489
 
490
+ // 行ごとに処理
491
+ const lines = processedText.split('\n');
492
+ const processedLines = [];
493
 
494
+ for (const line of lines) {
495
+ // 感嘆符・ハートマークのパターン
496
+ const markPattern = /([!?!?♡♥❤]+)(\s*)/g;
497
 
498
+ let processedLine = line.replace(markPattern, function(match, marks, existingSpaces) {
499
+ // 行末の閉じ括弧の直前かどうかをチェック
500
+ const afterMatch = line.substring(line.indexOf(match) + match.length);
501
+ const isBeforeClosingBracket = /^\s*[)」』】〕]}]/.test(afterMatch);
502
+
503
+ if (isBeforeClosingBracket) {
504
+ // 閉じ括弧の直前の場合はスペースを削除
505
+ return marks;
506
+ } else {
507
+ // 既存のスペースを全角スペースに統一
508
+ const normalizedSpaces = existingSpaces.replace(/[ \u00A0]/g, ' ');
509
+
510
+ // 全角スペースが既に1つ以上ある場合はそのまま、ない場合は1つ追加
511
+ if (normalizedSpaces.length >= 1) {
512
+ return marks + normalizedSpaces;
513
+ } else {
514
+ return marks + ' ';
515
+ }
516
+ }
517
+ });
518
+
519
+ processedLines.push(processedLine);
520
+ }
521
 
522
+ return processedLines.join('\n');
523
  }
524
 
 
 
 
 
 
 
 
 
525
 
526
  // 三点リーダーとダッシュの統一関数
527
  function unifyEllipsisAndDash(text) {
 
599
  const textarea = document.getElementById(textareaId);
600
  let processedText = textarea.value;
601
 
602
+ // 1. 字下げ処理
603
+ processedText = applyJapaneseIndent(processedText);
604
+
605
+ // 2. 三点リーダーとダッシュの統一
606
  processedText = unifyEllipsisAndDash(processedText);
607
 
608
+ // 3. かぎ括弧内の句点削除
609
  processedText = removePeriodInQuotes(processedText);
610
 
611
+ // 4. 感嘆符・ハートマーク後のスペース処理
612
  processedText = addSpacesAfterMarks(processedText);
613
 
614
+ // 5. 数字表記の統一(セレクトメニューの選択に基づく)
615
+ const numberFormatSelect = document.getElementById('numberFormatSelect');
616
+ const numberFormat = numberFormatSelect.value;
617
+
618
+ if (numberFormat === 'kanji') {
619
+ processedText = unifyNumbersToKanji(processedText);
620
+ } else if (numberFormat === 'arabic') {
621
+ processedText = unifyNumbersToArabic(processedText);
622
+ }
623
+ // 'none'の場合は何もしない
624
+
625
  textarea.value = processedText;
626
  saveToUserStorage(true); // フォーマット統一後に自動保存
627
  }