Transport

<!-- MODUL 1: Zrušení "Chráněno:" z titulu stránky -->
<script>
document.addEventListener("DOMContentLoaded", function() {
  const titleEl = document.querySelector('.wp-block-post-title');
  if (titleEl) {
    titleEl.innerHTML = titleEl.innerHTML.replace(/^Chráněno:\s*/i, '');
  }
});
</script>

<!-- *************************************** -->
<!-- *************************************** -->
<!-- *************************************** -->

<!-- MODUL 2: Střídavé podbarvení sekcí (H2) -->
<style>
.recipe-section-wrapper {
  padding: 25px;
  margin-bottom: 25px;
  border-radius: 12px;
}
.recipe-section-wrapper > * {
  margin-top: 0;
  margin-bottom: 15px;
}
.recipe-section-wrapper > *:last-child {
  margin-bottom: 0;
}
.recipe-bg-odd {
  background-color: transparent; 
  border: 2px solid rgba(0, 0, 0, 0.08);
}
.recipe-bg-even {
  background-color: rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(0, 0, 0, 0.12);
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
  const h2Headings = document.querySelectorAll('h2:not(.wp-block-post-title)');
  let isEven = false; 

  h2Headings.forEach(function(h2) {
    if (h2.parentElement.classList.contains('recipe-section-wrapper')) return;

    let sectionElements = [h2];
    let curr = h2.nextElementSibling;
    
    while (curr && curr.tagName !== 'H2') {
      sectionElements.push(curr);
      curr = curr.nextElementSibling;
    }

    const wrapper = document.createElement('div');
    wrapper.classList.add('recipe-section-wrapper');
    
    if (isEven) {
      wrapper.classList.add('recipe-bg-even');
    } else {
      wrapper.classList.add('recipe-bg-odd');
    }
    isEven = !isEven; 

    h2.parentNode.insertBefore(wrapper, h2);

    sectionElements.forEach(function(el) {
      wrapper.appendChild(el);
    });
  });
});
</script>

<!-- *************************************** -->
<!-- *************************************** -->
<!-- *************************************** -->

