User:Liangent/Scripts/NoteTA2.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

// <nowiki>
( function( $, mw ) { mw.loader.using( [
    'jquery.ui',
    'mediawiki.api',
    'ext.gadget.site-lib'
], function() { $( function() {
    mw.util.addCSS( '#noteTA-dialog a { color: #3366BB; }' );

    var $dialog = null;
    var api = null;
    var init = function() {
        $dialog = $( '<div id="noteTA-dialog" />' );
        $dialog.html( '<div class="mw-ajax-loader" style="margin-top: 48px;" />' );
        $dialog.dialog( {
            title: wgULS( '字词转换', '字詞轉換' )
        } );
        api = new mw.Api();
        run();
    }, run = function() {
        var wikitext = '';
        var $dom = $( '#noteTA' );

        var $noteTAtitle = $dom.find( '#noteTA-title' );
        if ( $noteTAtitle.length ) {
            var titleConv = decodeURIComponent( $noteTAtitle.data( 'noteta-code' ).replace(/\+/g, '%20') );
            var titleDesc = $noteTAtitle.data( 'noteta-desc' );
            if ( titleDesc ) {
                titleDesc = '(' + decodeURIComponent( titleDesc.replace(/\+/g, '%20') ) + ')';
            } else {
                titleDesc = '';
            }
            wikitext += '; 本文使用[[Help:中文维基百科的繁简、地区词处理#條目標題|标题手工转换]] {{edit|' + mw.config.get( 'wgPageName' ) + '}}\n';
            wikitext += '* 转换标题为:-{D|' + titleConv + '}-' + titleDesc + '\n';
            wikitext += '* 实际标题为:-{' + mw.config.get( 'wgPageName' ) + '}-;当前显示为:-{' + titleConv + '}-\n';
        }

        var $noteTAgroups = $dom.find( '#noteTA-group > *[id^="noteTA-group-"]' );
        $noteTAgroups.each( function() {
            var $this = $( this );
            if ( $this.hasClass( 'noteTA-missing' ) ) {
                wikitext += '; 本文使用的公共转换组“' + $this.data( 'noteta-group' ) + '”尚未创建\n';
                wikitext += '* {{edit|Template:CGroup/' + $this.data( 'noteta-group' ) + '|创建公共转换组“' + $this.data( 'noteta-group' ) + '”}}\n';
            } else {
                wikitext += '{{CGroup/' + $this.data( 'noteta-group' ) + '}}\n';
            }
        } );

        var $noteTAlocal = $dom.find( '#noteTA-local' );
        if ( $noteTAlocal.length ) {
            wikitext += '; 本文使用[[Help:中文维基百科的繁简、地区词处理#控制自动转换的代碼|全文手工转换]] {{edit|' + mw.config.get( 'wgPageName' ) + '}}\n';
            var $noteTAlocals = $noteTAlocal.children( '*[id^="noteTA-local-"]' );
            $noteTAlocals.each( function() {
                var $this = $( this );
                var localConv = decodeURIComponent( $this.data( 'noteta-code' ).replace(/\+/g, '%20') );
                var localDesc = $this.data( 'noteta-desc' );
                if ( localDesc ) {
                    localDesc = '(' + decodeURIComponent( localDesc.replace(/\+/g, '%20') ) + ')';
                } else {
                    localDesc = '';
                }
                wikitext += '* -{D|' + localConv + '}-' + localDesc + '当前显示为:-{' + localConv + '}-\n';
            } );
        }

        // Maybe move to a template
        wikitext += '----\n';
        wikitext += '; [[Help:中文维基百科的繁简、地区词处理|字词转换]]说明\n';
        wikitext += ': 字詞轉換是中文维基的一項自動轉換,目的是通過-{zh-hans:计算机程序; zh-hant:電腦程式}-自動消除繁简、地区词等不同<strong>用字模式</strong>的差異,以達到閱讀方便。字詞轉換包括全局轉換和手動轉換,本說明所使用的标题转换和全文转换技術,都屬於手動轉換。\n';
        wikitext += ': 如果您想对我们的字词转换系统提出一些改进建议,或者提交应用面更广的转换([[中文维基百科]]全站乃至[[MediaWiki]]软件),或者报告转换系统的错误,请前往[[Wikipedia:字词转换请求或候选]]发表您的意见。\n';

        var parse = function() {
            api.post( {
                action: 'parse',
                title: 'Template:CGroup/-',
                text: wikitext,
                prop: 'text',
                variant: mw.config.get( 'wgUserVariant' )
            }, {
                ok: function( results ) {
                    $dialog.html( results.parse.text['*'] );
                    $dialog.dialog( 'option', 'width', Math.round( $( document ).width() * 0.8 ) );
                    $dialog.dialog( 'option', 'position', 'center' );
                },
                err: parse
            } );
        };
        parse();
    };

    $( '#noteTA-topicon' )
        .css( 'cursor', 'pointer' )
        .click( function() {
            if ( $dialog == null ) {
                init();
            } else {
                $dialog.dialog( 'open' );
            }
        } );
} ); } ); } )( jQuery, mediaWiki );
// </nowiki>