MediaWiki:Common.js: Porovnání verzí
Z Wiki JU
Bez shrnutí editace |
Bez shrnutí editace značka: revertováno |
||
| Řádek 22: | Řádek 22: | ||
}); | }); | ||
}); | }); | ||
// Unwrap external links when page is viewed via Google Translate proxy | |||
(function () { | |||
function isGoogleTranslateHost(h) { | |||
return /(^|\.)translate\.(goog|google\.com|googleusercontent\.com)$/.test(h); | |||
} | |||
function isGoogleTranslatePage() { | |||
return isGoogleTranslateHost(location.hostname) || | |||
/[?&](_x_tr_|translate_?c=)/.test(location.search) || | |||
/\/translate(_c)?\?/.test(location.href); | |||
} | |||
if (!isGoogleTranslatePage()) return; | |||
// Zjistíme kanonický server wiki (doménu), abychom poznali "interní" odkazy | |||
var canonical = (window.mw && mw.config && mw.config.get) ? mw.config.get('wgCanonicalServer') : null; | |||
var wikiHost = canonical ? new URL(canonical).host : null; | |||
// Vrátí původní URL z různých forem Google Translate wrapperu | |||
function originalUrl(href) { | |||
try { | |||
var url = new URL(href); | |||
// 1) translate.googleusercontent.com/translate_c?...&u=<ORIGINAL> | |||
if (isGoogleTranslateHost(url.hostname) && url.searchParams.get('u')) { | |||
return new URL(url.searchParams.get('u')).href; | |||
} | |||
// 2) *.translate.goog s parametry _x_tr_* | |||
if (url.hostname.endsWith('.translate.goog')) { | |||
var scheme = url.searchParams.get('_x_tr_sch') || 'https'; | |||
var hostPart = url.hostname.slice(0, -'.translate.goog'.length); | |||
var origHost = hostPart.replace(/-/g, '.'); | |||
// ponecháme jen parametry, které nezačínají _x_tr_ | |||
var kept = []; | |||
url.searchParams.forEach(function (v, k) { | |||
if (!/^_x_tr_/.test(k)) kept.push(encodeURIComponent(k) + '=' + encodeURIComponent(v)); | |||
}); | |||
var query = kept.length ? ('?' + kept.join('&')) : ''; | |||
return scheme + '://' + origHost + url.pathname + query + url.hash; | |||
} | |||
return href; | |||
} catch (e) { | |||
return href; | |||
} | |||
} | |||
document.querySelectorAll('a[href]').forEach(function (a) { | |||
var dest = originalUrl(a.href); | |||
if (!wikiHost) return; // Bez znalosti hostu raději nic neupravujeme | |||
try { | |||
var host = new URL(dest).host; | |||
// pokud odkaz vede mimo wiki, odbalíme ho a otevřeme mimo překladač | |||
if (host && host !== wikiHost) { | |||
a.href = dest; | |||
a.target = '_blank'; | |||
a.rel = (a.rel ? a.rel + ' ' : '') + 'noopener noreferrer'; | |||
} | |||
} catch (e) {} | |||
}); | |||
})(); | |||
Verze z 13. 8. 2025, 08:15
/* Zde uvedený JavaScript bude použit pro všechny uživatele při načtení každé stránky */
$(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);
});
});
});
// Unwrap external links when page is viewed via Google Translate proxy
(function () {
function isGoogleTranslateHost(h) {
return /(^|\.)translate\.(goog|google\.com|googleusercontent\.com)$/.test(h);
}
function isGoogleTranslatePage() {
return isGoogleTranslateHost(location.hostname) ||
/[?&](_x_tr_|translate_?c=)/.test(location.search) ||
/\/translate(_c)?\?/.test(location.href);
}
if (!isGoogleTranslatePage()) return;
// Zjistíme kanonický server wiki (doménu), abychom poznali "interní" odkazy
var canonical = (window.mw && mw.config && mw.config.get) ? mw.config.get('wgCanonicalServer') : null;
var wikiHost = canonical ? new URL(canonical).host : null;
// Vrátí původní URL z různých forem Google Translate wrapperu
function originalUrl(href) {
try {
var url = new URL(href);
// 1) translate.googleusercontent.com/translate_c?...&u=<ORIGINAL>
if (isGoogleTranslateHost(url.hostname) && url.searchParams.get('u')) {
return new URL(url.searchParams.get('u')).href;
}
// 2) *.translate.goog s parametry _x_tr_*
if (url.hostname.endsWith('.translate.goog')) {
var scheme = url.searchParams.get('_x_tr_sch') || 'https';
var hostPart = url.hostname.slice(0, -'.translate.goog'.length);
var origHost = hostPart.replace(/-/g, '.');
// ponecháme jen parametry, které nezačínají _x_tr_
var kept = [];
url.searchParams.forEach(function (v, k) {
if (!/^_x_tr_/.test(k)) kept.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
});
var query = kept.length ? ('?' + kept.join('&')) : '';
return scheme + '://' + origHost + url.pathname + query + url.hash;
}
return href;
} catch (e) {
return href;
}
}
document.querySelectorAll('a[href]').forEach(function (a) {
var dest = originalUrl(a.href);
if (!wikiHost) return; // Bez znalosti hostu raději nic neupravujeme
try {
var host = new URL(dest).host;
// pokud odkaz vede mimo wiki, odbalíme ho a otevřeme mimo překladač
if (host && host !== wikiHost) {
a.href = dest;
a.target = '_blank';
a.rel = (a.rel ? a.rel + ' ' : '') + 'noopener noreferrer';
}
} catch (e) {}
});
})();