<!-- MODUL 3: Klikatelné texty a kopírování schránky (OPRAVA KOPÍROVÁNÍ TEXTŮ VEDLE SEZNAMŮ) -->
<style>
.recipe-clickable {
  cursor: pointer;
  transition: background-color 0.3s ease;
  border-radius: 4px;
  padding: 2px 4px;
}
li.recipe-clickable {
  display: list-item;
}
html body .recipe-clickable:hover, 
html body .recipe-section-hover {
  background-color: var(--wp--preset--color--accent-2, rgba(0, 0, 0, 0.06));
}
@keyframes copyFlash {
  0% { background-color: var(--wp--preset--color--accent-1, #ffcc00); }
  100% { background-color: transparent; }
}
html body .copied-flash,
html body .copied-flash:hover,
html body .copied-flash.recipe-section-hover {
  animation: copyFlash 0.8s ease !important;
  background-color: transparent;
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
  function getRelativeDepth(li, rootUl) {
    let depth = 1;
    let parent = li.parentElement;
    while (parent && parent !== rootUl) {
      if (parent.tagName === 'UL' || parent.tagName === 'OL') {
        depth++;
      }
      parent = parent.parentElement;
    }
    return depth;
  }

  function formatListItem(li, rootUl) {
    let depth = getRelativeDepth(li, rootUl);
    let clone = li.cloneNode(true);
    clone.querySelectorAll('ul, ol').forEach(sub => sub.remove());
    let rawText = clone.innerText.trim();

    let stars = '*'.repeat(depth);
    const starIndents = ['', '  ', '     ', '         ', '              '];
    let starIndent = starIndents[depth - 1] || '  '.repeat(depth - 1);
    
    let totalPrefixLen = starIndent.length + stars.length + 1;
    let continuationIndent = ' '.repeat(totalPrefixLen);

    let wrappedText = wrapText(rawText, 75, continuationIndent);
    let result = starIndent + stars + ' ' + wrappedText;

    li.querySelectorAll(':scope > ul, :scope > ol').forEach(subList => {
      subList.querySelectorAll(':scope > li').forEach(subLi => {
        result += '\n' + formatListItem(subLi, rootUl);
      });
    });

    return result;
  }

  function wrapText(text, maxLineLength, continuationIndent) {
    let words = text.split(/\s+/);
    let lines = [];
    let currentLine = '';

    words.forEach(word => {
      let testLine = currentLine ? currentLine + ' ' + word : word;
      if (testLine.length > maxLineLength) {
        if (currentLine) lines.push(currentLine);
        currentLine = word;
      } else {
        currentLine = testLine;
      }
    });
    if (currentLine) lines.push(currentLine);

    return lines.map((line, index) => index === 0 ? line : continuationIndent + line).join('\n');
  }

  const postHeadings = document.querySelectorAll('h2, h3, h4, h5, h6');
  
  postHeadings.forEach(heading => {
    if (heading.classList.contains('wp-block-post-title')) return;

    let currentLevel = parseInt(heading.tagName.substring(1));
    let blockElements = [heading];
    let curr = heading.nextElementSibling;
    
    while (curr) {
      if (/^H[1-6]$/.test(curr.tagName)) {
        let nextLevel = parseInt(curr.tagName.substring(1));
        if (nextLevel <= currentLevel) {
          break; 
        }
      }
      blockElements.push(curr);
      curr = curr.nextElementSibling;
    }

    heading.classList.add('recipe-clickable');
    heading.title = "Klepnutím zkopírujete celou sekci";

    heading.addEventListener('mouseenter', () => {
      blockElements.forEach(el => el.classList.add('recipe-section-hover'));
    });
    heading.addEventListener('mouseleave', () => {
      blockElements.forEach(el => el.classList.remove('recipe-section-hover'));
    });

    // KOPÍROVÁNÍ CELÉ SEKCE: Čte obsah strukturovaně, kousek po kousku
    heading.addEventListener('click', function(e) {
      let fullText = heading.innerText.trim().toUpperCase();
      
      blockElements.slice(1).forEach(el => {
        let elementsToProcess = [];
        
        if (/^(P|UL|OL|H[1-6])$/.test(el.tagName)) {
            elementsToProcess.push(el);
        } else {
            // Pokud je to obalovací DIV (Group blok), najdeme vše uvnitř
            let candidates = el.querySelectorAll('p, ul, ol, h1, h2, h3, h4, h5, h6');
            let hasCandidates = false;
            candidates.forEach(cand => {
                if (/^(UL|OL)$/.test(cand.tagName)) {
                    if (!cand.parentElement.closest('ul, ol')) {
                        elementsToProcess.push(cand);
                        hasCandidates = true;
                    }
                } else {
                    if (!cand.closest('ul, ol')) {
                        elementsToProcess.push(cand);
                        hasCandidates = true;
                    }
                }
            });
            if (!hasCandidates && el.innerText.trim() !== "") {
                elementsToProcess.push(el);
            }
        }

        // Poskládání textu ve správném pořadí (odstavce + seznamy společně)
        elementsToProcess.forEach(node => {
            if (node.tagName === 'UL' || node.tagName === 'OL') {
                node.querySelectorAll(':scope > li').forEach(li => {
                    fullText += '\n' + formatListItem(li, node);
                });
            } else if (/^H[1-6]$/.test(node.tagName)) {
                fullText += '\n\n' + node.innerText.trim().toUpperCase();
            } else {
                fullText += '\n\n' + node.innerText.trim();
            }
        });
      });
      
      blockElements.forEach(el => {
        el.classList.remove('copied-flash');
        void el.offsetWidth; 
        el.classList.add('copied-flash');
        setTimeout(() => el.classList.remove('copied-flash'), 800);
      });

      navigator.clipboard.writeText(fullText);
    });

    // KLIKÁNÍ NA JEDNOTLIVÉ PRVKY
    blockElements.slice(1).forEach(el => {
      if (/^H[1-6]$/.test(el.tagName)) return;

      let listItems = el.tagName === 'LI' ? [el] : el.querySelectorAll('li');
      listItems.forEach(listItem => {
        listItem.classList.add('recipe-clickable');
        listItem.title = "Klepnutím zkopírujete tento bod";
        
        listItem.addEventListener('click', function(e) {
          e.stopPropagation(); 
          
          let rootUl = listItem.closest('ul') || listItem.closest('ol');
          while(rootUl && rootUl.parentElement && (rootUl.parentElement.tagName === 'UL' || rootUl.parentElement.tagName === 'OL' || rootUl.parentElement.tagName === 'LI')) {
            let nextRoot = rootUl.parentElement.closest('ul') || rootUl.parentElement.closest('ol');
            if (nextRoot) rootUl = nextRoot;
            else break;
          }

          const textToCopy = formatListItem(listItem, rootUl);
          
          listItem.classList.remove('copied-flash');
          void listItem.offsetWidth;
          listItem.classList.add('copied-flash');
          setTimeout(() => listItem.classList.remove('copied-flash'), 800);

          navigator.clipboard.writeText(textToCopy);
        });
      });

      let paras = Array.from(el.querySelectorAll('p'));
      if (el.tagName === 'P') paras.push(el);
      
      if (paras.length === 0 && !/^H[1-6]$/.test(el.tagName) && el.tagName !== 'UL' && el.tagName !== 'OL' && el.tagName !== 'LI' && !el.querySelector('ul, ol, li') && el.innerText.trim() !== "") {
        paras.push(el);
      }

      paras.forEach(p => {
        if (p.closest('li')) return; 
        
        p.classList.add('recipe-clickable');
        p.title = "Klepnutím zkopírujete tento odstavec";
        
        p.addEventListener('click', function(e) {
          e.stopPropagation();
          const textToCopy = p.innerText.trim();
          
          p.classList.remove('copied-flash');
          void p.offsetWidth;
          p.classList.add('copied-flash');
          setTimeout(() => p.classList.remove('copied-flash'), 800);

          navigator.clipboard.writeText(textToCopy);
        });
      });
    });
  });
});
</script>

<!-- *************************************** -->
<!-- *************************************** -->
<!-- *************************************** -->

<!-- MODUL 4: Automatické štítky pro omezenou dostupnost -->
<style>
.recipe-warning-badge {
  display: inline-block;
  background-color: #fff0f0;
  color: #cc0000;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 0.9em;
  border: 1px solid #ffcccc;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
  // Prohledá všechny běžné textové prvky
  const textElements = document.querySelectorAll('p, li, h3, h4');
  
  textElements.forEach(el => {
    // Pokud text obsahuje definované spojení, nahradí ho grafickým štítkem
    if (el.innerHTML.includes('dostupnost')) {
      // Ochrana proti dvojitému vložení štítku
      if (!el.innerHTML.includes('recipe-warning-badge')) {
        el.innerHTML = el.innerHTML.replace(
          'Omezená dostupnost', 
          '<span class="recipe-warning-badge">⚠️ Omezená dostupnost</span>'
        );
      }
    }
  });
});
</script>

