跳转到内容

MediaWiki:Gadget-PrintOptions.js:修订间差异

勤求古训,博采众方
无编辑摘要
标签已被回退
无编辑摘要
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
(function () {
/**
    'use strict';
* 打印选项是一个由 Derk-Jan Hartman / User:TheDJ 编写的小工具
   
* 更多信息参见 [[User:TheDJ/Print_options]]
    var windowManager;
*
    var printDialog;
* 采用 MIT 和/或 CC-by-SA 4.0 许可协议
   
*
    var printOptions = {
* 版权所有 (c) 2010-2017 Derk-Jan Hartman / User:TheDJ
        install: function () {
*
            var $printLink = $('#t-print a');
* 特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人,不受限制地处理本软件,
            if ($printLink.length === 0) return;
* 包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售本软件的副本,
           
* 并允许向其提供本软件的人这样做,但须符合以下条件:
            $printLink
*
                .text('可打印版本')
* 上述版权声明和本许可声明应包含在本软件的所有副本或主要部分中。
                .off('click')
*
                .on('click', function (e) {
* 本软件按“原样”提供,不提供任何形式的明示或暗示担保,
                    mw.loader.using(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows'])
* 包括但不限于对适销性、特定用途适用性和非侵权性的担保。
                        .then(printOptions.createWindow)
* 在任何情况下,作者或版权持有人均不对因使用本软件而产生的任何索赔、损害或其他责任承担责任,
                        .catch(function (err) {
* 无论是在合同诉讼、侵权诉讼还是其他诉讼中。
                            mw.notify('打印功能加载失败: ' + err.message, { type: 'error' });
*/
                        });
 
                    e.preventDefault();
( function () {
                });
'use strict';
           
var windowManager; // 窗口管理器实例
            // 预加载资源
var printDialog; // 打印对话框实例
            mw.loader.load(['oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows']);
 
        },
var printOptions = {
       
/**
        createWindow: function () {
* 安装打印选项功能
            function PrintDialog(config) {
* - 找到页面上的打印链接
                PrintDialog.super.call(this, config);
* - 重写打印链接的点击事件
            }
* - 预加载必要的 OOUI 组件
            OO.inheritClass(PrintDialog, OO.ui.ProcessDialog);
*/
           
install: function () {
            PrintDialog.static.name = 'printdialog';
var $printLink = $( '#t-print a' );
            PrintDialog.static.title = '打印此页面';
if ( $printLink.length === 0 ) {
            PrintDialog.static.actions = [
return;
                {
}
                    action: 'print',
$printLink
                    label: '打印',
.text( '打印页面' )
                    flags: ['primary', 'progressive'],
.off( 'click' )
                    icon: 'printer'
.get( 0 ).addEventListener( 'click', function ( e ) {
                },
// 加载 OOUI 核心组件、窗口组件和控件组件
                {  
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ] ).done( printOptions.createWindow );
                    action: 'cancel',
e.stopPropagation();
                    label: '取消',
e.preventDefault();
                    flags: 'safe',
}, true ); // 使用捕获阶段,以优先于其他点击处理程序
                    icon: 'close'
 
                }
// 延迟预加载 OOUI 组件
            ];
mw.loader.load( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ] );
           
},
            PrintDialog.prototype.initialize = function () {
 
                PrintDialog.super.prototype.initialize.apply(this, arguments);
/**
                this.panel = new OO.ui.PanelLayout({ padded: true, expanded: false });
* 创建打印选项对话框
                this.content = new OO.ui.FieldsetLayout();
* - 定义对话框类
               
* - 设置对话框标题和操作按钮
                printOptions.questions.forEach(function (question) {
* - 添加选项复选框
                    if (question.type === 'checkbox') {
* - 初始化窗口管理器并打开对话框
                        var checkbox = new OO.ui.CheckboxInputWidget({
*/
                            selected: question.checked
createWindow: function () {
                        });
