MediaWiki:Common.js: Porovnání verzí

Z Wiki JU
Ofara (diskuse | příspěvky)
Bez shrnutí editace
značka: revertováno
Ofara (diskuse | příspěvky)
Bez shrnutí editace
značka: revertováno
Řádek 63: Řádek 63:
//Vyhledávání
//Vyhledávání


/* Special:Search – profil=advanced, whitelist NS, přejmenování, default check; safe bez smyček */
/* Special:Search – profil=advanced, whitelist, přejmenování, default check (bez zacyklení) */
(function () {
(function () {
   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;


   // 1) Vynutit profil=advanced (jednorázové přesměrování)
   // vynutit profil=advanced
   const url = new URL(location.href);
   const url = new URL(location.href);
   if (url.searchParams.get('profile') !== 'advanced') {
   if (url.searchParams.get('profile') !== 'advanced') {
Řádek 75: Řádek 75:
   }
   }


  // --- Nastavení ---
  // Ponechat pouze tyto názvy (před NEBO po přejmenování – viz níže)
   const KEEP = new Set([
   const KEEP = new Set([
     '(Hlavní)', 'Stránky',
     '(Hlavní)', 'Stránky',
Řádek 85: Řádek 83:
     'Kategorie'
     'Kategorie'
   ]);
   ]);
  // Které mají být defaultně zaškrtnuté (stačí původní název)
   const DEFAULT_CHECK = new Set(['(Hlavní)', 'PřF']);
   const DEFAULT_CHECK = new Set(['(Hlavní)', 'PřF']);
  // Přejmenování (původní text -> nový text)
   const RENAME = new Map([
   const RENAME = new Map([
     ['(Hlavní)', 'Stránky'],
     ['(Hlavní)', 'Stránky'],
     ['PřF',      'Binolupa – Přirodovědecká fakulta']
     ['PřF',      'Binolupa – Přirodovědecká fakulta']
   ]);
   ]);
   const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();
   const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();


  let isApplying = false; // zámek proti reentranci
   function apply() {
  let lastApply = 0;      // debounce
 
   function applyOnce() {
    if (isApplying) return;
    isApplying = true;
 
    // Schovat horní záložky profilů
     const tabs = document.querySelector('.mw-search-profile-tabs');
     const tabs = document.querySelector('.mw-search-profile-tabs');
     if (tabs) tabs.style.display = 'none';
     if (tabs) tabs.style.display = 'none';


     const root =
     const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
      document.querySelector('#mw-searchoptions') ||
     if (!root) return;
      document.querySelector('.mw-search-nsoptions');
     if (!root) { isApplying = false; return; }


    // projít všechny řádky s checkboxy (OOUI)
     root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
     root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
       const labelEl = row.querySelector('label.oo-ui-labelElement-label');
       const label = row.querySelector('label.oo-ui-labelElement-label');
       const cb = row.querySelector('input[type="checkbox"]');
       const cb = row.querySelector('input[type="checkbox"]');
       if (!labelEl || !cb) return;
       if (!label || !cb) return;


      // ulož původní text (jen 1×)
       if (!row.dataset.origLabel) row.dataset.origLabel = norm(label.textContent);
       if (!row.dataset.origLabel) row.dataset.origLabel = norm(labelEl.textContent);
       const orig = row.dataset.origLabel;
       const orig = row.dataset.origLabel;


      // přejmenuj podle mapy (jen vizuálně)
       if (RENAME.has(orig)) label.textContent = RENAME.get(orig);
       if (RENAME.has(orig)) labelEl.textContent = RENAME.get(orig);
       const current = norm(label.textContent);
 
       const current = norm(labelEl.textContent);


      // ponech jen whitelist; ostatní schovej a odškrtni
       const keep = KEEP.has(orig) || KEEP.has(current);
       const keep = KEEP.has(orig) || KEEP.has(current);
       if (!keep) {
       row.classList.toggle('ns-hide', !keep);   // <<< skrýváme přes třídu
        row.style.display = 'none';
      if (!keep) { cb.checked = false; return; }
        cb.checked = false;
        return;
      } else {
        row.style.display = ''; // ujisti se, že whitelist je vidět
      }


      // default zaškrtnutí pro vybrané (podle původního názvu)
       if (DEFAULT_CHECK.has(orig)) cb.checked = true;
       if (DEFAULT_CHECK.has(orig)) cb.checked = true;
     });
     });
    isApplying = false;
    lastApply = Date.now();
   }
   }


   // Debounce wrapper pro volání applyOnce
   mw.hook('wikipage.content').add(apply);
  function scheduleApply() {
    const now = Date.now();
    if (now - lastApply < 50) return; // drobný debounce
    applyOnce();
  }


   // Aplikuj po načtení obsahu
   // pozoruj jen kontejner vyhledávacích voleb
  mw.hook('wikipage.content').add(applyOnce);
   (function observeContainer () {
 
     const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
  // Sleduj **jen kontejner vyhledávacích voleb**, ne celé body
     if (!root) { setTimeout(observeContainer, 100); return; }
   (function observeContainer() {
     new MutationObserver(apply).observe(root, { childList: true, subtree: true });
     const root =
      document.querySelector('#mw-searchoptions') ||
      document.querySelector('.mw-search-nsoptions');
     if (!root) {
      // počkej, až se objeví; zkus znovu po micro-delay
      setTimeout(observeContainer, 100);
      return;
    }
     const mo = new MutationObserver(scheduleApply);
    mo.observe(root, { childList: true, subtree: true });
   })();
   })();
  // Pro jistotu znovu po kliknutí na „Všechno/Nic“ (pokud jsou přítomná)
  document.addEventListener('click', function (e) {
    const t = e.target;
    if (!t) return;
    if (
      t.closest('.mw-search-nsinput') ||                  // někde uvnitř boxu
      (t.matches('button') && /Všechno|Nic/.test(t.textContent || ''))
    ) {
      setTimeout(scheduleApply, 0);
    }
  });
})();
})();

