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

MediaWiki:Citizen.js:修订间差异

MediaWiki界面页面
OnlyOTO留言 | 贡献
无编辑摘要
OnlyOTO留言 | 贡献
无编辑摘要
第1行: 第1行:
/* 这里所有JavaScript都会加载给Citizen皮肤的用户 */
/* 这里所有JavaScript都会加载给Citizen皮肤的用户 */
(function() {
(function() {
    mw.loader.using('jquery', function() {
if( window.magneticCursorInit ) return;
        $(function() {
window.magneticCursorInit = true;
            if (document.querySelector('.magnetic-pointer-original')) return;


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


            // 样式:纯空心四角角标
    // 强制覆盖样式:纯四角镂空,永不方块
            const style = document.createElement('style');
    const css = document.createElement('style');
            style.textContent = `
    css.textContent = `
.magnetic-pointer-original {
    .magnetic-true-corner{
    --width: 48px;
        position:fixed;left:0;top:0;
    --height: 48px;
        width:0;height:0;
    position: fixed;
        pointer-events:none;z-index:999999!important;
    top: 0;
        transition:none;will-change:left,top;
    left: 0;
    }
    width: var(--width);
    .magnetic-true-corner i{
    height: var(--height);
        position:absolute;width:14px;height:14px;
    transform-origin: center center;
        border:2px solid #17f700;border-radius:2px;
    transition: transform 0.22s ease, width 0.22s ease, height 0.22s ease;
        background:transparent!important;box-shadow:none!important;
    pointer-events: none !important;
    }
    z-index: 999999 !important;
    .magnetic-true-corner i:nth-child(1){top:-2px;left:-2px;border-right:none;border-bottom:none;}
    will-change: transform, width, height;
    .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-pointer-original div {
    .magnetic-true-corner i:nth-child(4){bottom:-2px;right:-2px;border-left:none;border-top:none;}
    position: absolute;
    `;
    width: 12px;
    document.head.appendChild(css);
    height: 12px;
    border-color: #17f700;
    background: transparent !important;
    box-sizing: border-box;
}
.magnetic-pointer-original div:nth-child(1) { top: 0; left: 0; border-top: 2px solid; border-left: 2px solid; }
.magnetic-pointer-original div:nth-child(2) { top: 0; right: 0; border-top: 2px solid; border-right: 2px solid; }
.magnetic-pointer-original div:nth-child(3) { bottom: 0; left: 0; border-bottom: 2px solid; border-left: 2px solid; }
.magnetic-pointer-original div:nth-child(4) { bottom: 0; right: 0; border-bottom: 2px solid; border-right: 2px solid; }
            `;
            document.head.appendChild(style);


            let target = null;
    let hoverEl = null;
            let mouseX = 0, mouseY = 0;
    let mx=0,my=0;
            let cursorX = 0, cursorY = 0;


            // 鼠标位置实时更新
    // 鼠标实时位置
            window.addEventListener('mousemove', (e) => {
    document.addEventListener('mousemove',e=>{mx=e.clientX;my=e.clientY;});
                mouseX = e.clientX;
                mouseY = e.clientY;
            });


            // 平滑跟随循环
    // 帧更新:精准贴元素四角
            function update() {
    function loop(){
                if (target) {
        if(hoverEl){
                    const rect = target.getBoundingClientRect();
            const r = hoverEl.getBoundingClientRect();
                    const cx = rect.left + rect.width / 2;
            ptr.style.left = r.left + 'px';
                    const cy = rect.top + rect.height / 2;
            ptr.style.top = r.top + 'px';
            ptr.style.width = r.width + 'px';
            ptr.style.height = r.height + 'px';
        }else{
            // 跟随鼠标缩小光标
            ptr.style.left = (mx - 20) + 'px';
            ptr.style.top = (my - 20) + 'px';
            ptr.style.width = '40px';
            ptr.style.height = '40px';
        }
        requestAnimationFrame(loop);
    }
    loop();


                    cursorX += (cx - cursorX) * 0.2;
    // ✅ Citizen 皮肤【官方原生真实选择器】一个不漏
                    cursorY += (cy - cursorY) * 0.2;
    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'
    ].join(',');


                    pointer.style.width = rect.width + 12 + 'px';
    // 绑定+防重复
                    pointer.style.height = rect.height + 12 + 'px';
    function bind(){
                } else {
        document.querySelectorAll(sel).forEach(el=>{
                    cursorX += (mouseX - cursorX) * 0.25;
             if(el._magBind)return;
                    cursorY += (mouseY - cursorY) * 0.25;
             el._magBind=1;
                    pointer.style.width = '48px';
             el.onmouseenter=()=>hoverEl=el;
                    pointer.style.height = '48px';
             el.onmouseleave=()=>hoverEl=null;
                }
        });
 
    }
                pointer.style.transform = `translate(${cursorX - pointer.offsetWidth/2}px, ${cursorY - pointer.offsetHeight/2}px)`;
                requestAnimationFrame(update);
             }
            update();
 
             // 👇 这是 Citizen 皮肤真正的按钮选择器(全覆盖)
            const citizenSelectors = [
                ".citizen-button",
                ".citizen-ui-btn",
                ".citizen-nav__item a",
                ".citizen-menu__item a",
                "#citizen-header a",
                "#citizen-sidebar a",
                "a.citizen-button",
                "button.citizen-button",
                ".mw-editsection a",
                ".mw-ui-button",
                ".citizen-btn"
             ].join(",");
 
             function bind() {
                document.querySelectorAll(citizenSelectors).forEach(el => {
                    if (el._magnet) return;
                    el._magnet = 1;


                    el.addEventListener("mouseenter", () => {
    bind();
                        target = el;
    new MutationObserver(bind).observe(document.body,{childList:true,subtree:true});
                    });
});
                    el.addEventListener("mouseleave", () => {
                        target = null;
                    });
                });
            }
 
            bind();
            new MutationObserver(bind).observe(document.body, { childList: true, subtree: true });
        });
    });
})();
})();

2026年3月31日 (二) 15:59的版本

/* 这里所有JavaScript都会加载给Citizen皮肤的用户 */
(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;
        transition:none;will-change:left,top;
    }
    .magnetic-true-corner i{
        position:absolute;width:14px;height:14px;
        border:2px solid #17f700;border-radius:2px;
        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;

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

    // 帧更新:精准贴元素四角
    function loop(){
        if(hoverEl){
            const r = hoverEl.getBoundingClientRect();
            ptr.style.left = r.left + 'px';
            ptr.style.top = r.top + 'px';
            ptr.style.width = r.width + 'px';
            ptr.style.height = r.height + 'px';
        }else{
            // 跟随鼠标缩小光标
            ptr.style.left = (mx - 20) + 'px';
            ptr.style.top = (my - 20) + 'px';
            ptr.style.width = '40px';
            ptr.style.height = '40px';
        }
        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'
    ].join(',');

    // 绑定+防重复
    function bind(){
        document.querySelectorAll(sel).forEach(el=>{
            if(el._magBind)return;
            el._magBind=1;
            el.onmouseenter=()=>hoverEl=el;
            el.onmouseleave=()=>hoverEl=null;
        });
    }

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