LLWiki正在建设中,欢迎加入我们!
MediaWiki:Gadget-noteTA.js
跳转到导航
跳转到搜索
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
// <nowiki> var noteTAViewer = function() { var api = new mw.Api(); var init = function() { var $dialog = $( '<div class="noteTA-dialog" />' ) .html( '<div class="mw-ajax-loader" style="margin-top: 48px;" />' ); $dialog.dialog( {title: wgULS( '字词转换', '字詞轉換' )} ); run( $dialog ); return $dialog; }; var run = function( $dialog ) { var wikitext = '', $dom = $( '.noteTA' ), actualTitle = mw.config.get( 'wgPageName' ).replace( /_/g, ' ' ); var parse = function() { api.get({ action: 'parse', contentmodel: 'wikitext', text: wikitext, prop: 'text', variant: mw.config.get( 'wgUserVariant' ), formatversion:2 }) .then( function( results ) { $dialog.html( results.parse.text ); $dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) ); $dialog.dialog( 'option', 'position', 'center' ); $dialog.find( '.mw-collapsible' ).makeCollapsible(); }); }; var $noteTAtitle = $dom.find( '.noteTA-title' ), editlink = '<span style="float:right">[{{plainlinks|{{fullurl:' + actualTitle + '|action=edit}} 编辑}}]</span>'; if ( $noteTAtitle.length ) { var titleConv = $noteTAtitle.attr( 'data-noteta-code' ), titleDesc = $noteTAtitle.attr( 'data-noteta-desc' ); titleDesc = titleDesc ? '(' + titleDesc + ')' : ''; wikitext += '; 本文使用标题手工转换。' + editlink + '\n' + '* 转换标题为:-{D|' + titleConv + '}-' + titleDesc + '\n' + '* 实际标题为:-{R|' + actualTitle + '}-;当前显示为:-{|' + titleConv + '}-\n'; } var $noteTAgroups = $dom.find( '.noteTA-group > div' ); if( $noteTAgroups.length ) { $noteTAgroups.each( function() { var $this = $( this ), groupName = $this.attr( 'data-noteta-group' ); wikitext += '; {{#invoke:cGroupViewer|dialog|' + groupName + '}}\n'; }); } var $noteTAlocal = $dom.find( '.noteTA-local' ); if ( $noteTAlocal.length ) { wikitext += '; 本文使用全文手工转换。' + editlink + '\n'; var $noteTAlocals = $noteTAlocal.children(); $noteTAlocals.each( function() { var $this = $( this ), localConv = $this.attr( 'data-noteta-code' ), localDesc = $this.attr( 'data-noteta-desc' ); localDesc = localDesc ? '(' + localDesc + ')' : ''; wikitext += '# -{D|' + localConv + '}-' + localDesc + ' 当前显示为:-{' + localConv + '}-\n'; }); } parse(); }; var $this = $( '#mw-indicator-noteTA, #mw-mobile-noteTA' ), $dialog = null; $this.click( function() { if ( $dialog === null ) { $dialog = init(); } else { $dialog.dialog( 'open' ); } }); $(window).on('resize', function() { $dialog.dialog( 'option', 'width', Math.round( $( window ).width() * 0.8 ) ); }); }; mw.hook('wikipage.content').add( function ( $content ) { if( $( '#mw-indicator-noteTA, #mw-mobile-noteTA' ).length ) { noteTAViewer(); } }); // </nowiki>