Původní šablona Rp. do 02.11.2026

<!-- MODUL 1: Zrušení "Chráněno:" z titulu stránky -->
<script>
document.addEventListener("DOMContentLoaded", function() {
  const titleEl = document.querySelector('.wp-block-post-title');
  if (titleEl) {
    titleEl.innerHTML = titleEl.innerHTML.replace(/^Chráněno:\s*/i, '');
  }
});
</script>

<!-- *************************************** -->
<!-- *************************************** -->
<!-- *************************************** -->

<!-- MODUL 2: Střídavé podbarvení sekcí (H2) -->
<style>
.recipe-section-wrapper {
  padding: 25px;
  margin-bottom: 25px;
  border-radius: 12px;
}
.recipe-section-wrapper > * {
  margin-top: 0;
  margin-bottom: 15px;
}
.recipe-section-wrapper > *:last-child {
  margin-bottom: 0;
}
.recipe-bg-odd {
  background-color: transparent; 
  border: 2px solid rgba(0, 0, 0, 0.08);
}
.recipe-bg-even {
  background-color: rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(0, 0, 0, 0.12);
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
  const h2Headings = document.querySelectorAll('h2:not(.wp-block-post-title)');
  let isEven = false; 

  h2Headings.forEach(function(h2) {
    if (h2.parentElement.classList.contains('recipe-section-wrapper')) return;

    let sectionElements = [h2];
    let curr = h2.nextElementSibling;
    
    while (curr && curr.tagName !== 'H2') {
      sectionElements.push(curr);
      curr = curr.nextElementSibling;
    }

    const wrapper = document.createElement('div');
    wrapper.classList.add('recipe-section-wrapper');
    
    if (isEven) {
      wrapper.classList.add('recipe-bg-even');
    } else {
      wrapper.classList.add('recipe-bg-odd');
    }
    isEven = !isEven; 

    h2.parentNode.insertBefore(wrapper, h2);

    sectionElements.forEach(function(el) {
      wrapper.appendChild(el);
    });
  });
});
</script>

