MediaWiki:Common.js: відмінності між версіями
Wiki (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
Wiki (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
||
| Рядок 123: | Рядок 123: | ||
//JJJJ | //JJJJ | ||
(function() { | mw.loader.using('mediawiki.util', function () { | ||
function redirectDirectFileView() { | |||
const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp']; | |||
const url = window.location.href.toLowerCase(); | |||
if (url.includes('/w/images/')) { | |||
for (const ext of imageExtensions) { | |||
if (url.endsWith(ext)) { | |||
const parts = url.split('/'); | |||
const fileName = decodeURIComponent(parts[parts.length - 1]); | |||
const mediaPageUrl = `/w/index.php/Файл:${encodeURIComponent(fileName)}#/media/Файл:${encodeURIComponent(fileName)}`; | |||
window.location.replace(mediaPageUrl); | |||
break; | |||
} | |||
} | } | ||
} | } | ||
} | } | ||
function overrideFileLinks() { | |||
document.body.addEventListener('click', function (e) { | |||
function | const link = e.target.closest('a[href*="Файл:"], a[href*="File:"]'); | ||
document.body.addEventListener('click', function(e) { | if (!link) return; | ||
const | |||
if (! | |||
const href = link.getAttribute('href'); | |||
if (href.includes('/ | if (!href.includes('#/media/')) { | ||
e.preventDefault(); | e.preventDefault(); | ||
const | const fileMatch = href.match(/(Файл:[^#?]+)/); | ||
const fileName = | if (!fileMatch) return; | ||
const | |||
const fileName = fileMatch[1]; | |||
const newHref = href.split('#')[0] + '#/media/' + encodeURIComponent(fileName); | |||
window.location.href = | window.location.href = newHref; | ||
} | } | ||
}); | }); | ||
} | } | ||
document.addEventListener('DOMContentLoaded', | |||
function init() { | |||
redirectDirectFileView(); | |||
overrideFileLinks(); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', init); | |||
} else { | |||
init(); | |||
} | |||
}); | }); | ||