// 定义打印对话框类
                        question.widget = checkbox;
function PrintDialog( config ) {
                        this.content.addItems([
PrintDialog.super.call( this, config );
                            new OO.ui.FieldLayout(checkbox, {
}
                                label: question.label,
// 继承 OO.ui.ProcessDialog
                                align: 'inline'
OO.inheritClass( PrintDialog, OO.ui.ProcessDialog );
                            })
 
                        ]);
// 对话框静态配置
                    }
PrintDialog.static.name = 'printdialog';
                }, this);
PrintDialog.static.title = '打印此页面';
               
PrintDialog.static.actions = [
                this.panel.$element.append(this.content.$element);
{ action: 'print', label: '打印', flags: 'primary' }, // 打印按钮(主要操作)
                this.$body.append(this.panel.$element);
{ label: '取消', flags: 'safe' } // 取消按钮(安全操作)
            };
];
           
 
            PrintDialog.prototype.getActionProcess = function (action) {
/**
                if (action === 'print') {
* 初始化对话框内容
                    return new OO.ui.Process(function () {
* - 创建面板和字段集
                        // 保存选项设置
* - 根据 questions 数组创建复选框
                        printOptions.questions.forEach(function (question) {
* - 将字段集添加到对话框中
                            if (question.widget) {
*/
                                printOptions[question.returnvalue] = question.widget.isSelected();
PrintDialog.prototype.initialize = function () {
                            }
var checkbox, fieldset = [];
                        });
PrintDialog.super.prototype.initialize.apply( this, arguments );
                       
// 创建面板布局
                        return this.close({ action: action }).then(function () {
this.panel = new OO.ui.PanelLayout( { padded: true, expanded: false } );
                            printOptions.changePrintCSS();
// 创建字段集布局
                            printOptions.otherEnhancements();
this.content = new OO.ui.FieldsetLayout();
                            setTimeout(window.print, 100);
 
                        });
// 遍历问题数组,创建复选框
                    }.bind(this));
for ( var i = 0; i < printOptions.questions.length; i++ ) {
                }
if ( printOptions.questions[ i ].type === 'checkbox' ) {
               
checkbox = new OO.ui.CheckboxInputWidget( {
                if (action === 'cancel') {
selected: printOptions.questions[ i ].checked // 设置默认选中状态
                    return new OO.ui.Process(function () {
} );
                        return this.close({ action: action });
// 保存复选框实例到问题对象中
                    }.bind(this));
printOptions.questions[ i ].widget = checkbox;
                }
// 创建字段布局并添加到字段集
               
fieldset.push( new OO.ui.FieldLayout( checkbox, { label: printOptions.questions[ i ].label, align: 'inline' } ) );
                return PrintDialog.super.prototype.getActionProcess.call(this, action);
}
            };
}
           
// 将字段集添加到内容布局
            if (!windowManager) {
this.content.addItems( fieldset );
                windowManager = new OO.ui.WindowManager();
 
                $('body').append(windowManager.$element);
// 将内容添加到面板,面板添加到对话框主体
            }
this.panel.$element.append( this.content.$element );
           
this.$body.append( this.panel.$element );
            // 每次都创建新的对话框实例,避免重复使用的问题
};
            printDialog = new PrintDialog({ size: 'medium' });
 
            windowManager.addWindows([printDialog]);
