打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Citizen.js:修订间差异

MediaWiki界面页面
OnlyOTO留言 | 贡献
无编辑摘要
OnlyOTO留言 | 贡献
无编辑摘要
第1行: 第1行:
(function() {
(function() {
    mw.loader.using('jquery', function() {
if( window.magneticCursorInit ) return;
        $(function() {
window.magneticCursorInit = true;
            if (document.querySelector('.magnetic-pointer-original')) return;


            const pointer = document.createElement('div');
mw.loader.using( [], function() {
            pointer.className = 'magnetic-pointer-original';
    // 创建四角光标
            pointer.innerHTML = '<div></div><div></div><div></div><div></div>';
    const ptr = document.createElement('div');
            document.body.appendChild(pointer);
    ptr.className = 'magnetic-true-corner';
    ptr.innerHTML = `<i></i><i></i><i></i><i></i>`;
    document.body.appendChild(ptr);


            const style = document.createElement('style');
    // 样式:原版亮绿 + 纯拐角无方块
            style.textContent = `
    const css = document.createElement('style');
.magnetic-pointer-original {
    css.textContent = `
    --width: 4rem;
    .magnetic-true-corner{
    --height: 4rem;
        position:fixed;
    position: fixed;
        left:0;top:0;
    top: calc(var(--height) / -2);
        width:0;height:0;
    left: calc(var(--width) / -2);
        pointer-events:none;
    width: var(--width);
        z-index:999999!important;
    height: var(--height);
    }
    transition: all 0.2s ease-out;
    .magnetic-true-corner i{
    pointer-events: none;
        position:absolute;
    z-index: 99999;
        width:14px;height:14px;
}
        border:2px solid #17f700;
/* 白天模式:绿色 */
        background:transparent!important;
.magnetic-pointer-original div {
        box-shadow:none!important;
    position: absolute;
     }
    width: 0.8rem;
    /* 只留拐角,镂空 */
    height: 0.8rem;
    .magnetic-true-corner i:nth-child(1){top:-2px;left:-2px;border-right:none;border-bottom:none;}
    border-color: #17f700;
    .magnetic-true-corner i:nth-child(2){top:-2px;right:-2px;border-left:none;border-bottom:none;}
    background: transparent !important;
     .magnetic-true-corner i:nth-child(3){bottom:-2px;left:-2px;border-right:none;border-top:none;}
    border-top:3px solid transparent;
    .magnetic-true-corner i:nth-child(4){bottom:-2px;right:-2px;border-left:none;border-top:none;}
     border-left:3px solid transparent;
    `;
}
    document.head.appendChild(css);
/* 黑夜模式:白色 */
html[data-color-scheme="dark"] .magnetic-pointer-original div {
     border-color: #ffffff !important;
}


.magnetic-pointer-original div:nth-child(1) {top:0;left:0;border-top-color:inherit;border-left-color:inherit;}
    let hoverEl = null;
.magnetic-pointer-original div:nth-child(2) {top:0;right:0;border-top-color:inherit;border-right-color:inherit;}
    let mx = 0, my = 0;
.magnetic-pointer-original div:nth-child(3) {bottom:0;left:0;border-bottom-color:inherit;border-left-color:inherit;}
    // 光标缓冲坐标(做顺滑移动)
.magnetic-pointer-original div:nth-child(4) {bottom:0;right:0;border-bottom-color:inherit;border-right-color:inherit;}
    let smoothX = 0, smoothY = 0;
            `;
    let curW = 40, curH = 40;
            document.head.appendChild(style);


            let currentTarget = null;
    // 鼠标实时位置
            let currentX = 0, currentY = 0;
    document.addEventListener('mousemove', e => {
        mx = e.clientX;
        my = e.clientY;
    });


            const onMouseMove = function(e) {
    // 顺滑帧动画:磁吸缓冲
                let x = e.clientX;
    function loop(){
                let y = e.clientY;
        const ease = 0.15; // 磁吸顺滑度,越小越黏
                if (currentTarget) {
        if(hoverEl){
                    const rect = currentTarget.getBoundingClientRect();
            // 吸附到元素中心 + 缓冲
                    const centerX = rect.left + rect.width / 2;
            const r = hoverEl.getBoundingClientRect();
                    const centerY = rect.top + rect.height / 2;
            const targetX = r.left + r.width / 2;
                    x = centerX + (x - centerX) * 0.1;
            const targetY = r.top + r.height / 2;
                    y = centerY + (y - centerY) * 0.1;
            smoothX += (targetX - smoothX) * ease;
                }
            smoothY += (targetY - smoothY) * ease;
                currentX = x;
            curW = r.width;
                currentY = y;
            curH = r.height;
                pointer.style.transform = `translate(${currentX}px, ${currentY}px)`;
            };


             const onMouseEnter = function(e) {
             // 四角框精准包住按钮
                currentTarget = e.currentTarget;
            ptr.style.left = (smoothX - curW / 2) + 'px';
                const rect = currentTarget.getBoundingClientRect();
            ptr.style.top = (smoothY - curH / 2) + 'px';
                pointer.style.setProperty('--width', rect.width + window.innerWidth / 50 + 'px');
            ptr.style.width = curW + 'px';
                pointer.style.setProperty('--height', rect.height + window.innerWidth / 50 + 'px');
            ptr.style.height = curH + 'px';
             };
        }else{
            // 常态跟随鼠标,小光标顺滑移动
            curW = 40;
            curH = 40;
            smoothX += (mx - smoothX) * ease;
             smoothY += (my - smoothY) * ease;


             const onMouseLeave = function() {
             ptr.style.left = (smoothX - 20) + 'px';
                currentTarget = null;
            ptr.style.top = (smoothY - 20) + 'px';
                pointer.style.setProperty('--width', '4rem');
            ptr.style.width = curW + 'px';
                pointer.style.setProperty('--height', '4rem');
            ptr.style.height = curH + 'px';
            };
        }
        requestAnimationFrame(loop);
    }
    loop();


            // 自动绑定:你自定义的 + Citizen + 评论插件
    // Citizen 精准按钮选择器
            const bindTargets = function() {
const sel = [
                document.querySelectorAll(`
    // 官方皮肤按钮
                    ._target,
    '.citizen-nav a',
                    .citizen-button,
    '.citizen-menu a',
                    .citizen-nav a,
    '.citizen-button',
                    .citizen-menu a,
    '.citizen-action-button',
                    .citizen-sidebar a,
    '.cdx-button',
                    .cdx-button,
    '.mw-editsection a',
                    .mw-ui-button,
    '#citizen-header__nav a',
                    button,
    '.citizen-sidebar a',
                    [class*="commentstreams"] button,
   
                    .commentstreams-box button,
    // ✅ 你自己加的 _target 类(所有你想吸附的元素)
                    .commentstreams-submit
    '._target',
                `).forEach(el => {
   
                    if (el._magneticBound) return;
    // ✅ Commentstreams 评论插件全按钮自动吸附
                    el._magneticBound = true;
    '.commentstreams-button',
                    el.addEventListener('mouseenter', onMouseEnter);
    '.commentstreams-submit',
                    el.addEventListener('mouseleave', onMouseLeave);
    '.commentstreams-header button',
                });
    '.commentstreams-box button',
            };
   
    // ✅ 常用插件通用按钮(全覆盖)
    '.mw-ui-button',
    'button',
    'a[role="button"]'
].join(',');


            window.addEventListener('mousemove', onMouseMove);
    function bind(){
             bindTargets();
        document.querySelectorAll(sel).forEach(el=>{
             const observer = new MutationObserver(bindTargets);
             if(el._magBind)return;
             observer.observe(document.body, { childList: true, subtree: true });
             el._magBind = 1;
            el.addEventListener('mouseenter', ()=> hoverEl = el);
             el.addEventListener('mouseleave', ()=> hoverEl = null);
         });
         });
     });
     }
 
    bind();
    new MutationObserver(bind).observe(document.body,{childList:true,subtree:true});
});
})();
})();

2026年3月31日 (二) 16:12的版本

(function() {
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 = `
    .magnetic-true-corner{
        position:fixed;
        left:0;top:0;
        width:0;height:0;
        pointer-events:none;
        z-index:999999!important;
    }
    .magnetic-true-corner i{
        position:absolute;
        width:14px;height:14px;
        border:2px solid #17f700;
        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();

    // Citizen 精准按钮选择器
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 类(所有你想吸附的元素)
    '._target',
    
    // ✅ Commentstreams 评论插件全按钮自动吸附
    '.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);
            el.addEventListener('mouseleave', ()=> hoverEl = null);
        });
    }

    bind();
    new MutationObserver(bind).observe(document.body,{childList:true,subtree:true});
});
})();