|
|
| (не показаны 64 промежуточные версии этого же участника) |
| Строка 1: |
Строка 1: |
| /* Нигилистические фокусы (см. [[Шаблон:Нигилизм/doc]]) */ | | /* Нигилистические фокусы (см. шаблон {{tl|Нигилизм}}) */ |
| $(function () { | | $(function () { |
| var nihilism = $('#nihilism'); | | var nihilism = $('#nihilism'); |
| Строка 20: |
Строка 20: |
| }); | | }); |
|
| |
|
| /* Стирание памяти для «Людей в чёрном» */ | | /* Стирание памяти для [[MIB]] («Людей в чёрном») */ |
| $(function () { | | $(function () { |
| if ($("#erase_memory")[0]) | | if ($("#erase_memory")[0]) |
| Строка 50: |
Строка 50: |
| /* Вставка юзернейма с помощью <span class="insertusername"></span> */ | | /* Вставка юзернейма с помощью <span class="insertusername"></span> */ |
| $(function () { | | $(function () { |
| if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && mw.config.get("wgUserName") !== null) | | if ((typeof (disableUsernameReplace) == "undefined" || !disableUsernameReplace) && mw.config.get("wgUserName") !== null) { |
| $("span.insertusername").html(mw.config.get("wgUserName")); | | var username = mw.config.get("wgUserName"); |
| | $("span.insertusername").text(username); |
| | } |
| }); | | }); |
|
| |
|
| function defaultUploadInfo() {
| |
| var rewrite = document.getElementById("wpForReUpload");
| |
| if (!rewrite) return;
| |
| if (rewrite.value == 1) return;
| |
|
| |
| var d = document.getElementById("wpUploadDescription");
| |
| if (d) {
| |
| if (!d.value.match(/\[\[(Категория|Category):/)) {
| |
| d.value += "\n\n\n[[Категория:Некатегоризованные изображения]]";
| |
| }
| |
| }
| |
| }
| |
|
| |
|
| /* Замена категорий для шаблона {{Cats}} */ | | /* Замена категорий для шаблона {{Cats}} */ |
| Строка 77: |
Строка 67: |
|
| |
|
|
| |
|
| /* Функция для вставки VK-видео на страницу для шаблона VKVideo, простая версия */ | | /* Вставка VK-видео на страницу для шаблона {{VKVideo}} */ |
| window.vkVideoInit = function() {
| | (function() { |
| console.log('VK Video: Initializing...'); | | 'use strict'; |
|
| |
| var containers = document.querySelectorAll('.vk-video-js');
| |
| console.log('VK Video: Found ' + containers.length + ' containers');
| |
| | | |
| for (var i = 0; i < containers.length; i++) { | | function initVKVideo() { |
| var container = containers[i]; | | var containers = document.querySelectorAll('.vk-video-js'); |
| var oid = container.getAttribute('data-oid');
| |
| var id = container.getAttribute('data-id');
| |
| var width = container.getAttribute('data-width') || '640';
| |
| var height = container.getAttribute('data-height') || '360';
| |
| | | |
| console.log('VK Video: Container ' + i + ' - oid:' + oid + ' id:' + id); | | for (var i = 0; i < containers.length; i++) { |
|
| | var container = containers[i]; |
| if (oid && id && oid !== 'null' && id !== 'null') {
| | var oid = container.getAttribute('data-oid'); |
| var iframe = document.createElement('iframe'); | | var id = container.getAttribute('data-id'); |
| iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id); | | var width = container.getAttribute('data-width') || '560'; |
| iframe.width = width; | | var height = container.getAttribute('data-height') || '315'; |
| iframe.height = height; | | |
| iframe.frameBorder = '0'; | | width = parseInt(width) || 560; |
| iframe.allowFullscreen = true; | | height = parseInt(height) || 315; |
| iframe.style.border = 'none'; | | if (width > 1920) width = 1920; |
| iframe.style.borderRadius = '4px';
| | if (height < 100) height = 100; |
| | if (height > 1080) height = 1080; |
| | | |
| container.innerHTML = ''; | | if (oid && id && oid !== 'null' && id !== 'null' && /^[a-zA-Z0-9_-]{1,100}$/.test(oid) && /^[-_a-zA-Z0-9]+$/.test(id)) { |
| container.appendChild(iframe);
| | var iframe = document.createElement('iframe'); |
| console.log('VK Video: Container ' + i + ' - SUCCESS');
| | iframe.src = 'https://vk.com/video_ext.php?oid=' + encodeURIComponent(oid) + '&id=' + encodeURIComponent(id); |
| } else {
| | iframe.width = width; |
| console.error('VK Video: Container ' + i + ' - MISSING DATA');
| | iframe.height = height; |
| container.innerHTML = '<div style="color: red; padding: 10px; text-align: center; border: 1px solid red;">Ошибка: неверные параметры видео</div>';
| | iframe.frameBorder = '0'; |
| }
| | iframe.allowFullscreen = true; |
| }
| | |
| };
| | iframe.sandbox = 'allow-scripts allow-same-origin allow-presentation allow-fullscreen'; |
| | iframe.allow = 'fullscreen'; |
| | iframe.referrerPolicy = 'no-referrer'; |
| | iframe.loading = 'lazy'; |
| | iframe.style.border = 'none'; |
| | |
| | while (container.firstChild) { |
| | container.removeChild(container.firstChild); |
| | } |
| | container.appendChild(iframe); |
| | } else { |
| | var errorDiv = document.createElement('div'); |
| | |
| | errorDiv.style.color = 'red'; |
| | errorDiv.style.padding = '10px'; |
| | errorDiv.style.textAlign = 'center'; |
| | errorDiv.style.border = '1px solid'; |
| | errorDiv.style.backgroundColor = '#fff'; |
| | errorDiv.style.fontFamily = 'Arial, sans-serif'; |
| | errorDiv.style.fontSize = '14px'; |
| | errorDiv.style.margin = '5px 0'; |
|
| |
|
| /* Запускаем после загрузки ВК-видео DOM */
| | errorDiv.textContent = 'Ошибка: неверные параметры видео'; |
| if (document.readyState === 'loading') {
| | |
| document.addEventListener('DOMContentLoaded', window.vkVideoInit);
| | while (container.firstChild) { |
| } else {
| | container.removeChild(container.firstChild); |
| window.vkVideoInit();
| | } |
| }
| | container.appendChild(errorDiv); |
| | | } |
| | |
| /* Простое раскрытие картинок во всплывающем окне по клику на них (для удобства назову — FancyBoxAlternative) */
| |
| | |
| (function() {
| |
| 'use strict';
| |
| | |
| if (document.getElementById('wikiImageModal')) {
| |
| return;
| |
| }
| |
| | |
| var modalHTML = [
| |
| '<div id="wikiImageModal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.9); z-index: 10000; cursor: zoom-out;">',
| |
| ' <div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 90vw; max-height: 90vh;">',
| |
| ' <img id="wikiModalImage" style="max-width: 100%; max-height: 100%; display: block; margin: 0 auto;" src="" alt="">',
| |
| ' <div id="wikiModalCaption" style="color: white; text-align: center; padding: 10px; font-size: 16px;"></div>',
| |
| ' </div>',
| |
| ' <button id="wikiModalClose" style="position: absolute; top: 20px; right: 30px; background: none; border: none; color: white; font-size: 40px; cursor: pointer; z-index: 10001;">×</button>',
| |
| '</div>'
| |
| ].join('');
| |
| | |
| document.body.insertAdjacentHTML('beforeend', modalHTML);
| |
| | |
| var modal = document.getElementById('wikiImageModal');
| |
| var modalImg = document.getElementById('wikiModalImage');
| |
| var modalCaption = document.getElementById('wikiModalCaption');
| |
| var closeBtn = document.getElementById('wikiModalClose');
| |
| | |
| function openModal(img) {
| |
| // Check if this is a video element handled by TimedMediaHandler
| |
| if (isVideoElement(img)) {
| |
| return; | |
| }
| |
|
| |
| modalImg.src = img.src;
| |
| modalCaption.textContent = img.alt || img.title || 'Изображение';
| |
| modal.style.display = 'block';
| |
| document.body.style.overflow = 'hidden';
| |
| }
| |
| | |
| function closeModal() {
| |
| modal.style.display = 'none';
| |
| document.body.style.overflow = 'auto';
| |
| }
| |
| | |
| function isVideoElement(element) {
| |
| if (element.closest('.video-js') ||
| |
| element.closest('.mw-tmh-player') ||
| |
| element.closest('.mw-tmh-thumbnail') ||
| |
| element.parentNode.classList.contains('mw-tmh-player') ||
| |
| element.src && (element.src.includes('.ogv') || element.src.includes('.webm') || element.src.includes('.oga'))) {
| |
| return true;
| |
| } | | } |
| return false;
| |
| }
| |
|
| |
| function addImageHandlers() {
| |
| var images = document.querySelectorAll('img');
| |
|
| |
| images.forEach(function(img) {
| |
| // Skip if already has handler or is modal image
| |
| if (img.hasAttribute('data-zoom-handler') ||
| |
| img === modalImg ||
| |
| img.classList.contains('no-zoom')) {
| |
| return;
| |
| }
| |
|
| |
| // Skip video-related images
| |
| if (isVideoElement(img)) {
| |
| return;
| |
| }
| |
|
| |
| // Add visual feedback
| |
| img.style.cursor = 'zoom-in';
| |
| img.style.transition = 'opacity 0.2s';
| |
|
| |
| img.addEventListener('mouseenter', function() {
| |
| this.style.opacity = '0.9';
| |
| });
| |
|
| |
| img.addEventListener('mouseleave', function() {
| |
| this.style.opacity = '1';
| |
| });
| |
|
| |
| // Add click handler
| |
| img.addEventListener('click', function(e) {
| |
| e.preventDefault();
| |
| e.stopPropagation();
| |
| openModal(this);
| |
| });
| |
|
| |
| // Mark as processed
| |
| img.setAttribute('data-zoom-handler', 'true');
| |
| });
| |
| } | | } |
|
| |
| closeBtn.addEventListener('click', closeModal);
| |
| modal.addEventListener('click', closeModal);
| |
|
| |
| // Prevent modal content from closing modal when clicked
| |
| modalImg.addEventListener('click', function(e) {
| |
| e.stopPropagation();
| |
| });
| |
| | | |
| // Close modal with Escape key
| |
| document.addEventListener('keydown', function(e) {
| |
| if (e.key === 'Escape' && modal.style.display === 'block') {
| |
| closeModal();
| |
| }
| |
| });
| |
|
| |
| // Initialize when DOM is ready
| |
| if (document.readyState === 'loading') { | | if (document.readyState === 'loading') { |
| document.addEventListener('DOMContentLoaded', addImageHandlers); | | document.addEventListener('DOMContentLoaded', initVKVideo); |
| } else { | | } else { |
| addImageHandlers(); | | initVKVideo(); |
| } | | } |
|
| |
| var observer = new MutationObserver(function(mutations) {
| |
| mutations.forEach(function(mutation) {
| |
| if (mutation.addedNodes.length) {
| |
| setTimeout(addImageHandlers, 100);
| |
| }
| |
| });
| |
| });
| |
|
| |
| observer.observe(document.body, {
| |
| childList: true,
| |
| subtree: true
| |
| });
| |
|
| |
| })(); | | })(); |