/**
           
* 处理对话框操作
            windowManager.openWindow(printDialog);
* @param {string} action - 操作名称
        },
* @returns {OO.ui.Process} 处理过程
       
*/
        changePrintCSS: function () {
PrintDialog.prototype.getActionProcess = function ( action ) {
            var printStyle = '';
var dialog = this;
           
if ( action === 'print' ) {
            if (this.noimages) {
return new OO.ui.Process( function () {
                printStyle += 'img, .thumb, .thumbinner, .thumbimage { display:none !important; }\n';
// 获取复选框的值
            }
var question;
            if (this.norefs) {
for ( var i = 0; i < printOptions.questions.length; i++ ) {
                printStyle += '.references, .reference, .reflist, .ref-list { display:none !important; }\n';
question = printOptions.questions[ i ];
            }
if ( question.type === 'checkbox' && question.widget ) {
            if (this.notoc) {
printOptions[ question.returnvalue ] = question.widget.isSelected();
                printStyle += '#toc, .toc { display:none !important; }\n';
}
            }
}
            if (this.nobackground) {
// 关闭对话框后执行打印操作
                printStyle += 'body { background: white !important; }\n';
dialog.close( { action: action } ).done( function () {
            }
printOptions.changePrintCSS(); // 修改打印样式
            if (this.blacktext) {
printOptions.otherEnhancements(); // 其他增强处理
                printStyle += '* { color: black !important; }\n';
window.print(); // 触发浏览器打印
            }
window.location = window.location; // 刷新页面恢复原始状态
           
} );
            // 清理旧样式
} );
            $('style[media="print"]').remove();
}
           
// 调用父类方法处理其他操作
            // 添加新样式
return PrintDialog.super.prototype.getActionProcess.call( this, action );
            if (printStyle) {
};
                $('<style>')
 
                    .attr('media', 'print')
// 初始化窗口管理器(如果未创建)
                    .text(printStyle)
if ( !windowManager ) {
                    .appendTo('head');
windowManager = new OO.ui.WindowManager();
            }
$( 'body' ).append( windowManager.$element );
        },
}
       
// 创建打印对话框(如果未创建)
        otherEnhancements: function () {
if ( !printDialog ) {
            var $link = $('div.printfooter a');
printDialog = new PrintDialog( {
            try {
size: 'medium' // 设置对话框大小为中等
                $link.text(decodeURIComponent($link.text()));
} );
            } catch (e) {
 
                mw.log.warn('URL解码失败:', e);
windowManager.addWindows( [ printDialog ] ); // 将对话框添加到窗口管理器
            }
}
        },
