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 – Advanced profil, whitelist | /* Special:Search – Advanced profil, whitelist (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 (jednorázové přesměrování) | ||
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 === | ||
// | // 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 (pro vlastní NS | // 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', | ||
'Aktuality', | 'Aktuality', | ||
'PřF', 'Binolupa – | 'PřF', 'Binolupa – Přírodovědecká fakulta', | ||
'Šablona', ' | 'Soubor', 'Soubory', | ||
'Šablona', 'Šablony', | |||
'Kategorie' | |||
]); | ]); | ||
// Defaultně zaškrtnout (podle | // Defaultně zaškrtnout Stránky (ID 0) + PřF (podle názvu) | ||
const DEFAULT_CHECK_IDS = new Set([0]); | const DEFAULT_CHECK_IDS = new Set([0]); | ||
// Přejmenování | // Přejmenování štítků | ||
const RENAME = new Map([ | const RENAME = new Map([ | ||
['(Hlavní)', 'Stránky'], | ['(Hlavní)', 'Stránky'], | ||
['Hlavní', 'Stránky'], | ['Hlavní', 'Stránky'], | ||
['PřF', 'Binolupa – | ['PřF', 'Binolupa – Přírodovědecká fakulta'], | ||
['Soubor', 'Soubory'], | |||
['Šablona', 'Šablony'] | |||
]); | ]); | ||
const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim(); | const norm = s => String(s || '').replace(/\u00A0/g, ' ').replace(/\s+/g, ' ').trim(); | ||
const isPrF = t => /^(PřF|Binolupa – | const isPrF = t => /^(PřF|Binolupa – Přírodovědecká fakulta)$/i.test(norm(t)); | ||
function | function apply() { | ||
// | // Schovat horní profilové záložky | ||
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 | // Přepsat nadpis | ||
const container = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions'); | |||
if (container) { | |||
const heading = container.querySelector('h4, legend, .mw-search-togglebox h4'); | |||
if (heading && norm(heading.textContent).length) heading.textContent = 'Co chcete vyhledávat?'; | |||
} | |||
const root = container; | |||
if (!root) return; | if (!root) return; | ||
// | // Odstraň nechtěné NS a uprav povolené | ||
root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => { | root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => { | ||
const cb = row.querySelector('input[type="checkbox"]'); | const cb = row.querySelector('input[type="checkbox"]'); | ||
const | const lbl = row.querySelector('label.oo-ui-labelElement-label'); | ||
if (!cb || ! | if (!cb || !lbl) return; | ||
// | // ID NS | ||
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 124: | Řádek 134: | ||
} | } | ||
// | // Původní text | ||
if (!row.dataset.origLabel) row.dataset.origLabel = norm( | if (!row.dataset.origLabel) row.dataset.origLabel = norm(lbl.textContent); | ||
const orig = row.dataset.origLabel; | const orig = row.dataset.origLabel; | ||
// | // Přejmenování (jen jednou) | ||
if (!row.dataset.renamed && RENAME.has(orig)) { | if (!row.dataset.renamed && RENAME.has(orig)) { | ||
lbl.textContent = RENAME.get(orig); | |||
row.dataset.renamed = '1'; | row.dataset.renamed = '1'; | ||
} | } | ||
const current = norm( | const current = norm(lbl.textContent); | ||
// | // Whitelist: pokud neprojde, odstranit z DOM | ||
const keep = ALLOW_IDS.has(nsId) || ALLOW_NAMES.has(orig) || ALLOW_NAMES.has(current); | 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; | |||
// Defaultně zaškrtnout Stránky | |||
if (DEFAULT_CHECK_IDS.has(nsId) || isPrF(orig) || isPrF(current)) | |||
}); | }); | ||
} | } | ||
// | // Po načtení obsahu | ||
mw.hook('wikipage.content').add( | mw.hook('wikipage.content').add(apply); | ||
// Sleduj | // Sleduj jen kontejner NS; při přestavbě OOUI znovu apply() | ||
(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(() => apply()).observe(root, { childList: true, subtree: true }); | ||
})(); | })(); | ||
})(); | })(); | ||
Verze z 25. 9. 2025, 08:40
/* 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, whitelist (remove z DOM), přejmenování, default check, nadpis */
(function () {
if (mw.config.get('wgCanonicalSpecialPageName') !== 'Search') return;
// Vynutit profil=advanced (jednorázové přesměrování)
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 (podle názvu)
const DEFAULT_CHECK_IDS = new Set([0]);
// Přejmenování š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));
function apply() {
// 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, .mw-search-togglebox h4');
if (heading && norm(heading.textContent).length) heading.textContent = 'Co chcete vyhledávat?';
}
const root = container;
if (!root) return;
// Odstraň nechtěné NS a uprav povolené
root.querySelectorAll('.oo-ui-fieldLayout').forEach(row => {
const cb = row.querySelector('input[type="checkbox"]');
const lbl = row.querySelector('label.oo-ui-labelElement-label');
if (!cb || !lbl) return;
// ID NS
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
if (!row.dataset.origLabel) row.dataset.origLabel = norm(lbl.textContent);
const orig = row.dataset.origLabel;
// Přejmenování (jen jednou)
if (!row.dataset.renamed && RENAME.has(orig)) {
lbl.textContent = RENAME.get(orig);
row.dataset.renamed = '1';
}
const current = norm(lbl.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;
});
}
// Po načtení obsahu
mw.hook('wikipage.content').add(apply);
// Sleduj jen kontejner NS; při přestavbě OOUI znovu apply()
(function observe() {
const root = document.querySelector('#mw-searchoptions') || document.querySelector('.mw-search-nsoptions');
if (!root) { setTimeout(observe, 120); return; }
new MutationObserver(() => apply()).observe(root, { childList: true, subtree: true });
})();
})();