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

勤求古训,博采众方
跳转到导航 跳转到搜索
删除的内容 添加的内容
小无编辑摘要
标签:已被回退
小无编辑摘要
 
(未显示同一用户的1个中间版本)
第1行: 第1行:
/**
(function () {
* 打印选项是一个由 Derk-Jan Hartman / User:TheDJ 编写的小工具
'use strict';
* 更多信息参见 [[User:TheDJ/Print_options]]
*
var windowManager;
* 采用 MIT 和/或 CC-by-SA 4.0 许可协议
var printDialog;
*
* 版权所有 (c) 2010-2017 Derk-Jan Hartman / User:TheDJ
var printOptions = {
*
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' });

});
( function () {
e.preventDefault();
'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 () {
var $printLink = $( '#t-print a' );
PrintDialog.static.name = 'printdialog';
if ( $printLink.length === 0 ) {
PrintDialog.static.title = '打印此页面';
return;
PrintDialog.static.actions = [
}
{
$printLink
action: 'print',
label: '打印',
.text( '打印页面' )
.off( 'click' )
flags: ['primary', 'progressive'],
.get( 0 ).addEventListener( 'click', function ( e ) {
icon: 'printer'
// 加载 OOUI 核心组件、窗口组件和控件组件
},
mw.loader.using( [ 'oojs-ui-core', 'oojs-ui-widgets', 'oojs-ui-windows' ] ).done( printOptions.createWindow );
{
e.stopPropagation();
action: 'cancel',
e.preventDefault();
label: '取消',
}, true ); // 使用捕获阶段,以优先于其他点击处理程序
flags: 'safe',

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({
createWindow: function () {
selected: question.checked
// 定义打印对话框类
});
function PrintDialog( config ) {
question.widget = checkbox;
PrintDialog.super.call( this, config );
this.content.addItems([
}
new OO.ui.FieldLayout(checkbox, {
// 继承 OO.ui.ProcessDialog
label: question.label,
OO.inheritClass( PrintDialog, OO.ui.ProcessDialog );
align: 'inline'

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

/**
PrintDialog.prototype.getActionProcess = function (action) {
* 初始化对话框内容
if (action === 'print') {
* - 创建面板和字段集
return new OO.ui.Process(function () {
* - 根据 questions 数组创建复选框
// 保存选项设置
* - 将字段集添加到对话框中
printOptions.questions.forEach(function (question) {
*/
if (question.widget) {
PrintDialog.prototype.initialize = function () {
printOptions[question.returnvalue] = question.widget.isSelected();
var checkbox, fieldset = [];
}
PrintDialog.super.prototype.initialize.apply( this, arguments );
});
// 创建面板布局
this.panel = new OO.ui.PanelLayout( { padded: true, expanded: false } );
return this.close({ action: action }).then(function () {
// 创建字段集布局
printOptions.changePrintCSS();
this.content = new OO.ui.FieldsetLayout();
printOptions.otherEnhancements();

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

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]);
* 处理对话框操作
* @param {string} action - 操作名称
windowManager.openWindow(printDialog);
* @returns {OO.ui.Process} 处理过程
},
*/
PrintDialog.prototype.getActionProcess = function ( action ) {
changePrintCSS: function () {
var printStyle = '';
var dialog = this;
if ( action === 'print' ) {
return new OO.ui.Process( function () {
if (this.noimages) {
// 获取复选框的值
printStyle += 'img, .thumb, .thumbinner, .thumbimage { display:none !important; }\n';
var question;
}
for ( var i = 0; i < printOptions.questions.length; i++ ) {
if (this.norefs) {
question = printOptions.questions[ i ];
printStyle += '.references, .reference, .reflist, .ref-list { display:none !important; }\n';
if ( question.type === 'checkbox' && question.widget ) {
}
printOptions[ question.returnvalue ] = question.widget.isSelected();
if (this.notoc) {
}
printStyle += '#toc, .toc { display:none !important; }\n';
}
}
// 关闭对话框后执行打印操作
if (this.nobackground) {
dialog.close( { action: action } ).done( function () {
printStyle += 'body { background: white !important; }\n';
printOptions.changePrintCSS(); // 修改打印样式
}
printOptions.otherEnhancements(); // 其他增强处理
if (this.blacktext) {
window.print(); // 触发浏览器打印
printStyle += '* { color: black !important; }\n';
window.location = window.location; // 刷新页面恢复原始状态
}
} );
} );
// 清理旧样式
}
$('style[media="print"]').remove();
// 调用父类方法处理其他操作
return PrintDialog.super.prototype.getActionProcess.call( this, action );
// 添加新样式
};
if (printStyle) {

$('<style>')
// 初始化窗口管理器(如果未创建)
.attr('media', 'print')
if ( !windowManager ) {
.text(printStyle)
windowManager = new OO.ui.WindowManager();
.appendTo('head');
$( 'body' ).append( windowManager.$element );
}
}
},
// 创建打印对话框(如果未创建)
if ( !printDialog ) {
otherEnhancements: function () {
printDialog = new PrintDialog( {
var $link = $('div.printfooter a');
size: 'medium' // 设置对话框大小为中等
try {
} );
$link.text(decodeURIComponent($link.text()));

} catch (e) {
windowManager.addWindows( [ printDialog ] ); // 将对话框添加到窗口管理器
mw.log.warn('URL解码失败:', e);
}
}
windowManager.openWindow( printDialog ); // 打开对话框
},
},