Verze z 25. 9. 2025, 08:19

/* Zde uvedený JavaScript bude použit pro všechny uživatele při načtení každé stránky */

//Zpětná vazba

$(function () {
  // Zruš jQuery UI vzhled tlačítka
  $('.articleFeedbackv5-submit').button('destroy');
});

document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('.extern-download').forEach(el => {
    el.style.cursor = 'pointer';
    el.style.color = '#0645AD';
    el.style.textDecoration = 'underline';
    el.addEventListener('click', () => {
      const a = document.createElement('a');
      a.href = el.getAttribute('data-url');
      a.setAttribute('download', '');
      a.style.display = 'none';
      document.body.appendChild(a);
      a.click();
      document.body.removeChild(a);
    });
  });
});

(function () {
  var NOTE_ID = 'af5-note';
  var NOTE_HTML =
    '<div id="' + NOTE_ID + '" class="articleFeedbackv5-note">' +
      '<b>Tento formulář slouží pouze jako zpětná vazba pro tuto stránku.</b> ' +
      'Řešíte-li nějaký problém, napište e-mail na ' +
      '<a href="/Servicedesk/Seznam_e-mailových_adres_pro_zadávání_požadavků">službu,</a> které se Váš problém týká.' +
    '</div>';

   function injectNote(root) {
    var $title = (root ? $(root) : $(document))
      .find('.articleFeedbackv5-title-wrap')
      .first();

    if (!$title.length) return false;                 // nadpis není
    if (document.getElementById(NOTE_ID)) return true; // už vloženo

    $title.after(NOTE_HTML);                          // vložit pod nadpis
    return true;
  }

  if (injectNote()) return;

  var obs = new MutationObserver(function (mutations) {
    for (var m of mutations) {
      if (injectNote(m.target)) {
        obs.disconnect();
        break;
      }
    }
  });

  obs.observe(document.body, { childList: true, subtree: true });
  setTimeout(function () { injectNote(); obs.disconnect(); }, 5000);
})();

//Vyhledávání

/* Special:Search – profil=advanced, whitelist, přejmenování, default check (bez zacyklení) */
(function () {
  if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;

  // vynutit profil=advanced
  const url = new URL(location.href);
  if (url.searchParams.get('profile') !== 'advanced') {
    url.searchParams.set('profile', 'advanced');
    location.replace(url.toString());
    return;
  }

  const KEEP = new Set([
    '(Hlavní)', 'Stránky',
    'Aktuality',
    'Šablona',
    'PřF', 'Binolupa – Přirodovědecká fakulta',
    'Soubor',
    'Kategorie'
  ]);
  const DEFAULT_CHECK = new Set(['(Hlavní)', 'PřF']);
  const RENAME = new Map([
    ['(Hlavní)', 'Stránky'],
    ['PřF',      'Binolupa – Přirodovědecká fakulta']
  ]);
  const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();

  function apply() {
    const tabs = document.querySelector('.mw-search-profile-tabs');
    if (tabs) tabs.style.display = 'none';

    const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
    if (!root) return;

    root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
      const label = row.querySelector('label.oo-ui-labelElement-label');
      const cb = row.querySelector('input[type="checkbox"]');
      if (!label || !cb) return;

      if (!row.dataset.origLabel) row.dataset.origLabel = norm(label.textContent);
      const orig = row.dataset.origLabel;

      if (RENAME.has(orig)) label.textContent = RENAME.get(orig);
      const current = norm(label.textContent);

      const keep = KEEP.has(orig) || KEEP.has(current);
      row.classList.toggle('ns-hide', !keep);   // <<< skrýváme přes třídu
      if (!keep) { cb.checked = false; return; }

      if (DEFAULT_CHECK.has(orig)) cb.checked = true;
    });
  }

  mw.hook('wikipage.content').add(apply);

  // pozoruj jen kontejner vyhledávacích voleb
  (function observeContainer () {
    const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
    if (!root) { setTimeout(observeContainer, 100); return; }
    new MutationObserver(apply).observe(root, { childList: true, subtree: true });
  })();
})();