|
Мітки: Ручний відкіт Скасовано |
| Рядок 120: |
Рядок 120: |
| ); | | ); |
| }, 1000); | | }, 1000); |
| });
| |
|
| |
| //JJJJ
| |
| 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) {
| |
| const link = e.target.closest('a[href*="Файл:"], a[href*="File:"]');
| |
| if (!link) return;
| |
|
| |
| const href = link.getAttribute('href');
| |
| if (!href.includes('#/media/')) {
| |
| e.preventDefault();
| |
|
| |
| const fileMatch = href.match(/(Файл:[^#?]+)/);
| |
| if (!fileMatch) return;
| |
|
| |
| const fileName = fileMatch[1];
| |
| const newHref = href.split('#')[0] + '#/media/' + encodeURIComponent(fileName);
| |
|
| |
| window.location.href = newHref;
| |
| }
| |
| });
| |
| }
| |
|
| |
| function init() {
| |
| redirectDirectFileView();
| |
| overrideFileLinks();
| |
| }
| |
|
| |
| if (document.readyState === 'loading') {
| |
| document.addEventListener('DOMContentLoaded', init);
| |
| } else {
| |
| init();
| |
| }
| |
| }); | | }); |