windowManager.openWindow( printDialog ); // 打开对话框
       
},
        questions: [
 
            {
/**
                label: '隐藏图像',
* 修改打印样式表
                type: 'checkbox',
* - 禁用仅打印样式表
                checked: false,
* - 为屏幕样式表添加打印介质
                returnvalue: 'noimages'
* - 删除仅打印的样式规则
            },
* - 为屏幕样式规则添加打印介质
            {
* - 根据选项添加自定义打印样式
                label: '隐藏引用',
*/
                type: 'checkbox',
changePrintCSS: function () {
                checked: false,
/* 此处我们:
                returnvalue: 'norefs'
- 禁用仅用于打印的样式表
            },
- 使屏幕样式表也适用于打印介质
            {
- 删除仅用于打印的样式规则
                label: '隐藏目录',
- 使屏幕样式规则也适用于打印介质
                type: 'checkbox',
*/
                checked: false,
var printStyle = '';
                returnvalue: 'notoc'
if ( this.enhanced === false ) {
            },
var i, j, k,
            {
rule,
                label: '删除背景',
hasPrint, // 是否包含打印介质
                type: 'checkbox',
hasScreen, // 是否包含屏幕介质
                checked: false,
rules, // 样式规则集合
                returnvalue: 'nobackground'
stylesheet, // 当前样式表
            },
stylesheets = document.styleSheets; // 所有样式表
            {
 
                label: '强制文本为黑色',
for ( i = 0; i < stylesheets.length; i++ ) {
                type: 'checkbox',
stylesheet = stylesheets[ i ];
                checked: true,
if ( !stylesheet.media ) {
                returnvalue: 'blacktext'
continue;
            }
}
        ]
// 处理样式表的介质类型
    };
if ( stylesheet.media.mediaText && stylesheet.media.mediaText.indexOf( 'print' ) !== -1 ) {
   
// 如果是仅打印样式表,禁用它
    // 🌐 多语言支持扩展
if ( stylesheet.media.mediaText.indexOf( 'screen' ) === -1 ) {
    var i18n = {
stylesheet.disabled = true;
        'title': mw.message('printdialog-title').plain() || '打印此页面',
}
        'print-btn': mw.message('printdialog-print-btn').plain() || '打印',
} else if ( stylesheet.media.mediaText && stylesheet.media.mediaText.indexOf( 'screen' ) !== -1 ) {
        'cancel-btn': mw.message('printdialog-cancel-btn').plain() || '取消',
// 如果是仅屏幕样式表,添加打印介质
        'link-text': mw.message('printdialog-link-text').plain() || '可打印版本',
if ( stylesheet.media.mediaText.indexOf( 'print' ) === -1 ) {
        'options': {
try {
            'hideImages': mw.message('printdialog-opt-hide-images').plain() || '隐藏图像',
stylesheet.media.appendMedium( 'print' );
            'hideRefs': mw.message('printdialog-opt-hide-refs').plain() || '隐藏引用',
} catch ( e ) {
            'hideToc': mw.message('printdialog-opt-hide-toc').plain() || '隐藏目录',
stylesheet.media.mediaText += ',print';
            'noBackground': mw.message('printdialog-opt-no-background').plain() || '删除背景',
}
            'blackText': mw.message('printdialog-opt-black-text').plain() || '强制文本为黑色'
}
        }
}
    };
 
   
/* 现在处理单个样式规则 */
    // 🔥 快捷键支持
try {
    function registerHotkeys() {
rules = stylesheet.cssRules || stylesheet.rules;
        $(document).off('keydown.printdialog').on('keydown.printdialog', function (e) {
} catch ( e ) {
            if (!printDialog || !windowManager) return;
/* 跨域问题 */
           
mw.log.warn( '由于跨域限制,无法修正样式表' );
            // ESC - 取消
continue;
            if (e.key === 'Escape') {
}
                printDialog.executeAction('cancel');
// 兼容不同浏览器的删除规则方法
                e.preventDefault();
stylesheet.compatdelete = stylesheet.deleteRule || stylesheet.removeRule;
            }
for ( j = 0; rules && j < rules.length; j++ ) {
           
rule = rules[ j ];
            // Ctrl+Enter - 打印
hasPrint = false;
            if (e.ctrlKey && e.key === 'Enter') {
hasScreen = false;
                printDialog.executeAction('print');
// 检查媒体规则
                e.preventDefault();
if ( rule.type === CSSRule.MEDIA_RULE && rule.media ) {
            }
for ( k = 0; k < rule.media.length; k++ ) {
        });
if ( rule.media[ k ] === 'print' ) {
    }
hasPrint = true;
   
} else if ( rule.media[ k ] === 'screen' ) {
    // 应用多语言文本
hasScreen = true;
    function applyI18n() {
}
        // 更新对话框文本
}
        if (printDialog && printDialog.constructor.static) {
} else {
            printDialog.constructor.static.title = i18n.title;
continue;
            printDialog.constructor.static.actions = [
}
                {
// 删除仅打印的规则
                    action: 'print',
if ( hasPrint && !hasScreen ) {
                    label: i18n['print-btn'],
stylesheet.compatdelete( j );
                    flags: ['primary', 'progressive'],
j--; // 索引回退,因为删除了一个规则
                    icon: 'printer'
} else if ( hasScreen && !hasPrint ) {
                },
// 为仅屏幕规则添加打印介质
                {  
try {
                    action: 'cancel',  
rule.media.appendMedium( 'print' );
                    label: i18n['cancel-btn'],  
} catch ( e ) {
                    flags: 'safe',
rule.media.mediaText += ',print';
                    icon: 'close'
}
                }
}
            ];
}
        }
}
       
}
        // 更新选项标签
/* 根据选项添加自定义打印样式 */
        printOptions.questions = [
// 隐藏图片
            {
if ( this.noimages ) {
                label: i18n.options.hideImages,
printStyle += 'img, .thumb {display:none;}\n';
                type: 'checkbox',
}
                checked: false,
// 隐藏引用标记和引用列表
                returnvalue: 'noimages'
if ( this.norefs ) {
            },
printStyle += '.mw-heading:has(#References), ol.references, .reference {display:none;}\n';
            {
}
                label: i18n.options.hideRefs,
// 隐藏目录
                type: 'checkbox',
if ( this.notoc ) {
                checked: false,
printStyle += '#toc, .toc {display:none;}\n';
                returnvalue: 'norefs'
}
            },
// 移除背景
            {
if ( this.nobackground ) {
                label: i18n.options.hideToc,
printStyle += '* {background:none !important;}\n';
                type: 'checkbox',
}
                checked: false,
// 强制文本为黑色
                returnvalue: 'notoc'
if ( this.blacktext ) {
            },
printStyle += '* {color:black !important;}\n';
            {
}
                label: i18n.options.noBackground,
 
                type: 'checkbox',
// 添加自定义样式到页面
                checked: false,
if ( printStyle ) {
                returnvalue: 'nobackground'
$( 'head' ).append( '<style type="text/css" media="print">' + printStyle + '</style>' );
            },
}
            {
},
                label: i18n.options.blackText,
 
                type: 'checkbox',
/**
                checked: true,
* 其他增强处理
                returnvalue: 'blacktext'
* - 将 "retrieved from" 链接转换为可读文本
            }
*/
        ];
otherEnhancements: function () {
       
var link = $( 'div.printfooter a' );
        // 更新链接文本
link.text( decodeURI( link.text() ) );
        $('#t-print a').text(i18n['link-text']);
},
    }
 
   
