MediaWiki:Common.js
MediaWiki界面页面
更多操作
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// 侧边栏广告
$(function() {
if ($('#p-navigation').length) {
var adHtml = '<div id="sidebar-ad"></div>';
$('#p-navigation').after(adHtml);
$.get(mw.util.wikiScript('api'), {
action: 'parse',
text: '{{CitizenAd}}',
format: 'json'
}, function(data) {
$('#sidebar-ad').html(data.parse.text['*']);
});
}
});
/**
* Blockland Wiki Liquid Glass Lighting System
*/
(function() {
'use strict';
var isPerformanceMode = function() {
return document.documentElement.classList.contains('citizen-feature-performance-mode-clientpref-1');
};
var GLASS_SELECTORS = '#mw-panel-toc, #citizen-sidebar-lastmod, .aero-news-box, .citizen-header, .citizen-menu__card, .citizen-toc-card, .citizen-command-palette, .infobox, table.ambox, .mwe-popups-container, .oo-ui-popupWidget-popup, .oo-ui-menuSelectWidget, .voy-box';
var lastMouseX = 0;
var lastMouseY = 0;
var syncLight = function(e) {
if (isPerformanceMode()) return;
lastMouseX = e.clientX;
lastMouseY = e.clientY;
var elements = document.querySelectorAll(GLASS_SELECTORS);
elements.forEach(function(el) {
var rect = el.getBoundingClientRect();
if (rect.width > 0 && rect.top < window.innerHeight && rect.bottom > 0) {
var x = ((e.clientX - rect.left) / rect.width) * 100;
var y = ((e.clientY - rect.top) / rect.height) * 100;
el.style.setProperty('--mouse-x', x.toFixed(2) + '%');
el.style.setProperty('--mouse-y', y.toFixed(2) + '%');
}
});
};
var initPopupLight = function(container) {
if (isPerformanceMode()) return;
var rect = container.getBoundingClientRect();
if (rect.width > 0) {
var x = ((lastMouseX - rect.left) / rect.width) * 100;
var y = ((lastMouseY - rect.top) / rect.height) * 100;
container.style.setProperty('--mouse-x', x.toFixed(2) + '%');
container.style.setProperty('--mouse-y', y.toFixed(2) + '%');
}
};
setInterval(function() {
if (isPerformanceMode()) return;
var p = document.querySelector('.citizen-command-palette');
if (p && !p.classList.contains('glass-show')) {
p.classList.add('glass-show');
}
}, 100);
var ticking = false;
document.addEventListener('mousemove', function(e) {
if (isPerformanceMode()) return;
if (!ticking) {
window.requestAnimationFrame(function() {
syncLight(e);
ticking = false;
});
ticking = true;
}
}, { passive: true });
var modeObserver = new MutationObserver(function() {
if (isPerformanceMode()) {
document.querySelectorAll(GLASS_SELECTORS).forEach(function(el) {
el.style.removeProperty('--mouse-x');
el.style.removeProperty('--mouse-y');
});
}
});
modeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
window._liquidGlassInitPopup = initPopupLight;
})();
/**
* Section25. Wiki 弹出预览菜单动画控制
*/
(function() {
'use strict';
var style = document.createElement('style');
style.textContent = `
.mwe-popups .mwe-popups-container {
opacity: 0 !important;
transform: translateY(-12px) !important;
transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
}
.mwe-popups.popup-show .mwe-popups-container {
opacity: 1 !important;
transform: translateY(0) !important;
}
.mwe-popups.flipped-y .mwe-popups-container {
transform: translateY(12px) !important;
}
.mwe-popups.flipped-y.popup-show .mwe-popups-container {
transform: translateY(0) !important;
}
`;
document.head.appendChild(style);
var seen = new WeakSet();
new MutationObserver(function(muts) {
muts.forEach(function(m) {
m.addedNodes.forEach(function(node) {
if (node.classList && node.classList.contains('mwe-popups') && !seen.has(node)) {
seen.add(node);
var container = node.querySelector('.mwe-popups-container');
if (!container) return;
if (window._liquidGlassInitPopup) {
window._liquidGlassInitPopup(container);
}
node.style.pointerEvents = 'none';
container.offsetHeight;
requestAnimationFrame(function() {
requestAnimationFrame(function() {
node.classList.add('popup-show');
setTimeout(function() {
node.style.pointerEvents = '';
}, 350);
});
});
}
});
});
}).observe(document.body, { childList: true, subtree: true });
})();
/**
* Section19. 通知面板动画控制
* 检测到面板后再开始动画
*/
(function() {
'use strict';
function handlePopup(popup) {
if (popup.dataset.animatorInited) return;
popup.dataset.animatorInited = 'true';
const observer = new MutationObserver(() => {
const inner = popup.querySelector('.oo-ui-popupWidget-popup');
if (!inner) return;
const isVisible = popup.style.display !== 'none' && popup.offsetParent !== null;
if (isVisible) {
if (inner.getAttribute('data-is-active') !== 'true') {
inner.setAttribute('data-is-active', 'true');
// 1. 初始化:置于下方并透明
inner.style.setProperty('transition', 'none', 'important');
inner.style.setProperty('opacity', '0', 'important');
inner.style.setProperty('transform', 'translateY(20px)', 'important');
inner.offsetHeight; // 触发重绘
requestAnimationFrame(() => {
setTimeout(() => {
// 2. 向上滑动并渐显
inner.style.setProperty('transition', 'opacity 0.3s ease-out, transform 0.4s cubic-bezier(0.23, 1, 0.32, 1)', 'important');
inner.style.setProperty('opacity', '1', 'important');
inner.style.setProperty('transform', 'translateY(0)', 'important');
}, 10);
});
}
} else {
// 关闭时直接重置,不加动画,确保下次打开干净利落
if (inner.getAttribute('data-is-active') === 'true') {
inner.removeAttribute('data-is-active');
inner.style.removeProperty('opacity');
inner.style.removeProperty('transform');
inner.style.removeProperty('transition');
inner.style.removeProperty('transform-origin');
}
}
});
observer.observe(popup, { attributes: true, attributeFilter: ['style', 'class'] });
}
const scanner = new MutationObserver(() => {
document.querySelectorAll('.mw-echo-ui-notificationBadgeButtonPopupWidget-popup').forEach(handlePopup);
});
scanner.observe(document.body, { childList: true, subtree: true });
document.querySelectorAll('.mw-echo-ui-notificationBadgeButtonPopupWidget-popup').forEach(handlePopup);
})();
// 添加液态玻璃按钮
(function() {
'use strict';
function addLiquidGlassOption() {
const form = document.querySelector('#skin-client-prefs-citizen-feature-performance-mode form');
if (!form) {
setTimeout(addLiquidGlassOption, 100);
return;
}
// 检查是否已经添加过
if (document.getElementById('skin-client-pref-citizen-feature-performance-mode-value-2')) {
return;
}
// 创建液态玻璃选项
const liquidGlassOption = document.createElement('div');
liquidGlassOption.className = 'citizen-client-prefs-radio';
liquidGlassOption.innerHTML = `
<input name="skin-client-pref-citizen-feature-performance-mode-group"
id="skin-client-pref-citizen-feature-performance-mode-value-2"
type="radio"
value="2"
data-event-name="skin-client-pref-citizen-feature-performance-mode-value-2"
class="citizen-client-prefs-radio__input">
<span class="citizen-client-prefs-radio__icon"></span>
<label for="skin-client-pref-citizen-feature-performance-mode-value-2"
class="citizen-client-prefs-radio__labe">耄耋玻璃</label>
`;
// 添加到表单
form.appendChild(liquidGlassOption);
console.log('液态玻璃按钮已添加');
// 绑定所有单选按钮的事件
const allRadios = document.querySelectorAll('input[name="skin-client-pref-citizen-feature-performance-mode-group"]');
allRadios.forEach(radio => {
radio.addEventListener('change', function() {
const value = this.value;
console.log('选中值:', value);
// 保存到 localStorage
localStorage.setItem('citizen-feature-performance-mode-clientpref-', value);
console.log('保存到 localStorage:', localStorage.getItem('citizen-feature-performance-mode-clientpref-'));
// 更新 HTML class
const htmlElement = document.documentElement;
// 移除旧的 class
htmlElement.className = htmlElement.className.replace(/citizen-feature-performance-mode-clientpref-\d/g, '');
// 添加新的 class
htmlElement.classList.add('citizen-feature-performance-mode-clientpref-' + value);
console.log('更新后的 class:', htmlElement.className);
});
});
}
// 页面加载时执行
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', addLiquidGlassOption);
} else {
addLiquidGlassOption();
}
})();
// 液态玻璃 SVG 背景折射效果
(function() {
'use strict';
function addLiquidGlassEffect() {
// 检查是否已经添加过 SVG 滤镜
if (document.getElementById('liquid-glass-svg-filters')) {
return;
}
// 创建 SVG 滤镜容器
const svgFilters = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svgFilters.id = 'liquid-glass-svg-filters';
svgFilters.style.display = 'none';
svgFilters.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
svgFilters.setAttribute('viewBox', '0 0 100 100');
// 定义折射滤镜
svgFilters.innerHTML = `
<defs>
<!-- 径向扭曲:边缘强,中心弱 -->
<filter id="liquid-glass-radial-distortion" x="-50%" y="-50%" width="200%" height="200%">
<feTurbulence type="fractalNoise" baseFrequency="0.02" numOctaves="3" result="noise" seed="2" />
<feDisplacementMap in="SourceGraphic" in2="noise" scale="8" xChannelSelector="R" yChannelSelector="G" />
</filter>
</defs>
`;
document.body.appendChild(svgFilters);
console.log('液态玻璃背景折射效果已加载');
// 应用滤镜到液态玻璃元素
applyLiquidGlassFilter();
}
function applyLiquidGlassFilter() {
// 监听 DOM 变化,动态应用滤镜
const observer = new MutationObserver(function() {
const elements = document.querySelectorAll(
'html[class*="citizen-feature-performance-mode-clientpref-2"] .citizen-menu__card, ' +
'html[class*="citizen-feature-performance-mode-clientpref-2"] #citizen-preferences__card, ' +
'html[class*="citizen-feature-performance-mode-clientpref-2"] .citizen-sticky-header-background, ' +
'html[class*="citizen-feature-performance-mode-clientpref-2"] .page-actions-more__card, ' +
'html[class*="citizen-feature-performance-mode-clientpref-2"] .mwe-popups .mwe-popups-container, ' +
'html[class*="citizen-feature-performance-mode-clientpref-2"] .infobox, ' +
'html[class*="citizen-feature-performance-mode-clientpref-2"] .mw-parser-output table.wikitable'
);
elements.forEach(el => {
if (!el.getAttribute('data-liquid-glass-applied')) {
el.style.filter = 'url(#liquid-glass-radial-distortion)';
el.setAttribute('data-liquid-glass-applied', 'true');
console.log('已应用液态玻璃滤镜到:', el.className);
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
// 页面加载时执行
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', addLiquidGlassEffect);
} else {
addLiquidGlassEffect();
}
})();