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

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

来自LLWiki
跳转到导航 跳转到搜索
(// 使用Wikiplus小工具快速编辑)
标签移动版网页编辑 移动版编辑
(// 使用Wikiplus小工具快速编辑)
标签移动版网页编辑 移动版编辑
第40行: 第40行:
else if (specialPageName == "History") {
else if (specialPageName == "History") {
/* 移动版历史添加与当前对比链接 */
/* 移动版历史添加与当前对比链接 */
const addDiffLink = function(lastrevid) {
function addDiffLink(lastrevid) {
$('.page-summary > a').each(function() {
$('.page-summary > a').each(function() {
const oldid = parseInt( this.href.match( /\d+$/ ) );
const oldid = parseInt( this.href.match( /\d+$/ ) );
第48行: 第48行:
}
}
});
});
},
}
href = window.location.href;
mw.hook( 'wikipage.content' ).add(function() {
mw.hook( 'wikipage.content' ).add(function() {
console.log('Hook: wikipage.content,开始添加与当前对比链接');
console.log('Hook: wikipage.content,开始添加与当前对比链接');

2020年12月12日 (六) 11:44的版本

//<nowiki>
// 拆分自[[Special:Mypage/common.js]],不可使用ES6语法
"use strict";
/*global mw, $, wgULS*/
mw.gadgets = mw.gadgets || {};
mw.loader.using( 'jquery.client' ).then(function() {
    if ($.client.profile().name == 'firefox') {
        mw.gadgets.stickyHeading = $.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(); }); });

mw.loader.using( 'mediawiki.util' ).then(function() {
    const nsid = mw.config.get( 'wgNamespaceNumber' ),
        specialPageName = 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');
    function loadJs(page) { mw.loader.load(script + '?action=raw&ctype=text/javascript&title=' + page); }

    if (nsid >= 0 && mw.config.get('wgAction') == 'view') {
        // 移动版强制章节折叠
        loadJs( 'user:bhsd/mobileCollapse.js' );
    }
    else if (specialPageName == '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 (specialPageName == "History") {
        /* 移动版历史添加与当前对比链接 */
        function addDiffLink(lastrevid) {
            $('.page-summary > a').each(function() {
                const oldid = parseInt( this.href.match( /\d+$/ ) );
                if (oldid < lastrevid) {
                    $(this).children( '.list-thumb' ).append( $('<p>', {html: $('<a>', {text: wgULS("当前", "目前"),
                        href: script + '/special:移动版差异/' + oldid + '...' + lastrevid })}) );
                }
            });
        }
        mw.hook( 'wikipage.content' ).add(function() {
            console.log('Hook: wikipage.content,开始添加与当前对比链接');
            if ( !mw.util.getParamValue( 'offset' ) ) {
                const lastrevid = $('.page-summary > a').first().attr( 'href' ).match(/\d+$/);
                addDiffLink(parseInt( lastrevid ));
                return;
            }
            mw.loader.using( 'mediawiki.api' ).then(function() {
                const timerStart = mw.now();
                console.log('API request: 查询最新修订ID');
                new mw.Api().get({ action: 'query', prop: 'info', titles: mw.config.get( 'wgRelevantPageName' ),
                    formatversion: 2 }).then(function(data) {
                    console.log('End API request: 已获得最新修订ID,用时 ' + (mw.now() - timerStart) + ' ms');
                    addDiffLink(parseInt( data.query.pages[0].lastrevid ));
                }, function(reason) { mw.notify('无法获得最新修订ID。错误信息:' + reason, {type: 'error'}); });
            });
        });
    }

    /* 自定义移动版导航 */
    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>