/**
    // 增强的安装函数
* 打印选项问题配置
    var originalInstall = printOptions.install;
* 每个对象包含:
    printOptions.install = function() {
* - label: 复选框标签
        originalInstall.call(this);
* - type: 输入类型(checkbox)
        applyI18n();
* - checked: 默认选中状态
        registerHotkeys();
* - returnvalue: 存储结果的属性名
    };
*/
   
questions: [
    // 延迟初始化以避免冲突
{
    $(function () {
label: '隐藏界面元素',
        if (mw.config.get('wgNamespaceNumber') >= 0) {
type: 'checkbox',
            setTimeout(printOptions.install, 100);
checked: true,
        }
returnvalue: 'enhanced'
    });
},
   
{
    // 暴露到全局以便调试
label: '隐藏图片',
    window.PrintDialog = printOptions;
type: 'checkbox',
})();
checked: false,
returnvalue: 'noimages'
},
{
label: '隐藏引用',
type: 'checkbox',
checked: false,
returnvalue: 'norefs'
},
{
label: '隐藏目录',
type: 'checkbox',
checked: false,
returnvalue: 'notoc'
},
{
label: '移除背景(您的浏览器可能会覆盖此设置)',
type: 'checkbox',
checked: false,
returnvalue: 'nobackground'
},
{
label: '强制所有文本为黑色',
type: 'checkbox',
checked: true,
returnvalue: 'blacktext'
}
]
};
 
// 仅在主命名空间(ns >= 0)加载
if ( mw.config.get( 'wgNamespaceNumber' ) >= 0 ) {
$( function () {
// 这可能在 MW 安装点击处理程序之前执行
// 因此,将自己重新添加到 document.ready 队列的末尾
// 使用异步超时来实现
setTimeout( function () {
$( printOptions.install );
} );
} );
}
}() );

2025年11月23日 (日) 19:40的最新版本