questions: [
/**
{
* 修改打印样式表
label: '隐藏图像',
* - 禁用仅打印样式表
type: 'checkbox',
* - 为屏幕样式表添加打印介质
checked: false,
* - 删除仅打印的样式规则
returnvalue: 'noimages'
* - 为屏幕样式规则添加打印介质
},
* - 根据选项添加自定义打印样式
{
*/
label: '隐藏引用',
changePrintCSS: function () {
type: 'checkbox',
/* 此处我们:
checked: false,
- 禁用仅用于打印的样式表
returnvalue: 'norefs'
- 使屏幕样式表也适用于打印介质
},
- 删除仅用于打印的样式规则
{
- 使屏幕样式规则也适用于打印介质
label: '隐藏目录',
*/
type: 'checkbox',
var printStyle = '';
checked: false,
if ( this.enhanced === false ) {
returnvalue: 'notoc'
var i, j, k,
},
rule,
{
hasPrint, // 是否包含打印介质
label: '删除背景',
hasScreen, // 是否包含屏幕介质
type: 'checkbox',
rules, // 样式规则集合
checked: false,
stylesheet, // 当前样式表
returnvalue: 'nobackground'
stylesheets = document.styleSheets; // 所有样式表
},

{
for ( i = 0; i < stylesheets.length; i++ ) {
label: '强制文本为黑色',
stylesheet = stylesheets[ i ];
type: 'checkbox',
if ( !stylesheet.media ) {
checked: true,
continue;
returnvalue: 'blacktext'
}
}
// 处理样式表的介质类型
]
if ( stylesheet.media.mediaText && stylesheet.media.mediaText.indexOf( 'print' ) !== -1 ) {
};
// 如果是仅打印样式表,禁用它
if ( stylesheet.media.mediaText.indexOf( 'screen' ) === -1 ) {
// 🌐 多语言支持扩展
stylesheet.disabled = true;
var i18n = {
}
'title': mw.message('printdialog-title').plain() || '打印此页面',
} else if ( stylesheet.media.mediaText && stylesheet.media.mediaText.indexOf( 'screen' ) !== -1 ) {
'print-btn': mw.message('printdialog-print-btn').plain() || '打印',
// 如果是仅屏幕样式表,添加打印介质
'cancel-btn': mw.message('printdialog-cancel-btn').plain() || '取消',
if ( stylesheet.media.mediaText.indexOf( 'print' ) === -1 ) {
'link-text': mw.message('printdialog-link-text').plain() || '可打印版本',
try {
'options': {
stylesheet.media.appendMedium( 'print' );
'hideImages': mw.message('printdialog-opt-hide-images').plain() || '隐藏图像',
} catch ( e ) {
'hideRefs': mw.message('printdialog-opt-hide-refs').plain() || '隐藏引用',
stylesheet.media.mediaText += ',print';
'hideToc': mw.message('printdialog-opt-hide-toc').plain() || '隐藏目录',
}
'noBackground': mw.message('printdialog-opt-no-background').plain() || '删除背景',
}
'blackText': mw.message('printdialog-opt-black-text').plain() || '强制文本为黑色'
}
}

};
/* 现在处理单个样式规则 */
try {
// 🔥 快捷键支持
rules = stylesheet.cssRules || stylesheet.rules;
function registerHotkeys() {
} catch ( e ) {
$(document).off('keydown.printdialog').on('keydown.printdialog', function (e) {
/* 跨域问题 */
if (!printDialog || !windowManager) return;
mw.log.warn( '由于跨域限制,无法修正样式表' );
continue;
// ESC - 取消
}
if (e.key === 'Escape') {
// 兼容不同浏览器的删除规则方法
printDialog.executeAction('cancel');
stylesheet.compatdelete = stylesheet.deleteRule || stylesheet.removeRule;
e.preventDefault();
}
for ( j = 0; rules && j < rules.length; j++ ) {
rule = rules[ j ];
hasPrint = false;
// Ctrl+Enter - 打印
hasScreen = false;
if (e.ctrlKey && e.key === 'Enter') {
// 检查媒体规则
printDialog.executeAction('print');
if ( rule.type === CSSRule.MEDIA_RULE && rule.media ) {
e.preventDefault();
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() {
}
// 更新对话框文本
} else {
if (printDialog && printDialog.constructor.static) {
continue;
printDialog.constructor.static.title = i18n.title;
}
printDialog.constructor.static.actions = [
// 删除仅打印的规则
{
if ( hasPrint && !hasScreen ) {
action: 'print',
stylesheet.compatdelete( j );
label: i18n['print-btn'],
j--; // 索引回退,因为删除了一个规则
flags: ['primary', 'progressive'],
} else if ( hasScreen && !hasPrint ) {
icon: 'printer'
// 为仅屏幕规则添加打印介质
},
try {
{
rule.media.appendMedium( 'print' );
action: 'cancel',
} catch ( e ) {
label: i18n['cancel-btn'],
rule.media.mediaText += ',print';
flags: 'safe',
}
icon: 'close'
}
}
}
];
}
}
}
/* 根据选项添加自定义打印样式 */
// 更新选项标签
// 隐藏图片
printOptions.questions = [
if ( this.noimages ) {
{
printStyle += 'img, .thumb {display:none;}\n';
label: i18n.options.hideImages,
}
type: 'checkbox',
// 隐藏引用标记和引用列表
checked: false,
if ( this.norefs ) {
returnvalue: 'noimages'
printStyle += '.mw-heading:has(#References), ol.references, .reference {display:none;}\n';
},
}
{
// 隐藏目录
label: i18n.options.hideRefs,
if ( this.notoc ) {
type: 'checkbox',
printStyle += '#toc, .toc {display:none;}\n';
checked: false,
}
returnvalue: 'norefs'
// 移除背景
},
if ( this.nobackground ) {
{
printStyle += '* {background:none !important;}\n';
label: i18n.options.hideToc,
}
type: 'checkbox',
// 强制文本为黑色
checked: false,
if ( this.blacktext ) {
returnvalue: 'notoc'
printStyle += '* {color:black !important;}\n';
},
}
{

label: i18n.options.noBackground,
// 添加自定义样式到页面
type: 'checkbox',
if ( printStyle ) {
checked: false,
$( 'head' ).append( '<style type="text/css" media="print">' + printStyle + '</style>' );
returnvalue: 'nobackground'
}
},
},
{

label: i18n.options.blackText,
/**
type: 'checkbox',
* 其他增强处理
checked: true,
* - 将 "retrieved from" 链接转换为可读文本
returnvalue: 'blacktext'
*/
}
otherEnhancements: function () {
];
var link = $( 'div.printfooter a' );
link.text( decodeURI( link.text() ) );
// 更新链接文本
},
$('#t-print a').text(i18n['link-text']);

}
/**
* 打印选项问题配置
// 增强的安装函数
* 每个对象包含:
var originalInstall = printOptions.install;
* - label: 复选框标签
printOptions.install = function() {
* - type: 输入类型(checkbox)
originalInstall.call(this);
* - checked: 默认选中状态
applyI18n();
* - returnvalue: 存储结果的属性名
registerHotkeys();
*/
};
questions: [
{
// 延迟初始化以避免冲突
label: '隐藏界面元素',
$(function () {
type: 'checkbox',
if (mw.config.get('wgNamespaceNumber') >= 0) {
checked: true,
setTimeout(printOptions.install, 100);
returnvalue: 'enhanced'
}
},
});
{
label: '隐藏图片',
// 暴露到全局以便调试
type: 'checkbox',
window.PrintDialog = printOptions;
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 );
			} );
		} );
	}
}() );