|
|
| Řádek 62: |
Řádek 62: |
|
| |
|
| //Vyhledávání | | //Vyhledávání |
|
| |
| /* Special:Search — Timeless: advanced profil, ns0 v URL, whitelist (remove z DOM),
| |
| přejmenování, zachování voleb, skrytí „Zapamatovat si…“, změna nadpisu,
| |
| robustní submit (vč. horního vyhledávacího pole) */
| |
| (function () {
| |
| if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
| |
|
| |
| // ── 1) Uprav URL jednorázově (profile=advanced + ns0=1) a reloadni, pokud bylo něco doplněno
| |
| (function ensureUrlParams() {
| |
| const url = new URL(location.href);
| |
| let changed = false;
| |
|
| |
| if (url.searchParams.get('profile') !== 'advanced') {
| |
| url.searchParams.set('profile', 'advanced');
| |
| changed = true;
| |
| }
| |
| // když chybí ns0 nebo nejsou žádné ns parametry → přidej ns0=1
| |
| const hasAnyNs = Array.from(url.searchParams.keys()).some(k => /^ns\d+$/.test(k));
| |
| if (!hasAnyNs || !url.searchParams.has('ns0')) {
| |
| url.searchParams.set('ns0', '1');
| |
| changed = true;
| |
| }
| |
| if (changed) {
| |
| location.replace(url.toString()); // jednorázový reload, žádná smyčka
| |
| return;
| |
| }
| |
| })();
| |
|
| |
| // ── 2) Konfigurace
| |
| // standardní NS ID: 0 Hlavní, 6 Soubor, 10 Šablona, 14 Kategorie
| |
| const ALLOW_IDS = new Set([0, 6, 10, 14]);
| |
| const ALLOW_NAMES = new Set([
| |
| '(Hlavní)', 'Hlavní', 'Stránky',
| |
| 'Aktuality',
| |
| 'PřF', 'Binolupa – Přírodovědecká fakulta',
| |
| 'Soubor', 'Soubory',
| |
| 'Šablona', 'Šablony',
| |
| 'Kategorie'
| |
| ]);
| |
| const RENAME = new Map([
| |
| ['(Hlavní)', 'Stránky'],
| |
| ['Hlavní', 'Stránky'],
| |
| ['PřF', 'Binolupa – Přírodovědecká fakulta'],
| |
| ['Soubor', 'Soubory'],
| |
| ['Šablona', 'Šablony']
| |
| ]);
| |
|
| |
| const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim();
| |
| const getContainer = () => document.querySelector('#mw-searchoptions, .mw-search-nsoptions');
| |
|
| |
| // ── 3) Úprava UI + respektování voleb z URL
| |
| function processOnce(root) {
| |
| if (!root || root.dataset.nsTweaked === '1') return;
| |
| root.dataset.nsTweaked = '1';
| |
|
| |
| // Nadpis a skrytí profilových záložek
| |
| const heading = root.querySelector('h4, legend');
| |
| if (heading) heading.textContent = 'Co chcete vyhledávat?';
| |
| const tabs = document.querySelector('.mw-search-profile-tabs');
| |
| if (tabs) tabs.style.display = 'none';
| |
|
| |
| // Schovat „Zapamatovat si výběr…“
| |
| (function hideRememberRow() {
| |
| const input = root.querySelector('#mw-search-powersearch-remember');
| |
| const row = input?.closest('.oo-ui-fieldLayout') || root.querySelector('label[for="mw-search-powersearch-remember"]')?.closest('.oo-ui-fieldLayout');
| |
| if (row) row.remove();
| |
| })();
| |
|
| |
| // Volby z URL (nsX=1) → zachovat při reloadu
| |
| const sp = new URL(location.href).searchParams;
| |
| const requestedNs = new Set();
| |
| for (const [k, v] of sp) {
| |
| const m = /^ns(\d+)$/.exec(k);
| |
| if (m && v !== '0') requestedNs.add(parseInt(m[1], 10));
| |
| }
| |
| const hasExplicitNs = requestedNs.size > 0; // po zajištění výše min. ns0
| |
|
| |
| // Zpracuj checkboxy jmenných prostorů
| |
| root.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"], input[type="checkbox"][name="ns[]"]').forEach(cb => {
| |
| const row = cb.closest('.oo-ui-fieldLayout') || cb.closest('div');
| |
| if (!row) return;
| |
|
| |
| const label = (cb.id && root.querySelector(`label[for="${cb.id}"]`)) || row.querySelector('label');
| |
| if (!label) return;
| |
|
| |
| // NS ID
| |
| let nsId = NaN;
| |
| const m = cb.id && cb.id.match(/mw-search-ns(\d+)/);
| |
| if (m) nsId = parseInt(m[1], 10);
| |
| if (isNaN(nsId)) {
| |
| const v = cb.getAttribute('value');
| |
| if (v && /^\d+$/.test(v)) nsId = parseInt(v, 10);
| |
| }
| |
|
| |
| // Přejmenování a whitelist
| |
| const orig = norm(label.textContent);
| |
| if (RENAME.has(orig)) label.textContent = RENAME.get(orig);
| |
| const current = norm(label.textContent);
| |
| const keep = ALLOW_IDS.has(nsId) || ALLOW_NAMES.has(orig) || ALLOW_NAMES.has(current);
| |
| if (!keep) { row.remove(); return; }
| |
|
| |
| // Zaškrtnutí: respektuj URL; fallback (hypoteticky) jen ns0
| |
| if (!isNaN(nsId)) {
| |
| if (hasExplicitNs) cb.checked = requestedNs.has(nsId);
| |
| else cb.checked = (nsId === 0);
| |
| }
| |
| });
| |
|
| |
| // ── 4) Robustní submit pro Timeless (všechny search formuláře na stránce)
| |
| bindSearchSubmit(root);
| |
| }
| |
|
| |
| // Sestavení URL a přesměrování při submitu
| |
| function bindSearchSubmit(root) {
| |
| document.querySelectorAll('form').forEach(form => {
| |
| if (form.dataset.searchBound) return;
| |
| const input = form.querySelector('input[name="search"], input[name="searchtext"], input[type="search"]');
| |
| if (!input) return; // není to vyhledávací formulář
| |
| form.dataset.searchBound = '1';
| |
|
| |
| form.addEventListener('submit', function (ev) {
| |
| ev.preventDefault();
| |
|
| |
| const q = input.value || '';
| |
| const target = new URL(mw.util.getUrl('Special:Search'), location.origin);
| |
| if (q) target.searchParams.set('search', q);
| |
| target.searchParams.set('profile', 'advanced');
| |
| target.searchParams.set('fulltext', '1'); // rovnou plnotextové výsledky
| |
| target.searchParams.set('ns0', '1'); // vždy zahrň Hlavní
| |
|
| |
| // Vezmi aktuální stav NS z panelu (pokud je na stránce)
| |
| const boxes = root?.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"]') || [];
| |
| let anyExtra = false;
| |
| boxes.forEach(box => {
| |
| const m = box.id.match(/mw-search-ns(\d+)/);
| |
| if (!m) return;
| |
| if (box.checked) {
| |
| target.searchParams.set('ns' + m[1], '1');
| |
| if (m[1] !== '0') anyExtra = true;
| |
| }
| |
| });
| |
|
| |
| // přesměrování
| |
| location.href = target.toString();
| |
| });
| |
| });
| |
| }
| |
|
| |
| // Počkej, až se kontejner i checkboxy objeví, pak jednou zpracuj
| |
| function waitAndRun(tries = 0) {
| |
| const root = getContainer();
| |
| const ready = root && root.querySelector('input[type="checkbox"][id^="mw-search-ns"], input[type="checkbox"][name="ns[]"]');
| |
| if (ready) { processOnce(root); return; }
| |
| if (tries < 60) setTimeout(() => waitAndRun(tries + 1), 100); // max ~6 s, bez smyček
| |
| }
| |
|
| |
| document.addEventListener('DOMContentLoaded', waitAndRun);
| |
| mw.hook('wikipage.content').add(waitAndRun);
| |
| })();
| |
/* 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í