/**
 * 打印选项是一个由 Derk-Jan Hartman / User:TheDJ 编写的小工具
 * 更多信息参见 [[User:TheDJ/Print_options]]
 *
 * 采用 MIT 和/或 CC-by-SA 4.0 许可协议
 *
 * 版权所有 (c) 2010-2017 Derk-Jan Hartman / User:TheDJ
 *
 * 特此免费授予任何获得本软件及相关文档文件(以下简称“软件”)副本的人,不受限制地处理本软件,
 * 包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售本软件的副本,
 * 并允许向其提供本软件的人这样做,但须符合以下条件:
 *
 * 上述版权声明和本许可声明应包含在本软件的所有副本或主要部分中。
 *
 * 本软件按“原样”提供,不提供任何形式的明示或暗示担保,
 * 包括但不限于对适销性、特定用途适用性和非侵权性的担保。
 * 在任何情况下,作者或版权持有人均不对因使用本软件而产生的任何索赔、损害或其他责任承担责任,
 * 无论是在合同诉讼、侵权诉讼还是其他诉讼中。
 */

( function () {
	'use strict';
	var windowManager; // 窗口管理器实例
	var printDialog; // 打印对话框实例

	var printOptions = {
		/**
		 * 安装打印选项功能
		 * - 找到页面上的打印链接
		 * - 重写打印链接的点击事件
		 * - 预加载必要的 OOUI 组件
		 */
		install: function () {
			var $printLink = $( '#t-print a' );
			if ( $printLink.length === 0 ) {
				return;
			}
			$printLink
				.text( '打印页面' )
				.off( 'click' )
				.get( 0 ).addEventListener( 'click', function ( e ) {
					// 加载 OOUI 核心组件、窗口组件和控件组件
					mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ] ).done( printOptions.createWindow );
					e.stopPropagation();
					e.preventDefault();
				}, true ); // 使用捕获阶段,以优先于其他点击处理程序

			// 延迟预加载 OOUI 组件
			mw.loader.load( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ] );
		},

		/**
		 * 创建打印选项对话框
		 * - 定义对话框类
		 * - 设置对话框标题和操作按钮
		 * - 添加选项复选框
		 * - 初始化窗口管理器并打开对话框
		 */
		createWindow: function () {
			// 定义打印对话框类
			function PrintDialog( config ) {
				PrintDialog.super.call( this, config );
			}
			// 继承 OO.ui.ProcessDialog
			OO.inheritClass( PrintDialog, OO.ui.ProcessDialog );

			// 对话框静态配置
			PrintDialog.static.name = 'printdialog';
			PrintDialog.static.title = '打印此页面';
			PrintDialog.static.actions = [
				{ action: 'print', label: '打印', flags: 'primary' }, // 打印按钮(主要操作)
				{ label: '取消', flags: 'safe' } // 取消按钮(安全操作)
			];

			/**
			 * 初始化对话框内容
			 * - 创建面板和字段集
			 * - 根据 questions 数组创建复选框
			 * - 将字段集添加到对话框中
			 */
			PrintDialog.prototype.initialize = function () {
				var checkbox, fieldset = [];
				PrintDialog.super.prototype.initialize.apply( this, arguments );
				// 创建面板布局
				this.panel = new OO.ui.PanelLayout( { padded: true, expanded: false } );
				// 创建字段集布局
				this.content = new OO.ui.FieldsetLayout();

				// 遍历问题数组,创建复选框
				for ( var i = 0; i < printOptions.questions.length; i++ ) {
					if ( printOptions.questions[ i ].type === 'checkbox' ) {
						checkbox = new OO.ui.CheckboxInputWidget( {
							selected: printOptions.questions[ i ].checked // 设置默认选中状态
						} );
						// 保存复选框实例到问题对象中
						printOptions.questions[ i ].widget = checkbox;
						// 创建字段布局并添加到字段集
						fieldset.push( new OO.ui.FieldLayout( checkbox, { label: printOptions.questions[ i ].label, align: 'inline' } ) );
					}
				}
				// 将字段集添加到内容布局
				this.content.addItems( fieldset );

				// 将内容添加到面板,面板添加到对话框主体
				this.panel.$element.append( this.content.$element );
				this.$body.append( this.panel.$element );
			};

			/**
			 * 处理对话框操作
			 * @param {string} action - 操作名称
			 * @returns {OO.ui.Process} 处理过程
			 */
			PrintDialog.prototype.getActionProcess = function ( action ) {
				var dialog = this;
				if ( action === 'print' ) {
					return new OO.ui.Process( function () {
						// 获取复选框的值
						var question;
						for ( var i = 0; i < printOptions.questions.length; i++ ) {
							question = printOptions.questions[ i ];
							if ( question.type === 'checkbox' && question.widget ) {
								printOptions[ question.returnvalue ] = question.widget.isSelected();
							}
						}
						// 关闭对话框后执行打印操作
						dialog.close( { action: action } ).done( function () {
							printOptions.changePrintCSS(); // 修改打印样式
							printOptions.otherEnhancements(); // 其他增强处理
							window.print(); // 触发浏览器打印
							window.location = window.location; // 刷新页面恢复原始状态
						} );
					} );
				}
				// 调用父类方法处理其他操作
				return PrintDialog.super.prototype.getActionProcess.call( this, action );
			};

			// 初始化窗口管理器(如果未创建)
			if ( !windowManager ) {
				windowManager = new OO.ui.WindowManager();
				$( 'body' ).append( windowManager.$element );
			}
			// 创建打印对话框(如果未创建)
			if ( !printDialog ) {
				printDialog = new PrintDialog( {
					size: 'medium' // 设置对话框大小为中等
				} );

				windowManager.addWindows( [ printDialog ] ); // 将对话框添加到窗口管理器
			}
			windowManager.openWindow( printDialog ); // 打开对话框
		},

		/**
		 * 修改打印样式表
		 * - 禁用仅打印样式表
		 * - 为屏幕样式表添加打印介质
		 * - 删除仅打印的样式规则
		 * - 为屏幕样式规则添加打印介质
		 * - 根据选项添加自定义打印样式
		 */
		changePrintCSS: function () {
			/* 此处我们:
				 - 禁用仅用于打印的样式表
				 - 使屏幕样式表也适用于打印介质
				 - 删除仅用于打印的样式规则
				 - 使屏幕样式规则也适用于打印介质
			*/
			var printStyle = '';
			if ( this.enhanced === false ) {
				var i, j, k,
					rule,
					hasPrint, // 是否包含打印介质
					hasScreen, // 是否包含屏幕介质
					rules, // 样式规则集合
					stylesheet, // 当前样式表
					stylesheets = document.styleSheets; // 所有样式表

				for ( i = 0; i < stylesheets.length; i++ ) {
					stylesheet = stylesheets[ i ];
					if ( !stylesheet.media ) {
						continue;
					}
					// 处理样式表的介质类型
					if ( stylesheet.media.mediaText && stylesheet.media.mediaText.indexOf( 'print' ) !== -1 ) {
						// 如果是仅打印样式表,禁用它
						if ( stylesheet.media.mediaText.indexOf( 'screen' ) === -1 ) {
							stylesheet.disabled = true;
						}
					} else if ( stylesheet.media.mediaText && stylesheet.media.mediaText.indexOf( 'screen' ) !== -1 ) {
						// 如果是仅屏幕样式表,添加打印介质
						if ( stylesheet.media.mediaText.indexOf( 'print' ) === -1 ) {
							try {
								stylesheet.media.appendMedium( 'print' );
							} catch ( e ) {
								stylesheet.media.mediaText += ',print';
							}
						}
					}

					/* 现在处理单个样式规则 */
					try {
						rules = stylesheet.cssRules || stylesheet.rules;
					} catch ( e ) {
						/* 跨域问题 */
						mw.log.warn( '由于跨域限制,无法修正样式表' );
						continue;
					}
					// 兼容不同浏览器的删除规则方法
					stylesheet.compatdelete = stylesheet.deleteRule || stylesheet.removeRule;
					for ( j = 0; rules && j < rules.length; j++ ) {
						rule = rules[ j ];
						hasPrint = false;
						hasScreen = false;
						// 检查媒体规则
						if ( rule.type === CSSRule.MEDIA_RULE && rule.media ) {
							for ( k = 0; k < rule.media.length; k++ ) {
								if ( rule.media[ k ] === 'print' ) {
									hasPrint = true;
								} else if ( rule.media[ k ] === 'screen' ) {
									hasScreen = true;
								}
							}
						} else {
							continue;
						}
						// 删除仅打印的规则
						if ( hasPrint && !hasScreen ) {
							stylesheet.compatdelete( j );
							j--; // 索引回退,因为删除了一个规则
						} else if ( hasScreen && !hasPrint ) {
							// 为仅屏幕规则添加打印介质
							try {
								rule.media.appendMedium( 'print' );
							} catch ( e ) {
								rule.media.mediaText += ',print';
							}
						}
					}
				}
			}
			/* 根据选项添加自定义打印样式 */
			// 隐藏图片
			if ( this.noimages ) {
				printStyle += 'img, .thumb {display:none;}\n';
			}
			// 隐藏引用标记和引用列表
			if ( this.norefs ) {
				printStyle += '.mw-heading:has(#References), ol.references, .reference {display:none;}\n';
			}
			// 隐藏目录
			if ( this.notoc ) {
				printStyle += '#toc, .toc {display:none;}\n';
			}
			// 移除背景
			if ( this.nobackground ) {
				printStyle += '* {background:none !important;}\n';
			}
			// 强制文本为黑色
			if ( this.blacktext ) {
				printStyle += '* {color:black !important;}\n';
			}

			// 添加自定义样式到页面
			if ( printStyle ) {
				$( 'head' ).append( '<style type="text/css" media="print">' + printStyle + '</style>' );
			}
		},

		/**
		 * 其他增强处理
		 * - 将 "retrieved from" 链接转换为可读文本
		 */
		otherEnhancements: function () {
			var link = $( 'div.printfooter a' );
			link.text( decodeURI( link.text() ) );
		},

		/**
		 * 打印选项问题配置
		 * 每个对象包含:
		 * - label: 复选框标签
		 * - type: 输入类型(checkbox)
		 * - checked: 默认选中状态
		 * - returnvalue: 存储结果的属性名
		 */
		questions: [
			{
				label: '隐藏界面元素',
				type: 'checkbox',
				checked: true,
				returnvalue: 'enhanced'
			},
			{
				label: '隐藏图片',
				type: 'checkbox',
				checked: false,
				returnvalue: 'noimages'
			},
			{
				label: '隐藏引用',
				type: 'checkbox',
				checked: false,
				returnvalue: 'norefs'
			},
			{
				label: '隐藏目录',
				type: 'checkbox',
				checked: false,
				returnvalue: 'notoc'
			},
			{
				label: '移除背景(您的浏览器可能会覆盖此设置)',
				type: 'checkbox',
				checked: false,
				returnvalue: 'nobackground'
			},
			{
				label: '强制所有文本为黑色',
				type: 'checkbox',
				checked: true,
				returnvalue: 'blacktext'
			}
		]
	};

	// 仅在主命名空间(ns >= 0)加载
	if ( mw.config.get( 'wgNamespaceNumber' ) >= 0 ) {
		$( function () {
			// 这可能在 MW 安装点击处理程序之前执行
			// 因此,将自己重新添加到 document.ready 队列的末尾
			// 使用异步超时来实现
			setTimeout( function () {
				$( printOptions.install );
			} );
		} );
	}
}() );