MediaWiki:Citizen.js:修订间差异
MediaWiki界面页面
更多操作
无编辑摘要 标签:已被回退 |
无编辑摘要 标签:已被回退 |
||
| 第7行: | 第7行: | ||
]; | ]; | ||
const currentPage = mw.config.get("wgTitle"); | const currentPage = mw.config.get("wgTitle"); | ||
if( !allowPages.includes(currentPage) ){ | if( !allowPages.includes(currentPage) ){ | ||
| 第22行: | 第21行: | ||
document.body.appendChild(ptr); | document.body.appendChild(ptr); | ||
// | // 样式:旋转动画+悬停暂停+深银灰+隐藏原生光标 | ||
const css = document.createElement('style'); | const css = document.createElement('style'); | ||
css.textContent = ` | css.textContent = ` | ||
/* 全局隐藏原生光标(仅白名单页面生效) */ | |||
/* | body, body * { | ||
body | |||
* { | |||
cursor: none !important; | cursor: none !important; | ||
} | } | ||
/* 旋转关键帧 */ | |||
@keyframes rotateLoop { | @keyframes rotateLoop { | ||
from { transform: rotate(0deg); } | from { transform: rotate(0deg); } | ||
| 第45行: | 第41行: | ||
pointer-events:none; | pointer-events:none; | ||
z-index:999999!important; | z-index:999999!important; | ||
animation: rotateLoop 8s linear infinite; | /* 8秒匀速转圈,改数字调快慢 */ | ||
animation: rotateLoop 8s linear infinite; | |||
} | } | ||
/* 悬停按钮时暂停旋转 */ | |||
.magnetic-true-corner.pause-rotate { | |||
animation-play-state: paused; | |||
} | |||
.magnetic-true-corner i{ | .magnetic-true-corner i{ | ||
position:absolute; | position:absolute; | ||
| 第63行: | 第65行: | ||
let hoverEl = null; | let hoverEl = null; | ||
let mx = 0, my = 0; | let mx = 0, my = 0; | ||
let smoothX = 0, smoothY = 0; | let smoothX = 0, smoothY = 0; | ||
let curW = 40, curH = 40; | let curW = 40, curH = 40; | ||
document.addEventListener('mousemove', e => { | document.addEventListener('mousemove', e => { | ||
mx = e.clientX; | mx = e.clientX; | ||
| 第73行: | 第73行: | ||
}); | }); | ||
function loop(){ | function loop(){ | ||
const ease = 0.15; | const ease = 0.15; | ||
if(hoverEl){ | if(hoverEl){ | ||
const r = hoverEl.getBoundingClientRect(); | const r = hoverEl.getBoundingClientRect(); | ||
const targetX = r.left + r.width / 2; | const targetX = r.left + r.width / 2; | ||
| 第86行: | 第84行: | ||
curH = r.height; | curH = r.height; | ||
ptr.style.left = (smoothX - curW / 2) + 'px'; | ptr.style.left = (smoothX - curW / 2) + 'px'; | ||
ptr.style.top = (smoothY - curH / 2) + 'px'; | ptr.style.top = (smoothY - curH / 2) + 'px'; | ||
| 第92行: | 第89行: | ||
ptr.style.height = curH + 'px'; | ptr.style.height = curH + 'px'; | ||
}else{ | }else{ | ||
curW = 40; | curW = 40; | ||
curH = 40; | curH = 40; | ||
| 第108行: | 第104行: | ||
const sel = [ | const sel = [ | ||
'.citizen-nav a', | '.citizen-nav a', | ||
'.citizen-menu a', | '.citizen-menu a', | ||
| 第117行: | 第112行: | ||
'#citizen-header__nav a', | '#citizen-header__nav a', | ||
'.citizen-sidebar a', | '.citizen-sidebar a', | ||
'._target', | '._target', | ||
'.commentstreams-button', | '.commentstreams-button', | ||
'.commentstreams-submit', | '.commentstreams-submit', | ||
'.commentstreams-header button', | '.commentstreams-header button', | ||
'.commentstreams-box button', | '.commentstreams-box button', | ||
'.mw-ui-button', | '.mw-ui-button', | ||
'button', | 'button', | ||
| 第137行: | 第126行: | ||
if(el._magBind)return; | if(el._magBind)return; | ||
el._magBind = 1; | el._magBind = 1; | ||
el.addEventListener('mouseenter', ()=> hoverEl = el); | el.addEventListener('mouseenter', ()=> { | ||
el.addEventListener('mouseleave', ()=> | hoverEl = el; | ||
ptr.classList.add('pause-rotate'); | |||
}); | |||
el.addEventListener('mouseleave', ()=> { | |||
hover ptr.classList.remove('pause-rotate'); | |||
}); | |||
}); | }); | ||
} | } | ||
2026年3月31日 (二) 23:14的版本
(function() {
// 页面白名单
const allowPages = [
"首页",
"Main Page",
"你的自定义首页名字"
];
const currentPage = mw.config.get("wgTitle");
if( !allowPages.includes(currentPage) ){
return;
}
if( window.magneticCursorInit ) return;
window.magneticCursorInit = true;
mw.loader.using( [], function() {
// 创建四角光标
const ptr = document.createElement('div');
ptr.className = 'magnetic-true-corner';
ptr.innerHTML = `<i></i><i></i><i></i><i></i>`;
document.body.appendChild(ptr);
// 样式:旋转动画+悬停暂停+深银灰+隐藏原生光标
const css = document.createElement('style');
css.textContent = `
/* 全局隐藏原生光标(仅白名单页面生效) */
body, body * {
cursor: none !important;
}
/* 旋转关键帧 */
@keyframes rotateLoop {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.magnetic-true-corner{
position:fixed;
left:0;top:0;
width:0;height:0;
pointer-events:none;
z-index:999999!important;
/* 8秒匀速转圈,改数字调快慢 */
animation: rotateLoop 8s linear infinite;
}
/* 悬停按钮时暂停旋转 */
.magnetic-true-corner.pause-rotate {
animation-play-state: paused;
}
.magnetic-true-corner i{
position:absolute;
width:14px;height:14px;
border:2px solid #888e99;
background:transparent!important;
box-shadow:none!important;
}
.magnetic-true-corner i:nth-child(1){top:-2px;left:-2px;border-right:none;border-bottom:none;}
.magnetic-true-corner i:nth-child(2){top:-2px;right:-2px;border-left:none;border-bottom:none;}
.magnetic-true-corner i:nth-child(3){bottom:-2px;left:-2px;border-right:none;border-top:none;}
.magnetic-true-corner i:nth-child(4){bottom:-2px;right:-2px;border-left:none;border-top:none;}
`;
document.head.appendChild(css);
let hoverEl = null;
let mx = 0, my = 0;
let smoothX = 0, smoothY = 0;
let curW = 40, curH = 40;
document.addEventListener('mousemove', e => {
mx = e.clientX;
my = e.clientY;
});
function loop(){
const ease = 0.15;
if(hoverEl){
const r = hoverEl.getBoundingClientRect();
const targetX = r.left + r.width / 2;
const targetY = r.top + r.height / 2;
smoothX += (targetX - smoothX) * ease;
smoothY += (targetY - smoothY) * ease;
curW = r.width;
curH = r.height;
ptr.style.left = (smoothX - curW / 2) + 'px';
ptr.style.top = (smoothY - curH / 2) + 'px';
ptr.style.width = curW + 'px';
ptr.style.height = curH + 'px';
}else{
curW = 40;
curH = 40;
smoothX += (mx - smoothX) * ease;
smoothY += (my - smoothY) * ease;
ptr.style.left = (smoothX - 20) + 'px';
ptr.style.top = (smoothY - 20) + 'px';
ptr.style.width = curW + 'px';
ptr.style.height = curH + 'px';
}
requestAnimationFrame(loop);
}
loop();
const sel = [
'.citizen-nav a',
'.citizen-menu a',
'.citizen-button',
'.citizen-action-button',
'.cdx-button',
'.mw-editsection a',
'#citizen-header__nav a',
'.citizen-sidebar a',
'._target',
'.commentstreams-button',
'.commentstreams-submit',
'.commentstreams-header button',
'.commentstreams-box button',
'.mw-ui-button',
'button',
'a[role="button"]'
].join(',');
function bind(){
document.querySelectorAll(sel).forEach(el=>{
if(el._magBind)return;
el._magBind = 1;
el.addEventListener('mouseenter', ()=> {
hoverEl = el;
ptr.classList.add('pause-rotate');
});
el.addEventListener('mouseleave', ()=> {
hover ptr.classList.remove('pause-rotate');
});
});
}
bind();
new MutationObserver(bind).observe(document.body,{childList:true,subtree:true});
});
})();