MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 标签:已被回退 |
无编辑摘要 标签:已被回退 |
||
| 第14行: | 第14行: | ||
(function() { | (function() { | ||
mw.loader.using('jquery', function() { | mw.loader.using('jquery', function() { | ||
$(function() { | $(function() { | ||
if (document.querySelector('.magnetic-pointer-original')) return; | if (document.querySelector('.magnetic-pointer-original')) return; | ||
const pointer = document.createElement('div'); | const pointer = document.createElement('div'); | ||
pointer.className = 'magnetic-pointer-original'; | pointer.className = 'magnetic-pointer-original'; | ||
| 第26行: | 第23行: | ||
document.body.appendChild(pointer); | document.body.appendChild(pointer); | ||
const style = document.createElement('style'); | const style = document.createElement('style'); | ||
style.textContent = ` | style.textContent = ` | ||
.magnetic-pointer-original { | |||
--width: 4rem; | |||
--height: 4rem; | |||
position: fixed; | |||
top: calc(var(--height) / -2); | |||
left: calc(var(--width) / -2); | |||
width: var(--width); | |||
height: var(--height); | |||
transition: all 0.2s ease-out; | |||
pointer-events: none; | |||
z-index: 99999; | |||
} | |||
.magnetic-pointer-original div { | |||
position: absolute; | |||
width: 0.8rem; | |||
height: 0.8rem; | |||
border-color: #17f700; | |||
background: transparent !important; | |||
} | |||
.magnetic-pointer-original div:nth-child(1) {top:0;left:0;border-top:3px solid;border-left:3px solid;} | |||
.magnetic-pointer-original div:nth-child(2) {top:0;right:0;border-top:3px solid;border-right:3px solid;} | |||
.magnetic-pointer-original div:nth-child(3) {bottom:0;left:0;border-bottom:3px solid;border-left:3px solid;} | |||
.magnetic-pointer-original div:nth-child(4) {bottom:0;right:0;border-bottom:3px solid;border-right:3px solid;} | |||
`; | `; | ||
document.head.appendChild(style); | document.head.appendChild(style); | ||
| 第58行: | 第54行: | ||
let currentX = 0, currentY = 0; | let currentX = 0, currentY = 0; | ||
const onMouseMove = function(e) { | const onMouseMove = function(e) { | ||
let x = e.clientX; | let x = e.clientX; | ||
| 第74行: | 第69行: | ||
}; | }; | ||
const onMouseEnter = function(e) { | const onMouseEnter = function(e) { | ||
currentTarget = e.currentTarget; | currentTarget = e.currentTarget; | ||
| 第82行: | 第76行: | ||
}; | }; | ||
const onMouseLeave = function() { | const onMouseLeave = function() { | ||
currentTarget = null; | currentTarget = null; | ||
| 第89行: | 第82行: | ||
}; | }; | ||
const bindTargets = function() { | const bindTargets = function() { | ||
document.querySelectorAll('._target').forEach(el => { | document.querySelectorAll('._target').forEach(el => { | ||
| 第99行: | 第91行: | ||
}; | }; | ||
window.addEventListener('mousemove', onMouseMove); | window.addEventListener('mousemove', onMouseMove); | ||
bindTargets(); | bindTargets(); | ||
const observer = new MutationObserver(bindTargets); | const observer = new MutationObserver(bindTargets); | ||
observer.observe(document.body, { childList: true, subtree: true }); | observer.observe(document.body, { childList: true, subtree: true }); | ||
2026年3月31日 (二) 15:55的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* USERNAME */
$( function() {
if ( mw.user.isNamed() ) {
$( '.insertusername' ).text( mw.user.getName() );
} else {
$( '.insertusername' ).text( '访客' );
}
} );
/* INFOBOX */
$('.infobox').hide();
(function() {
mw.loader.using('jquery', function() {
$(function() {
if (document.querySelector('.magnetic-pointer-original')) return;
const pointer = document.createElement('div');
pointer.className = 'magnetic-pointer-original';
pointer.innerHTML = '<div></div><div></div><div></div><div></div>';
document.body.appendChild(pointer);
const style = document.createElement('style');
style.textContent = `
.magnetic-pointer-original {
--width: 4rem;
--height: 4rem;
position: fixed;
top: calc(var(--height) / -2);
left: calc(var(--width) / -2);
width: var(--width);
height: var(--height);
transition: all 0.2s ease-out;
pointer-events: none;
z-index: 99999;
}
.magnetic-pointer-original div {
position: absolute;
width: 0.8rem;
height: 0.8rem;
border-color: #17f700;
background: transparent !important;
}
.magnetic-pointer-original div:nth-child(1) {top:0;left:0;border-top:3px solid;border-left:3px solid;}
.magnetic-pointer-original div:nth-child(2) {top:0;right:0;border-top:3px solid;border-right:3px solid;}
.magnetic-pointer-original div:nth-child(3) {bottom:0;left:0;border-bottom:3px solid;border-left:3px solid;}
.magnetic-pointer-original div:nth-child(4) {bottom:0;right:0;border-bottom:3px solid;border-right:3px solid;}
`;
document.head.appendChild(style);
let currentTarget = null;
let currentX = 0, currentY = 0;
const onMouseMove = function(e) {
let x = e.clientX;
let y = e.clientY;
if (currentTarget) {
const rect = currentTarget.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
x = centerX + (x - centerX) * 0.1;
y = centerY + (y - centerY) * 0.1;
}
currentX = x;
currentY = y;
pointer.style.transform = `translate(${currentX}px, ${currentY}px)`;
};
const onMouseEnter = function(e) {
currentTarget = e.currentTarget;
const rect = currentTarget.getBoundingClientRect();
pointer.style.setProperty('--width', rect.width + window.innerWidth / 50 + 'px');
pointer.style.setProperty('--height', rect.height + window.innerWidth / 50 + 'px');
};
const onMouseLeave = function() {
currentTarget = null;
pointer.style.setProperty('--width', '4rem');
pointer.style.setProperty('--height', '4rem');
};
const bindTargets = function() {
document.querySelectorAll('._target').forEach(el => {
if (el._magneticBound) return;
el._magneticBound = true;
el.addEventListener('mouseenter', onMouseEnter);
el.addEventListener('mouseleave', onMouseLeave);
});
};
window.addEventListener('mousemove', onMouseMove);
bindTargets();
const observer = new MutationObserver(bindTargets);
observer.observe(document.body, { childList: true, subtree: true });
});
});
})();