MediaWiki:Common.js: Porovnání verzí
Z Wiki JU
Bez shrnutí editace značka: revertováno |
Bez shrnutí editace značka: revertováno |
||
| Řádek 63: | Řádek 63: | ||
//Vyhledávání | //Vyhledávání | ||
/* Special:Search | /* Special:Search — profil=advanced, whitelist NS (remove z DOM), přejmenování, default check, nadpis */ | ||
(function () { | (function () { | ||
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return; | ||
// Vynutit profil=advanced ( | // 1) Vynutit profil=advanced (provedeme jednou přesměrováním) | ||
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: | ||
} | } | ||
// === KONFIGURACE === | // ===== KONFIGURACE ===== | ||
// Standardní ID: 0 Hlavní, 6 Soubor, 10 Šablona, 14 Kategorie | // Standardní ID: 0 Hlavní, 6 Soubor, 10 Šablona, 14 Kategorie | ||
const ALLOW_IDS = new Set([0, 6, 10, 14]); | const ALLOW_IDS = new Set([0, 6, 10, 14]); | ||
// Povolené názvy (před/po přejmenování) pro vlastní NS a jistotu | // Povolené názvy (před/po přejmenování) – pro vlastní NS a jistotu | ||
const ALLOW_NAMES = new Set([ | const ALLOW_NAMES = new Set([ | ||
'(Hlavní)', 'Hlavní', 'Stránky', | '(Hlavní)', 'Hlavní', 'Stránky', | ||
| Řádek 89: | Řádek 89: | ||
]); | ]); | ||
// Defaultně zaškrtnout Stránky (ID 0) + PřF ( | // Defaultně zaškrtnout: Stránky (ID 0) + PřF (dle názvu) | ||
const DEFAULT_CHECK_IDS = new Set([0]); | const DEFAULT_CHECK_IDS = new Set([0]); | ||
// Přejmenování štítků | // Přejmenování zobrazených štítků | ||
const RENAME = new Map([ | const RENAME = new Map([ | ||
['(Hlavní)', 'Stránky'], | ['(Hlavní)', 'Stránky'], | ||
| Řádek 104: | Řádek 104: | ||
const isPrF = t => /^(PřF|Binolupa – Přírodovědecká fakulta)$/i.test(norm(t)); | const isPrF = t => /^(PřF|Binolupa – Přírodovědecká fakulta)$/i.test(norm(t)); | ||
function | // Najdi „řádek“ s checkboxem (funguje napříč skiny) | ||
function findRow(el) { | |||
let n = el; | |||
for (let i = 0; i < 6 && n; i++) { | |||
if (n.classList && (n.classList.contains('oo-ui-fieldLayout') || n.classList.contains('mw-htmlform-field-HTMLCheckMatrix'))) { | |||
return n; | |||
} | |||
n = n.parentElement; | |||
} | |||
// fallback: nejbližší DIV | |||
n = el; | |||
for (let i = 0; i < 6 && n; i++) { | |||
if (n.tagName === 'DIV') return n; | |||
n = n.parentElement; | |||
} | |||
return el; | |||
} | |||
function process() { | |||
// Schovat horní profilové záložky | // Schovat horní profilové záložky | ||
const tabs = document.querySelector('.mw-search-profile-tabs'); | const tabs = document.querySelector('.mw-search-profile-tabs'); | ||
| Řádek 112: | Řádek 130: | ||
const container = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | const container = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | ||
if (container) { | if (container) { | ||
const heading = container.querySelector('h4, legend | const heading = container.querySelector('h4, legend'); | ||
if (heading | if (heading) heading.textContent = 'Co chcete vyhledávat?'; | ||
} | } | ||
if (!container) return; | |||
const | // Všechny checkboxy „namespace“ (robustní výběr) | ||
if (! | const cbs = container.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"], input[type="checkbox"][name="ns[]"]'); | ||
cbs.forEach(cb => { | |||
const row = findRow(cb); | |||
// Zjisti label | |||
const labelEl = | |||
(cb.id && container.querySelector('label[for="' + cb.id + '"]')) || | |||
row.querySelector('label') || | |||
null; | |||
if (!labelEl) return; | |||
// Zjisti NS id | |||
// | |||
let nsId = NaN; | let nsId = NaN; | ||
const m = cb.id && cb.id.match(/mw-search-ns(\d+)/); | const m = cb.id && cb.id.match(/mw-search-ns(\d+)/); | ||
| Řádek 134: | Řádek 155: | ||
} | } | ||
// Původní text | // Původní text (ulož 1×), případné přejmenování | ||
if (!row.dataset.origLabel) row.dataset.origLabel = norm( | if (!row.dataset.origLabel) row.dataset.origLabel = norm(labelEl.textContent); | ||
const orig = row.dataset.origLabel; | const orig = row.dataset.origLabel; | ||
if (!row.dataset.renamed && RENAME.has(orig)) { | if (!row.dataset.renamed && RENAME.has(orig)) { | ||
labelEl.textContent = RENAME.get(orig); | |||
row.dataset.renamed = '1'; | row.dataset.renamed = '1'; | ||
} | } | ||
const current = norm( | const current = norm(labelEl.textContent); | ||
// Whitelist: pokud neprojde, odstranit z DOM | // Whitelist: pokud neprojde, odstranit z DOM | ||
| Řádek 154: | Řádek 173: | ||
} | } | ||
// | // Spusť po načtení obsahu | ||
mw.hook('wikipage.content').add( | mw.hook('wikipage.content').add(process); | ||
// | // Znovu aplikuj, když se konkrétní kontejner překreslí (OOUI/klik na „Všechno/Nic“ ap.) | ||
(function observe() { | (function observe() { | ||
const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | ||
if (!root) { setTimeout(observe, 120); return; } | if (!root) { setTimeout(observe, 120); return; } | ||
new MutationObserver(() => | new MutationObserver(() => process()).observe(root, { childList: true, subtree: true }); | ||
})(); | })(); | ||
})(); | })(); | ||
Verze z 25. 9. 2025, 08:43
/* 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 NS (remove z DOM), přejmenování, default check, nadpis */
(function () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
// 1) Vynutit profil=advanced (provedeme jednou přesměrováním)
const url = new URL(location.href);
if (url.searchParams.get('profile') !== 'advanced') {
url.searchParams.set('profile', 'advanced');
location.replace(url.toString());
return;
}
// ===== KONFIGURACE =====
// Standardní ID: 0 Hlavní, 6 Soubor, 10 Šablona, 14 Kategorie
const ALLOW_IDS = new Set([0, 6, 10, 14]);
// Povolené názvy (před/po přejmenování) – pro vlastní NS a jistotu
const ALLOW_NAMES = new Set([
'(Hlavní)', 'Hlavní', 'Stránky',
'Aktuality',
'PřF', 'Binolupa – Přírodovědecká fakulta',
'Soubor', 'Soubory',
'Šablona', 'Šablony',
'Kategorie'
]);
// Defaultně zaškrtnout: Stránky (ID 0) + PřF (dle názvu)
const DEFAULT_CHECK_IDS = new Set([0]);
// Přejmenování zobrazených štítků
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 isPrF = t => /^(PřF|Binolupa – Přírodovědecká fakulta)$/i.test(norm(t));
// Najdi „řádek“ s checkboxem (funguje napříč skiny)
function findRow(el) {
let n = el;
for (let i = 0; i < 6 && n; i++) {
if (n.classList && (n.classList.contains('oo-ui-fieldLayout') || n.classList.contains('mw-htmlform-field-HTMLCheckMatrix'))) {
return n;
}
n = n.parentElement;
}
// fallback: nejbližší DIV
n = el;
for (let i = 0; i < 6 && n; i++) {
if (n.tagName === 'DIV') return n;
n = n.parentElement;
}
return el;
}
function process() {
// Schovat horní profilové záložky
const tabs = document.querySelector('.mw-search-profile-tabs');
if (tabs) tabs.style.display = 'none';
// Přepsat nadpis
const container = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
if (container) {
const heading = container.querySelector('h4, legend');
if (heading) heading.textContent = 'Co chcete vyhledávat?';
}
if (!container) return;
// Všechny checkboxy „namespace“ (robustní výběr)
const cbs = container.querySelectorAll('input[type="checkbox"][id^="mw-search-ns"], input[type="checkbox"][name="ns[]"]');
cbs.forEach(cb => {
const row = findRow(cb);
// Zjisti label
const labelEl =
(cb.id && container.querySelector('label[for="' + cb.id + '"]')) ||
row.querySelector('label') ||
null;
if (!labelEl) return;
// Zjisti 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ůvodní text (ulož 1×), případné přejmenování
if (!row.dataset.origLabel) row.dataset.origLabel = norm(labelEl.textContent);
const orig = row.dataset.origLabel;
if (!row.dataset.renamed && RENAME.has(orig)) {
labelEl.textContent = RENAME.get(orig);
row.dataset.renamed = '1';
}
const current = norm(labelEl.textContent);
// Whitelist: pokud neprojde, odstranit z DOM
const keep = ALLOW_IDS.has(nsId) || ALLOW_NAMES.has(orig) || ALLOW_NAMES.has(current);
if (!keep) { row.remove(); return; }
// Defaultně zaškrtnout Stránky + PřF
if (DEFAULT_CHECK_IDS.has(nsId) || isPrF(orig) || isPrF(current)) cb.checked = true;
});
}
// Spusť po načtení obsahu
mw.hook('wikipage.content').add(process);
// Znovu aplikuj, když se konkrétní kontejner překreslí (OOUI/klik na „Všechno/Nic“ ap.)
(function observe() {
const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
if (!root) { setTimeout(observe, 120); return; }
new MutationObserver(() => process()).observe(root, { childList: true, subtree: true });
})();
})();