MediaWiki:Common.js: Porovnání verzí
Z Wiki JU
Bez shrnutí editace značka: revertováno |
Bez shrnutí editace značka: revertováno |
||
| Řádek 151: | Řádek 151: | ||
if (isNaN(nsId)) { | if (isNaN(nsId)) { | ||
const v = cb.getAttribute('value'); | const v = cb.getAttribute('value'); | ||
if (v && /^\d+$/.test(v)) nsId = parseInt(v, 10); | |||
} | |||
// Původní text + přejmenování (vizuální) | |||
const orig = norm(label.textContent); | |||
if (RENAME.has(orig)) label.textContent = RENAME.get(orig); | |||
const current = norm(label.textContent); | |||
// Whitelist: co není povoleno, rovnou odstraň z DOM | |||
const keep = ALLOW_IDS.has(nsId) || ALLOW_NAMES.has(orig) || ALLOW_NAMES.has(current); | |||
if (!keep) { row.remove(); return; } | |||
// Nastavení zaškrtnutí: | |||
// - pokud jsou v URL explicitní ns parametry → drž se jich | |||
// - jinak (teoretická záloha) by se použil default (jen ns0), ale k tomu po úpravě URL nedojde | |||
if (!isNaN(nsId)) { | |||
if (hasExplicitNs) { | |||
cb.checked = requestedNs.has(nsId); // respektuj volbu uživatele (vč. ns0, nsPřF, …) | |||
} else { | |||
cb.checked = (nsId === 0); // fallback: jen Hlavní | |||
} | |||
} | |||
}); | |||
} | |||
// Počkej, až se kontejner i checkboxy opravdu 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); | |||
})(); | |||
Verze z 25. 9. 2025, 09:18
/* 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 — Advanced profil, ns0 v URL, whitelist (remove z DOM), přejmenování, zachování voleb, nadpis */
(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'
]);
// Přejmenování štítků (původní text → nový text)
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();
function getContainer() {
return document.querySelector('#mw-searchoptions, .mw-search-nsoptions');
}
function processOnce(root) {
if (!root || root.dataset.nsTweaked === '1') return;
root.dataset.nsTweaked = '1';
// Nadpis a skrytí horních 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';
// --- přečti volby z URL: nsX=1 → zachovej volbu uživatele 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 našem zajištění bude pravda (min. ns0)
// Najdi všechny checkboxy pro jmenné prostory a zpracuj je
const cbs = root.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"], input[type="checkbox"][name="ns[]"]');
cbs.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;
// Zjisti ID jmenného prostoru
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ůvodní text + přejmenování (vizuální)
const orig = norm(label.textContent);
if (RENAME.has(orig)) label.textContent = RENAME.get(orig);
const current = norm(label.textContent);
// Whitelist: co není povoleno, rovnou odstraň z DOM
const keep = ALLOW_IDS.has(nsId) || ALLOW_NAMES.has(orig) || ALLOW_NAMES.has(current);
if (!keep) { row.remove(); return; }
// Nastavení zaškrtnutí:
// - pokud jsou v URL explicitní ns parametry → drž se jich
// - jinak (teoretická záloha) by se použil default (jen ns0), ale k tomu po úpravě URL nedojde
if (!isNaN(nsId)) {
if (hasExplicitNs) {
cb.checked = requestedNs.has(nsId); // respektuj volbu uživatele (vč. ns0, nsPřF, …)
} else {
cb.checked = (nsId === 0); // fallback: jen Hlavní
}
}
});
}
// Počkej, až se kontejner i checkboxy opravdu 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);
})();