<!-- *************************************** -->
<!-- *************************************** -->
<!-- *************************************** -->

<!-- MODUL 3: Klikatelné texty a kopírování schránky (S OCHRANOU PROTI KOPÍROVÁNÍ ŠTÍTKU) -->
<style>
.recipe-clickable {
  cursor: pointer;
  transition: background-color 0.3s ease;
  border-radius: 4px;
  padding: 2px 4px;
}
li.recipe-clickable {
  display: list-item;
}
html body .recipe-clickable:hover, 
html body .recipe-section-hover {
  background-color: var(--wp--preset--color--accent-2, rgba(0, 0, 0, 0.06));
}
@keyframes copyFlash {
  0% { background-color: var(--wp--preset--color--accent-1, #ffcc00); }
  100% { background-color: transparent; }
}
html body .copied-flash,
html body .copied-flash:hover,
html body .copied-flash.recipe-section-hover {
  animation: copyFlash 0.8s ease !important;
  background-color: transparent;
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
  function getRelativeDepth(li, rootUl) {
    let depth = 1;
    let parent = li.parentElement;
    while (parent && parent !== rootUl) {
      if (parent.tagName === 'UL' || parent.tagName === 'OL') {
        depth++;
      }
      parent = parent.parentElement;
    }
    return depth;
  }

  function formatListItem(li, rootUl) {
    let depth = getRelativeDepth(li, rootUl);
    let clone = li.cloneNode(true);
    clone.querySelectorAll('ul, ol').forEach(sub => sub.remove());
    let rawText = clone.innerText.trim();

    let stars = '*'.repeat(depth);
    const starIndents = ['', '  ', '     ', '         ', '              '];
    let starIndent = starIndents[depth - 1] || '  '.repeat(depth - 1);
    
    let totalPrefixLen = starIndent.length + stars.length + 1;
    let continuationIndent = ' '.repeat(totalPrefixLen);

    let wrappedText = wrapText(rawText, 75, continuationIndent);
    let result = starIndent + stars + ' ' + wrappedText;

    li.querySelectorAll(':scope > ul, :scope > ol').forEach(subList => {
      subList.querySelectorAll(':scope > li').forEach(subLi => {
        result += '\n' + formatListItem(subLi, rootUl);
      });
    });

    return result;
  }

  function wrapText(text, maxLineLength, continuationIndent) {
    let words = text.split(/\s+/);
    let lines = [];
    let currentLine = '';

    words.forEach(word => {
      let testLine = currentLine ? currentLine + ' ' + word : word;
      if (testLine.length > maxLineLength) {
        if (currentLine) lines.push(currentLine);
        currentLine = word;
      } else {
        currentLine = testLine;
      }
    });
    if (currentLine) lines.push(currentLine);

    return lines.map((line, index) => index === 0 ? line : continuationIndent + line).join('\n');
  }

  // Pomocná funkce, která z textu vždy spolehlivě vymaže případný nápis o omezené dostupnosti
  function cleanBadgeText(text) {
    return text.replace(/omezená dostupnost/gi, '').trim();
  }

  const postHeadings = document.querySelectorAll('h2, h3, h4, h5, h6');
  
  postHeadings.forEach(heading => {
    if (heading.classList.contains('wp-block-post-title')) return;

    let currentLevel = parseInt(heading.tagName.substring(1));
    let blockElements = [heading];
    let curr = heading.nextElementSibling;
    
    while (curr) {
      if (/^H[1-6]$/.test(curr.tagName)) {
        let nextLevel = parseInt(curr.tagName.substring(1));
        if (nextLevel <= currentLevel) {
          break; 
        }
      }
      blockElements.push(curr);
      curr = curr.nextElementSibling;
    }

    heading.classList.add('recipe-clickable');
    heading.title = "Klepnutím zkopírujete celou sekci";

    heading.addEventListener('mouseenter', () => {
      blockElements.forEach(el => el.classList.add('recipe-section-hover'));
    });
    heading.addEventListener('mouseleave', () => {
      blockElements.forEach(el => el.classList.remove('recipe-section-hover'));
    });

    heading.addEventListener('click', function(e) {
      // Úplně čistý text nadpisu bez štítku
      let rawHeadingText = cleanBadgeText(heading.innerText);
      let fullText = rawHeadingText.toUpperCase();
      
      blockElements.slice(1).forEach(el => {
        let elementsToProcess = [];
        
        if (/^(P|UL|OL|H[1-6])$/.test(el.tagName)) {
            elementsToProcess.push(el);
        } else {
            let candidates = el.querySelectorAll('p, ul, ol, h1, h2, h3, h4, h5, h6');
            let hasCandidates = false;
            candidates.forEach(cand => {
                if (/^(UL|OL)$/.test(cand.tagName)) {
                    if (!cand.parentElement.closest('ul, ol')) {
                        elementsToProcess.push(cand);
                        hasCandidates = true;
                    }
                } else {
                    if (!cand.closest('ul, ol')) {
                        elementsToProcess.push(cand);
                        hasCandidates = true;
                    }
                }
            });
            if (!hasCandidates && el.innerText.trim() !== "") {
                elementsToProcess.push(el);
            }
        }

        elementsToProcess.forEach(node => {
            if (node.tagName === 'UL' || node.tagName === 'OL') {
                node.querySelectorAll(':scope > li').forEach(li => {
                    fullText += '\n' + formatListItem(li, node);
                });
            } else if (/^H[1-6]$/.test(node.tagName)) {
                // Vyčistíme i případné nadpisy uvnitř sekce
                let cleanSubHeading = cleanBadgeText(node.innerText);
                if (cleanSubHeading !== "") {
                    fullText += '\n\n' + cleanSubHeading.toUpperCase();
                }
            } else {
                let cleanText = cleanBadgeText(node.innerText);
                if (cleanText !== "") {
                    fullText += '\n\n' + cleanText;
                }
            }
        });
      });
      
      blockElements.forEach(el => {
        el.classList.remove('copied-flash');
        void el.offsetWidth; 
        el.classList.add('copied-flash');
        setTimeout(() => el.classList.remove('copied-flash'), 800);
      });

      navigator.clipboard.writeText(fullText);
    });

    blockElements.slice(1).forEach(el => {
      if (/^H[1-6]$/.test(el.tagName)) return;

      let listItems = el.tagName === 'LI' ? [el] : el.querySelectorAll('li');
      listItems.forEach(listItem => {
        listItem.classList.add('recipe-clickable');
        listItem.title = "Klepnutím zkopírujete tento bod";
        
        listItem.addEventListener('click', function(e) {
          e.stopPropagation(); 
          
          let rootUl = listItem.closest('ul') || listItem.closest('ol');
          while(rootUl && rootUl.parentElement && (rootUl.parentElement.tagName === 'UL' || rootUl.parentElement.tagName === 'OL' || rootUl.parentElement.tagName === 'LI')) {
            let nextRoot = rootUl.parentElement.closest('ul') || rootUl.parentElement.closest('ol');
            if (nextRoot) rootUl = nextRoot;
            else break;
          }

          const textToCopy = formatListItem(listItem, rootUl);
          
          listItem.classList.remove('copied-flash');
          void listItem.offsetWidth;
          listItem.classList.add('copied-flash');
          setTimeout(() => listItem.classList.remove('copied-flash'), 800);

          navigator.clipboard.writeText(textToCopy);
        });
      });

      let paras = Array.from(el.querySelectorAll('p'));
      if (el.tagName === 'P') paras.push(el);
      
      if (paras.length === 0 && !/^H[1-6]$/.test(el.tagName) && el.tagName !== 'UL' && el.tagName !== 'OL' && el.tagName !== 'LI' && !el.querySelector('ul, ol, li' ) && el.innerText.trim() !== "") {
        paras.push(el);
      }

      paras.forEach(p => {
        if (p.closest('li')) return; 
        
        p.classList.add('recipe-clickable');
        p.title = "Klepnutím zkopírujete tento odstavec";
        
        p.addEventListener('click', function(e) {
          e.stopPropagation();
          const textToCopy = p.innerText.trim();
          
          p.classList.add('copied-flash');
          setTimeout(() => p.classList.remove('copied-flash'), 800);

          navigator.clipboard.writeText(textToCopy);
        });
      });
    });
  });
});
</script>

<!-- *************************************** -->
<!-- *************************************** -->
<!-- *************************************** -->

<!-- MODUL 4: Automatický štítek "Omezená dostupnost" pro konkrétní recepty -->
<style>
.availability-badge {
  display: inline-block;
  margin-left: 10px;
  padding: 2px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #fff;
  background-color: #b33939;
  border-radius: 4px;
  vertical-align: middle;
  user-select: none;
}
</style>

<script>
document.addEventListener("DOMContentLoaded", function() {
  // Cílíme primárně na podnadpisy receptů (H3 a H4)
  const recipeHeadings = document.querySelectorAll('h3.wp-block-heading, h4.wp-block-heading, h3, h4');
  
  recipeHeadings.forEach(heading => {
    if (heading.classList.contains('wp-block-post-title')) return;
    if (heading.querySelector('.availability-badge')) return;

    // Ověření, zda jde o skutečný recept (zda po něm následuje seznam UL dříve, než jiný nadpis)
    let checker = heading.nextElementSibling;
    let isRecipe = false;
    while (checker) {
      if (checker.tagName === 'UL') {
        isRecipe = true;
        break;
      }
      if (checker.tagName && /^H[1-6]$/.test(checker.tagName)) {
        break;
      }
      checker = checker.nextElementSibling;
    }
    
    if (!isRecipe) return;

    // Sesbírání textu pouze pro tento jeden konkrétní recept
    let blockTextForBadge = heading.innerText.toLowerCase();
    let curr = heading.nextElementSibling;
    
    while(curr && !curr.classList.contains('wp-block-heading') && !/^H[1-6]$/.test(curr.tagName)) {
      blockTextForBadge += " " + curr.innerText.toLowerCase();
      curr = curr.nextElementSibling;
    }

    // Detekce klíčových slov pro omezenou dostupnost
    if (blockTextForBadge.includes('nedostup') || 
        blockTextForBadge.includes('nedodáv') || 
        blockTextForBadge.includes('nesehnateln')) {
      
      const badge = document.createElement('span');
      badge.className = 'availability-badge';
      badge.innerText = 'Omezená dostupnost';
      heading.appendChild(badge);
    }
  });
});
</script>