// source --> https://www.activitv.com/contents/wp-content/themes/tv/js/print.js 
function copyToClipboard() {
  // 仮想DOM要素を作成
  const tempDiv = document.createElement('div');
  tempDiv.innerHTML = document.body.innerHTML;

  // .print-btn.print_none クラスと .recipe_time クラスを持つ要素を仮想DOMから削除
  const excludedElements = tempDiv.querySelectorAll('.print-btn.print_none, .recipe_time');
  excludedElements.forEach(el => el.remove());

  // <noscript>と<iframe>タグを仮想DOMから削除
  const noscriptElements = tempDiv.querySelectorAll('noscript, iframe');
  noscriptElements.forEach(el => el.remove());

  // 仮想DOM内で<li>の連番を付ける
  const ulElements = tempDiv.querySelectorAll('ul');
  ulElements.forEach(ul => {
    const liElements = ul.querySelectorAll('li');
    liElements.forEach((li, index) => {
      // 連番を追加 (index+1 は 0-based index のため)
      li.textContent = (index + 1) + '. ' + li.textContent;
    });
  });

  // Clipboard APIを使用してクリップボードにコピー
  navigator.clipboard.writeText(tempDiv.innerText).then(function () {
    alert('レシピをクリップボードにコピーしました！\nペーストしてご利用ください。');
  }).catch(function (err) {
    alert('クリップボードへのコピーに失敗しました: ' + err);
  });
}


document.addEventListener("DOMContentLoaded", function () {
  // `<ul class="linum r_instructions">`を選択
  const ulElements = document.querySelectorAll('ul.linum.r_instructions');

  ulElements.forEach(ul => {
    const ol = document.createElement('ol'); // 新しい<ol>要素を作成
    ol.className = 'linum r_instructions';   // classを設定

    // 元の<ul>の中の全ての子要素を新しい<ol>に移動
    while (ul.firstChild) {
      ol.appendChild(ul.firstChild);
    }

    // 元の<ul>の位置に<ol>を挿入
    ul.parentNode.replaceChild(ol, ul);
  });
});