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

MediaWiki:Citizen.js:修订间差异

MediaWiki界面页面
OnlyOTO留言 | 贡献
无编辑摘要
OnlyOTO留言 | 贡献
无编辑摘要
标签手工回退
 
(未显示同一用户的16个中间版本)
第1行: 第1行:
/* 这里所有JavaScript都会加载给Citizen皮肤的用户 */
(function() {
(function() {
    mw.loader.using('jquery', function() {
// 页面白名单
        $(function() {
const allowPages = [
            if (document.querySelector('.magnetic-pointer-original')) return;
  "首页",
  "Main Page",
  "你的自定义首页名字"
];
const currentPage = mw.config.get("wgTitle");


            // 光标 DOM
            const pointer = document.createElement('div');
            pointer.className = 'magnetic-pointer-original';
            pointer.innerHTML = '<div></div><div></div><div></div><div></div>';
            document.body.appendChild(pointer);


            // 样式:纯空心四角角标
if( !allowPages.includes(currentPage) ){
            const style = document.createElement('style');
  return;
            style.textContent = `
.magnetic-pointer-original {
    --width: 48px;
    --height: 48px;
    position: fixed;
    top: 0;
    left: 0;
    width: var(--width);
    height: var(--height);
    transform-origin: center center;
    transition: transform 0.22s ease, width 0.22s ease, height 0.22s ease;
    pointer-events: none !important;
    z-index: 999999 !important;
    will-change: transform, width, height;
}
}
.magnetic-pointer-original div {
if( window.magneticCursorInit ) return;
    position: absolute;
window.magneticCursorInit = true;
    width: 12px;
    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;
mw.loader.using( [], function() {
            let mouseX = 0, mouseY = 0;
    // 创建四角光标
            let cursorX = 0, cursorY = 0;
    const ptr = document.createElement('div');
    ptr.className = 'magnetic-true-corner';
    ptr.innerHTML = `<i></i><i></i><i></i><i></i>`;
    document.body.appendChild(ptr);


            // 鼠标位置实时更新
    // 样式
            window.addEventListener('mousemove', (e) => {
    const css = document.createElement('style');
                mouseX = e.clientX;
    css.textContent = `
                mouseY = e.clientY;
            });


            // 平滑跟随循环
/* 隐藏浏览器原生光标 */
            function update() {
body {
                if (target) {
  cursor: none !important;
                    const rect = target.getBoundingClientRect();
}
                    const cx = rect.left + rect.width / 2;
/* 防止输入框/按钮露馅,强制全局隐藏 */
                    const cy = rect.top + rect.height / 2;
* {
  cursor: none !important;
}


                    cursorX += (cx - cursorX) * 0.2;
    .magnetic-true-corner{
                    cursorY += (cy - cursorY) * 0.2;
        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 #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);


                    pointer.style.width = rect.width + 12 + 'px';
    let hoverEl = null;
                    pointer.style.height = rect.height + 12 + 'px';
    let mx = 0, my = 0;
                } else {
    // 光标缓冲坐标
                    cursorX += (mouseX - cursorX) * 0.25;
    let smoothX = 0, smoothY = 0;
                    cursorY += (mouseY - cursorY) * 0.25;
    let curW = 40, curH = 40;
                    pointer.style.width = '48px';
                    pointer.style.height = '48px';
                }


                pointer.style.transform = `translate(${cursorX - pointer.offsetWidth/2}px, ${cursorY - pointer.offsetHeight/2}px)`;
    // 鼠标实时位置
                requestAnimationFrame(update);
    document.addEventListener('mousemove', e => {
            }
        mx = e.clientX;
            update();
        my = e.clientY;
    });


             // 👇 这是 Citizen 皮肤真正的按钮选择器(全覆盖)
    // 顺滑帧磁吸缓冲
             const citizenSelectors = [
    function loop(){
                ".citizen-button",
        const ease = 0.15; // 磁吸顺滑度
                ".citizen-ui-btn",
        if(hoverEl){
                ".citizen-nav__item a",
             // 吸附到元素中心 + 缓冲
                ".citizen-menu__item a",
             const r = hoverEl.getBoundingClientRect();
                "#citizen-header a",
            const targetX = r.left + r.width / 2;
                "#citizen-sidebar a",
            const targetY = r.top + r.height / 2;
                "a.citizen-button",
            smoothX += (targetX - smoothX) * ease;
                "button.citizen-button",
            smoothY += (targetY - smoothY) * ease;
                ".mw-editsection a",
            curW = r.width;
                ".mw-ui-button",
             curH = r.height;
                ".citizen-btn"
             ].join(",");


             function bind() {
             // 四角框
                document.querySelectorAll(citizenSelectors).forEach(el => {
            ptr.style.left = (smoothX - curW / 2) + 'px';
                    if (el._magnet) return;
            ptr.style.top = (smoothY - curH / 2) + 'px';
                    el._magnet = 1;
            ptr.style.width = curW + 'px';
            ptr.style.height = curH + 'px';
        }else{
            // 常态跟随鼠标
            curW = 40;
            curH = 40;
            smoothX += (mx - smoothX) * ease;
            smoothY += (my - smoothY) * ease;


                    el.addEventListener("mouseenter", () => {
            ptr.style.left = (smoothX - 20) + 'px';
                        target = el;
            ptr.style.top = (smoothY - 20) + 'px';
                    });
            ptr.style.width = curW + 'px';
                    el.addEventListener("mouseleave", () => {
            ptr.style.height = curH + 'px';
                        target = null;
        }
                    });
        requestAnimationFrame(loop);
                });
    }
            }
    loop();


             bind();
const sel = [
             new MutationObserver(bind).observe(document.body, { childList: true, subtree: true });
    // 官方皮肤按钮
    '.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});
});
})();
})();

2026年3月31日 (二) 23:17的最新版本

(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 {
  cursor: none !important;
}
/* 防止输入框/按钮露馅,强制全局隐藏 */
* {
  cursor: none !important;
}

    .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 #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 
    '._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});
});
})();