LLWiki正在建设中,欢迎加入我们

“User:Bhsd/minerva.js”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
(// 使用Wikiplus小工具快速编辑)
标签移动版网页编辑 移动版编辑
(overflow和sticky冲突)
标签撤销 移动版网页编辑 移动版编辑
第13行: 第13行:


// 直接进入讨论页
// 直接进入讨论页
//$(function() { $('.talk').off( 'click' ).click(function(e) { e.stopImmediatePropagation(); }); });
$(function() { $('.talk').off( 'click' ).click(function(e) { e.stopImmediatePropagation(); }); });


if (mw.config.get( 'wgArticleId' ) == 1521) {
if (mw.config.get( 'wgArticleId' ) == 1521) {
第73行: 第73行:
}) ) ).after( $('<li>').append( $('<a>', {href: script + '/Special:版本',
}) ) ).after( $('<li>').append( $('<a>', {href: script + '/Special:版本',
html: '<i class="fa fa-puzzle-piece"></i><span>版本</span>'}) ) );
html: '<i class="fa fa-puzzle-piece"></i><span>版本</span>'}) ) );
});

var $thead = {};
const tsticky = function() {
if (!$thead.length) { return; }
$thead.each(function() {
$(this).children( 'tr' ).toArray().reduce(function(height, ele, i) {
const $tr = $(ele);
if (i) { $tr.children( 'th' ).css('top', height); }
return height + $tr.height();
}, 0);
});
},
resize = mw.util.debounce(500, tsticky); // 降低不必要的执行频率
$(window).resize( resize );
mw.hook( 'wikipage.content' ).add(function($content) {
$thead = {}; // 立即清空$thead,防止出错
const $table = $content.find( '.wikitable.tsticky.sortable' ),
updateThead = function() {
if ($table.not( '.jquery-tablesorter' ).length) { return; } // 还需要继续等待jquery.tablesorter执行
observer.disconnect();
$thead = $table.children( 'thead' ).filter(function() { return this.childNodes.length > 1; });
tsticky();
},
observer = new MutationObserver( updateThead ); // jshint ignore: line
$table.each(function() { observer.observe(this, {attributes: true, attributeFilter: ['class']}); })
.filter( '.sif-song-table' ).find( 'th:has(.tabs-dropdown)' ).css('z-index', 2);
updateThead(); // 立即尝试更新需要固定的表头
});
});
});
});

2021年7月14日 (三) 11:57的版本

//<nowiki>
// 拆分自[[Special:Mypage/common.js]],不可使用ES6语法
"use strict";
mw.loader.using( 'jquery.client' ).then(function() {
    if ($.client.profile().name == 'firefox') {
        mw.gadgets = $.extend(mw.gadgets, {stickyHeading: {mode: 'desktop'}});
        mw.hook( 'wikipage.content' ).add(function($content) {
            console.log('Hook: wikipage.content, Firefox开始移除黏性章节标题');
            $content.removeClass( 'stickyHeading' );
        });
    }
});

// 直接进入讨论页
$(function() { $('.talk').off( 'click' ).click(function(e) { e.stopImmediatePropagation(); }); });

if (mw.config.get( 'wgArticleId' ) == 1521) {
    mw.loader.using( ['oojs-ui-core', 'ext.gadget.site-lib'] ).then(function() {
        mw.tipsy( $('#bodyContent'), '.myTable td[data-sort-value]', {id: 'myTipsy'} );
    });
}

mw.loader.using( 'mediawiki.util' ).then(function() {
    const nsid = mw.config.get( 'wgNamespaceNumber' ),
        specialPage = mw.config.get( 'wgCanonicalSpecialPageName' ),
        pageName = mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ),
        title = mw.util.wikiUrlencode( mw.config.get('wgTitle') ),
        script = mw.config.get('wgScript'),
        loadJs = function(page) { mw.loader.load(script + '?action=raw&ctype=text/javascript&title=' + page); };

    if (mw.config.get( 'wgArticleId' ) > 0 && mw.config.get('wgAction') == 'view') {
        // 移动版强制章节折叠
        loadJs( 'user:bhsd/mobileCollapse.js' );
    }
    else if (specialPage == 'Recentchanges') {
        // 移除多余的符号和空白字符
        mw.hook( 'wikipage.content' ).add(function($content) {
            console.log('Hook: wikipage.content,开始移除多余字符');
            $content.find( '.mw-changeslist-line-inner' ).contents().filter(function() { return this.nodeType == 3; })
                .remove();
        });
    }
    else if (specialPage == "History") {
        /* 移动版历史添加与当前对比链接 */
        $(function() {
            const lastrevid = mw.util.getParamValue( 'offset' ) ? 'cur' : parseInt( $('.page-summary > a').first().attr( 'href' ).match(/\d+$/) );
            $('.list-thumb').append(function() {
                const oldid = parseInt( $(this).parent().attr( 'href' ).match( /\d+$/ ) );
                return oldid == lastrevid ? null : $('<p>').append( $('<a>', {text: "当前",
                    href: '/zh/special:diff/' + oldid + '/' + lastrevid}) );
            });
        });
    }

    /* 自定义移动版导航 */
    mw.hook( 'mobile.menu' ).add(function($menu) {
        console.log('Hook: mobile.menu,开始添加自定义导航项目');
        $menu.find( '.mw-ui-icon-minerva-contributions' ).parent()
            .after( $('<li>').append( $('<a>', {html: '<i class="fa fa-folder-open"></i><span>子页面</span>',
                href: script + '?title=Special:前缀索引&prefix=' + title + '/&namespace=' + nsid + '&stripprefix=1'
            }) ) ).after( $('<li>').append( $('<a>', {html: '<i class="fa fa-hourglass-half"></i><span>展开模板</span>',
                href: script + '?title=Special:展开模板&wpRemoveComments=1&wpGenerateRawHtml=true&wpInput={{:' + pageName + '}}'
            }) ) ).after( $('<li>').append( $('<a>', {html: '<i class="fa fa-copy"></i><span>所有页面</span>',
                href: script + '?title=Special:所有页面&namespace=' + nsid
            }) ) ).after( $('<li>').append( $('<a>', {href: script + '/Special:替换文本',
                html: '<i class="fa fa-retweet"></i><span>替换文本</span>'
            }) ) ).after( $('<li>').append( $('<a>', {href: script + '/Special:滥用过滤器',
                html: '<i class="fa fa-ban"></i><span>滥用过滤器</span>'
            }) ) ).after( $('<li>').append( $('<a>', {href: script + '?target=http://*&title=Special:链接搜索',
                html: '<i class="fas fa-external-link-alt"></i><span>链接搜索</span>'
            }) ) ).after( $('<li>').append( $('<a>', {html: '<i class="fa fa-users"></i><span>用户列表</span>',
                href: script + '?title=Special:用户列表&creationSort=1&desc=1'
            }) ) ).after( $('<li>').append( $('<a>', {href: script + '/Special:版本',
                html: '<i class="fa fa-puzzle-piece"></i><span>版本</span>'}) ) );
    });
});
//</nowiki>