MediaWiki:Common.js
来自Age Of History 2 Chinese Wiki
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* Windows XP风格的MediaWiki JavaScript增强 */ // 轮播图功能 mw.hook('wikipage.content').add(function($content) { // 查找页面中所有轮播图 $content.find('.mw-carousel').each(function() { const $carousel = $(this); const $items = $carousel.find('.carousel-item'); const $indicators = $carousel.find('.carousel-indicators'); const $prevBtn = $carousel.find('.carousel-prev'); const $nextBtn = $carousel.find('.carousel-next'); let currentIndex = 0; const slideCount = $items.length; if (slideCount === 0) return; // 创建指示器 for (let i = 0; i < slideCount; i++) { const $indicator = $('<div class="indicator"></div>'); if (i === 0) $indicator.addClass('active'); $indicator.on('click', function() { goToSlide(i); }); $indicators.append($indicator); } // 初始化第一张幻灯片 $items.eq(0).addClass('active'); // 给每个幻灯片添加点击事件 $items.each(function() { const $item = $(this); const link = $item.data('link'); if (link && link.length > 0) { $item.css('cursor', 'pointer').on('click', function() { window.location.href = link; }); } }); // 切换到指定幻灯片 function goToSlide(index) { $items.removeClass('active'); $indicators.find('.indicator').removeClass('active'); $items.eq(index).addClass('active'); $indicators.find('.indicator').eq(index).addClass('active'); currentIndex = index; } // 上一张 function prevSlide() { const newIndex = (currentIndex - 1 + slideCount) % slideCount; goToSlide(newIndex); } // 下一张 function nextSlide() { const newIndex = (currentIndex + 1) % slideCount; goToSlide(newIndex); } // 绑定按钮事件 $prevBtn.on('click', function(e) { e.preventDefault(); e.stopPropagation(); prevSlide(); }); $nextBtn.on('click', function(e) { e.preventDefault(); e.stopPropagation(); nextSlide(); }); // 自动播放 let autoplayInterval = setInterval(nextSlide, 5000); $carousel.on('mouseenter', function() { clearInterval(autoplayInterval); }).on('mouseleave', function() { autoplayInterval = setInterval(nextSlide, 5000); }); // 触摸滑动支持 let touchStartX = 0; let touchEndX = 0; $carousel.on('touchstart', function(e) { touchStartX = e.originalEvent.touches[0].clientX; }); $carousel.on('touchend', function(e) { touchEndX = e.originalEvent.changedTouches[0].clientX; // 判断滑动方向 if (touchEndX < touchStartX - 50) { nextSlide(); // 左滑,下一张 } else if (touchEndX > touchStartX + 50) { prevSlide(); // 右滑,上一张 } }); }); }); // Collapsible blocks functionality $(document).ready(function() { // Initialize collapsible blocks $('.collapsible-header').click(function() { $(this).next('.collapsible-content').slideToggle(); $(this).toggleClass('active'); }); // Initially hide collapsible content $('.collapsible-content').hide(); }); /* Common.js - Database New主题JavaScript增强 */ $(function() { // 创建CRT效果容器 function createCRTEffects() { if ($('.crt-effects').length === 0) { var crtContainer = $('<div>', { 'class': 'crt-effects', html: [ $('<div>', {'class': 'scan-line-effect'}), $('<div>', {'class': 'scan-animation'}).append( $('<div>', {'class': 'fast-scan'}) ), $('<div>', {'class': 'radial-glow'}) ] }); $('body').append(crtContainer); } } // 初始化CRT效果 createCRTEffects(); // 橙幕切换功能 if (typeof window.orangemu_toggle_init === 'undefined') { window.orangemu_toggle_init = true; // 为橙幕添加点击切换功能 $(document).on('click', '.orangemu', function(e) { e.stopPropagation(); $(this).toggleClass('orangemu_toggle_on'); }); } // 修复动画问题 function fixAnimations() { // 延迟应用动画,防止页面加载时的闪烁 setTimeout(function() { $('#mw-content-text > *').each(function(index) { $(this).css({ 'animation': 'fadeIn 0.5s ease-out forwards', 'animation-delay': (index * 0.1) + 's', 'opacity': '0' }); }); }, 100); } // 应用动画修复 $(document).ready(function() { fixAnimations(); }); // 监听新内容加载(如AJAX) mw.hook('wikipage.content').add(function($content) { if ($content.attr('id') === 'mw-content-text') { fixAnimations(); } }); // 添加复古终端效果的打字动画 function typeWriter(element, text, speed) { var i = 0; element.empty(); function type() { if (i < text.length) { element.append(text.charAt(i)); i++; setTimeout(type, speed); } } type(); } // 为特定元素应用打字效果 $('.terminal-text').each(function() { var text = $(this).text(); typeWriter($(this), text, 50); }); // 添加闪烁光标效果 function createBlinkingCursor() { var cursor = $('<span>', { 'class': 'terminal-cursor', text: '▋' }); setInterval(function() { cursor.toggle(); }, 500); return cursor; } // 为终端元素添加光标 $('.terminal').each(function() { $(this).append(createBlinkingCursor()); }); // 模拟CRT屏幕抖动效果 function screenGlitch() { var container = $('#content'); container.css('transform', 'translate(' + (Math.random() * 2 - 1) + 'px, ' + (Math.random() * 2 - 1) + 'px)'); setTimeout(function() { container.css('transform', 'translate(0, 0)'); }, 50); } // 随机触发屏幕抖动 setInterval(function() { if (Math.random() < 0.005) { // 0.5%的概率 screenGlitch(); } }, 1000); // 为页面添加启动动画 function bootSequence() { $('body').addClass('booting'); setTimeout(function() { $('body').removeClass('booting').addClass('booted'); }, 500); } // 页面加载时执行启动序列 bootSequence(); }); // 辅助CSS类 $(function() { // 动态添加一些必要的CSS var customStyles = ` .terminal-cursor { animation: blink 1s infinite; } @keyframes blink { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } } .booting #content { opacity: 0; transform: scale(0.95); transition: all 0.5s ease-out; } .booted #content { opacity: 1; transform: scale(1); } .terminal { font-family: var(--mono-font); background-color: rgb(var(--black-monochrome)); color: rgb(var(--bright-accent)); padding: 1rem; border: 2px solid rgb(var(--bright-accent)); box-shadow: 0 0 10px rgba(var(--bright-accent), 0.3); } /* 修复动画闪烁问题 */ #mw-content-text > * { visibility: visible; } .mw-parser-output > *.animated { animation: none !important; } `; $('<style>').text(customStyles).appendTo('head'); }); // 修复变色龙皮肤的菜单折叠功能 $(document).ready(function() { // 移除之前的事件监听器并重新绑定 $('.navbar-toggler, .navbar-toggle').off('click.menu-toggle'); // 添加新的点击事件处理 $('.navbar-toggler, .navbar-toggle').on('click.menu-toggle', function(e) { e.preventDefault(); e.stopPropagation(); var $this = $(this); var $navbar = $this.closest('.navbar'); var $collapse = $navbar.find('.navbar-collapse'); // 切换显示状态 if ($collapse.hasClass('show')) { $collapse.removeClass('show').hide(); } else { // 先隐藏其他所有打开的菜单 $('.navbar-collapse').removeClass('show').hide(); $collapse.addClass('show').show(); } }); // 点击外部关闭菜单 $(document).on('click.close-menu', function(e) { if (!$(e.target).closest('.navbar-toggler, .navbar-toggle, .navbar-collapse').length) { $('.navbar-collapse').removeClass('show').hide(); } }); }); // 修复变色龙皮肤的Bootstrap组件 $(function() { function fixBootstrapComponents() { // 修复导航栏 $('.navbar').css({ 'background-color': 'rgb(236, 233, 216)', 'border-bottom': '1px solid rgb(0, 0, 0)' }); // 修复下拉菜单 $('.dropdown-menu').css({ 'background-color': 'rgb(236, 233, 216)', 'border': '1px solid rgb(0, 0, 0)' }); // 修复按钮 $('.btn').css({ 'background-color': 'rgb(192, 192, 192)', 'border': '1px solid rgb(0, 0, 0)', 'color': 'rgb(0, 0, 0)' }); // 修复表单控件 $('.form-control').css({ 'background-color': 'white', 'border': '1px solid rgb(0, 0, 0)', 'color': 'rgb(0, 0, 0)' }); } // 应用样式修复 fixBootstrapComponents(); // 监听DOM变化 var observer = new MutationObserver(function(mutations) { fixBootstrapComponents(); }); observer.observe(document.body, { childList: true, subtree: true }); }); // 修复头像加载 $(document).ready(function() { var username = mw.config.get('wgUserName'); if (username) { // 获取用户ID $.get(mw.util.wikiScript('api'), { action: 'query', list: 'users', ususers: username, usprop: 'registration|editcount', format: 'json' }).done(function(data) { if (data && data.query && data.query.users && data.query.users[0] && data.query.users[0].userid) { var userId = data.query.users[0].userid; // 尝试多个可能的头像路径 var possiblePaths = [ mw.config.get('wgScriptPath') + '/extensions/SocialProfile/avatars/' + mw.config.get('wgDBname') + '_' + userId + '_ml.jpg', mw.config.get('wgScriptPath') + '/extensions/SocialProfile/avatars/' + mw.config.get('wgDBname') + '_' + userId + '_l.jpg', mw.config.get('wgScriptPath') + '/extensions/SocialProfile/avatars/' + mw.config.get('wgDBname') + '_' + userId + '_ml.png', mw.config.get('wgScriptPath') + '/extensions/SocialProfile/avatars/' + mw.config.get('wgDBname') + '_' + userId + '_l.png', mw.config.get('wgScriptPath') + '/extensions/SocialProfile/avatars/default_ml.gif' ]; function tryLoadAvatar(index) { if (index >= possiblePaths.length) { console.log('No avatar found, using default'); return; } var img = new Image(); img.onload = function() { applyAvatarCSS(possiblePaths[index]); }; img.onerror = function() { tryLoadAvatar(index + 1); }; img.src = possiblePaths[index]; } tryLoadAvatar(0); } }); } function applyAvatarCSS(avatarUrl) { // 应用到所有可能的选择器 var css = [ '#pt-userpage > a::before', '.vector-user-menu-legacy #pt-userpage a::before', '#p-personal #pt-userpage a::before', '.skin-chameleon .navbar-tools > li:first-child > a::before' ].join(',') + '{' + 'background-image: url("' + avatarUrl + '") !important;' + '}'; // 移除之前的样式,添加新的 $('style[data-avatar-style]').remove(); $('<style data-avatar-style>').text(css).appendTo('head'); } }); /* Windows XP风格的MediaWiki JavaScript增强 */ // 修复重复渲染问题和完善功能 $(document).ready(function() { // 清理之前的所有任务栏元素 $('.taskbar').remove(); $('.start-button').remove(); $('.taskbar-clock').remove(); // 创建完整的任务栏 createTaskbar(); // 设置开始菜单 setupStartMenu(); // 修复响应式菜单 fixResponsiveMenu(); // 增强头像显示 enhanceAvatar(); // 添加扫描线效果(完整的三条扫描线) if ($('.scan-animation').length === 0) { var $scanContainer = $('<div class="scan-animation"></div>'); var $fastScan = $('<div class="fast-scan"></div>'); $scanContainer.append($fastScan); $('body').append($scanContainer); } // 添加XP窗口控制按钮(仅视觉效果) addWindowControls(); // 添加窗口拖动功能 makeWindowsDraggable(); }); // 创建完整的任务栏 function createTaskbar() { // 移除之前的任务栏 $('.taskbar, .start-button, .taskbar-clock').remove(); // 创建任务栏容器 var $taskbar = $('<div class="taskbar"></div>'); // 创建开始按钮 var $startButton = $('<div class="start-button">开始</div>'); $taskbar.append($startButton); // 创建任务栏内容区域 var $taskbarContent = $('<div class="taskbar-content"></div>'); // 创建快速启动栏 var $quickLaunch = $('<div class="quick-launch"></div>'); // 添加一些快速启动图标 var quickLaunchItems = [ { icon: '🌐', title: '浏览器', action: function() { window.location.href = '/wiki/首页'; } }, { icon: '📁', title: '文件夹', action: function() { window.location.href = '/wiki/Special:AllPages'; } }, { icon: '📧', title: '邮件', action: function() { window.location.href = '/wiki/Special:EmailUser'; } } ]; quickLaunchItems.forEach(function(item) { var $icon = $('<div class="quick-launch-icon" title="' + item.title + '">' + item.icon + '</div>'); $icon.click(item.action); $quickLaunch.append($icon); }); $taskbarContent.append($quickLaunch); $taskbar.append($taskbarContent); // 创建系统托盘 var $systemTray = $('<div class="system-tray"></div>'); // 添加系统图标 var $volumeIcon = $('<div class="tray-icon" title="音量">🔊</div>'); var $networkIcon = $('<div class="tray-icon" title="网络">📶</div>'); $systemTray.append($volumeIcon); $systemTray.append($networkIcon); var $clock = $('<div class="taskbar-clock"></div>'); $systemTray.append($clock); $taskbar.append($systemTray); // 添加到页面 $('body').append($taskbar); // 启动时钟 updateClock($clock); } // 更新时钟 function updateClock($clock) { function update() { var now = new Date(); var hours = now.getHours(); var minutes = now.getMinutes(); // 格式化时间 hours = (hours < 10 ? '0' : '') + hours; minutes = (minutes < 10 ? '0' : '') + minutes; $clock.text(hours + ':' + minutes); } update(); setInterval(update, 1000); } // 修复响应式菜单 function fixResponsiveMenu() { // 为变色龙皮肤的折叠按钮添加点击事件 $('.navbar-toggler, .navbar-toggle').off('click').on('click', function(e) { e.preventDefault(); e.stopPropagation(); var $navbar = $(this).closest('.navbar'); var $collapse = $navbar.find('.navbar-collapse'); if ($collapse.hasClass('show') || $collapse.hasClass('in')) { $collapse.removeClass('show in').slideUp(200); } else { $collapse.addClass('show in').slideDown(200); } }); // 点击外部关闭菜单 $(document).click(function(e) { if (!$(e.target).closest('.navbar').length) { $('.navbar-collapse').removeClass('show in').slideUp(200); } }); } // 重写开始菜单,避免重复 function setupStartMenu() { // 移除任何现有的开始菜单 $('#xp-start-menu').remove(); // 创建开始菜单元素 var $startMenu = $('<div id="xp-start-menu"></div>').css({ 'position': 'fixed', 'left': '0', 'bottom': '60px', 'width': '250px', 'background-color': 'white', 'border': '2px solid #0054e3', 'box-shadow': '2px -2px 5px rgba(0, 0, 0, 0.3)', 'z-index': '10000', 'display': 'none' }); // 添加菜单顶部 var username = mw.config.get('wgUserName') || 'Guest'; var $menuTop = $('<div class="start-menu-top"></div>').css({ 'height': '60px', 'background': 'linear-gradient(to bottom, #235ddc, #225ada 50%, #214fbb)', 'color': 'white', 'padding': '10px', 'font-weight': 'bold', 'display': 'flex', 'align-items': 'center' }); $menuTop.html('<span style="font-size: 16px;">' + username + '</span>'); $startMenu.append($menuTop); // 添加菜单项 var $menuItems = $('<div class="start-menu-items"></div>').css({ 'background-color': 'white', 'padding': '5px 0' }); // 定义菜单项 var menuItemsData = [ { icon: '📄', text: '我的文档', link: '/wiki/Special:MyPage' }, { icon: '🖼️', text: '我的图片', link: '/wiki/Special:MediaStatistics' }, { icon: '🎵', text: '我的音乐', link: '#' }, { icon: '⚙️', text: '控制面板', link: '/wiki/Special:Preferences' }, { icon: '🔍', text: '搜索', link: '/wiki/Special:Search' }, { icon: '❓', text: '帮助和支持', link: '/wiki/Help:目录' }, { icon: '🚪', text: '注销', link: '/wiki/Special:UserLogout' } ]; // 添加菜单项 $.each(menuItemsData, function(index, item) { var $menuItem = $('<div class="start-menu-item"></div>').css({ 'padding': '5px 10px', 'display': 'flex', 'align-items': 'center', 'cursor': 'pointer' }); $menuItem.html('<span style="margin-right: 10px; font-size: 16px;">' + item.icon + '</span>' + '<span>' + item.text + '</span>'); // 添加悬停效果 $menuItem.hover( function() { $(this).css('background-color', '#e0ecff'); }, function() { $(this).css('background-color', 'transparent'); } ); // 添加链接功能 $menuItem.click(function() { if (item.link && item.link !== '#') { window.location.href = mw.config.get('wgScriptPath') + item.link; } }); $menuItems.append($menuItem); }); $startMenu.append($menuItems); // 添加开始菜单到body $('body').append($startMenu); // 为开始按钮添加点击事件 $(document).on('click', '.start-button', function(e) { e.stopPropagation(); $startMenu.toggle(); }); // 点击其他区域关闭开始菜单 $(document).click(function(e) { if (!$(e.target).is('.start-button') && !$(e.target).closest('#xp-start-menu').length) { $startMenu.hide(); } }); } // 修复响应式菜单 $(document).ready(function() { // 确保折叠按钮在大屏幕上隐藏 function checkNavToggle() { var windowWidth = $(window).width(); if (windowWidth > 991) { $('.navbar-toggler').hide(); $('.navbar-collapse').show().removeClass('show'); } else { $('.navbar-toggler').show(); } } // 初始检查 checkNavToggle(); // 窗口调整时检查 $(window).resize(checkNavToggle); // 折叠按钮点击事件 $('.navbar-toggler').on('click', function(e) { e.preventDefault(); e.stopPropagation(); var $collapse = $(this).closest('.navbar').find('.navbar-collapse'); if ($collapse.is(':visible')) { $collapse.slideUp(200).removeClass('show'); } else { $collapse.slideDown(200).addClass('show'); } }); // 点击外部关闭菜单 $(document).on('click', function(e) { if (!$(e.target).closest('.navbar-toggler, .navbar-collapse').length) { $('.navbar-collapse').slideUp(200).removeClass('show'); } }); }); // 修复头像加载 $(document).ready(function() { var username = mw.config.get('wgUserName'); if (username) { $.get(mw.util.wikiScript('api'), { action: 'query', list: 'users', ususers: username, usprop: 'userid', format: 'json' }).done(function(data) { if (data && data.query && data.query.users && data.query.users[0] && data.query.users[0].userid) { var userId = data.query.users[0].userid; var dbName = mw.config.get('wgDBname'); var scriptPath = mw.config.get('wgScriptPath'); // 构建头像路径 var avatarPaths = [ scriptPath + '/extensions/SocialProfile/avatars/' + dbName + '_' + userId + '_ml.jpg', scriptPath + '/extensions/SocialProfile/avatars/' + dbName + '_' + userId + '_ml.png', scriptPath + '/extensions/SocialProfile/avatars/' + dbName + '_' + userId + '_l.jpg', scriptPath + '/extensions/SocialProfile/avatars/' + dbName + '_' + userId + '_l.png' ]; function tryLoadAvatar(index) { if (index >= avatarPaths.length) { console.log('No custom avatar found, using default'); return; } var img = new Image(); img.onload = function() { // 只应用到用户页面按钮,不影响Echo图标 var css = '#pt-userpage:not(#pt-notifications-alert):not(#pt-notifications-notice) > a::before {' + 'background-image: url("' + avatarPaths[index] + '") !important;' + '}'; // 移除之前的样式 $('style[data-custom-avatar]').remove(); // 添加新样式 $('<style data-custom-avatar>').text(css).appendTo('head'); }; img.onerror = function() { tryLoadAvatar(index + 1); }; img.src = avatarPaths[index]; } tryLoadAvatar(0); } }); } });
Loading comments...