MediaWiki:Gadget-defaultsummaries.js:修订间差异
跳转到导航
跳转到搜索
删除的内容 添加的内容
小无编辑摘要 |
小无编辑摘要 |
||
| 第1行: | 第1行: | ||
/* _____________________________________________________________________________ |
|||
* | | |
|||
* | === WARNING: GLOBAL GADGET FILE === | |
|||
* | Changes to this page affect many users. | |
|||
* | Please discuss changes on the talk page or on [[WT:Gadget]] before editing. | |
|||
* |_____________________________________________________________________________| |
|||
* |
|||
* Imported as of 09/06/2011 from [[User:ErrantX/defaultsummaries.js]] |
|||
* Edited version from [[User:MC10/defaultsummaries.js]] |
|||
* Implements default edit summary dropdown boxes |
|||
*/ |
|||
/* global mw, ve */ |
|||
/* eslint-disable no-jquery/no-global-selector */ |
|||
(() => { |
(() => { |
||
'use strict'; |
'use strict'; |
||
// 只保留你喜欢的第二套选项,想加/删直接改这个数组就行 |
|||
const SUMMARY_LISTS = { |
|||
const SUMMARY_OPTIONS = [ |
|||
'新条目', |
|||
'修饰语句', |
|||
'修正笔误', |
|||
'内容扩充', |
|||
'排版(调整格式)', |
|||
'来源(增加/调整参考资料)', |
|||
| ⚫ | |||
'内部链接(增加/调整)', |
|||
article: [ |
|||
'分类(增加/调整)', |
|||
'消歧义', |
|||
'维基化(适配维基格式)', |
|||
'维护清理' |
|||
| ⚫ | |||
'添加/删除类别', |
|||
'添加/删除外部链接', |
|||
'删除无源内容' |
|||
], |
|||
nonArticle: [ |
|||
'回复', |
|||
'注释', |
|||
'建议' |
|||
], |
|||
talkPage: [ |
|||
'WikiProject 标记', |
|||
'WikiProject 评估' |
|||
] |
|||
}; |
|||
const STYLES = { |
const STYLES = { |
||
dropdownContainer: { |
dropdownContainer: { |
||
width: ' |
width: '100%', |
||
paddingBottom: '1em' |
paddingBottom: '1em' |
||
} |
} |
||
| 第67行: | 第38行: | ||
} |
} |
||
// 适配可视化编辑器(VE) |
|||
setupVisualEditorHook() { |
setupVisualEditorHook() { |
||
mw.hook('ve.saveDialog.stateChanged').add(() => { |
mw.hook('ve.saveDialog.stateChanged').add(() => { |
||
| 第78行: | 第50行: | ||
$('body').addClass('has-summary-dropdowns'); |
$('body').addClass('has-summary-dropdowns'); |
||
$saveOptions.before(this. |
$saveOptions.before(this.createDropdown()); |
||
}); |
}); |
||
} |
} |
||
// 适配传统编辑器(WikiEditor) |
|||
setupWikiEditor() { |
setupWikiEditor() { |
||
Promise.all([ |
Promise.all([ |
||
| 第91行: | 第64行: | ||
$editCheckboxes.before( |
$editCheckboxes.before( |
||
this. |
this.createDropdown().css(STYLES.dropdownContainer) |
||
); |
); |
||
}); |
}); |
||
} |
} |
||
// 只创建一个下拉菜单(包含所有第二套选项) |
|||
createDropdown() { |
|||
const namespace = mw.config.get('wgNamespaceNumber'); |
|||
const isArticle = namespace === 0; |
|||
const isDraft = namespace === 118; |
|||
const isTalkPage = namespace % 2 !== 0 && namespace !== 3; |
|||
const dropdown = new OO.ui.DropdownWidget({ |
const dropdown = new OO.ui.DropdownWidget({ |
||
label: ' |
label: '快捷摘要' // 下拉菜单标题,可改成自己想显示的文字 |
||
}); |
|||
const minorDropdown = new OO.ui.DropdownWidget({ |
|||
label: '常见小编辑摘要' |
|||
}); |
}); |
||
// 点击选项填充到摘要框 |
|||
dropdown.menu.on('select', this.handleSummarySelect.bind(this)); |
dropdown.menu.on('select', this.handleSummarySelect.bind(this)); |
||
minorDropdown.menu.on('select', this.handleSummarySelect.bind(this)); |
|||
this.addOptionsToDropdown(minorDropdown, SUMMARY_LISTS.minor); |
|||
// 给下拉菜单添加你喜欢的选项 |
|||
this.addOptionsToDropdown(dropdown, SUMMARY_OPTIONS); |
|||
} else { |
|||
this.addOptionsToDropdown(dropdown, SUMMARY_LISTS.nonArticle); |
|||
if (isTalkPage) { |
|||
this.addOptionsToDropdown(dropdown, SUMMARY_LISTS.talkPage); |
|||
} |
|||
} |
|||
return dropdown.$element |
return dropdown.$element; |
||
} |
} |
||
// 给下拉菜单添加选项的工具方法 |
|||
addOptionsToDropdown(dropdown, optionTexts) { |
addOptionsToDropdown(dropdown, optionTexts) { |
||
dropdown.menu.addItems( |
dropdown.menu.addItems( |
||
| 第133行: | 第91行: | ||
} |
} |
||
// 处理选项点击:填充到摘要框,支持拼接已有内容 |
|||
handleSummarySelect(option) { |
handleSummarySelect(option) { |
||
const originalValue = this.summaryBox.val(); |
const originalValue = this.summaryBox.val(); |
||
// 已有内容则加空格拼接,没有就直接填充 |
|||
const newSummary = originalValue.length && !originalValue.endsWith(' ') |
const newSummary = originalValue.length && !originalValue.endsWith(' ') |
||
? `${originalValue} ${option.getLabel()}` |
? `${originalValue} ${option.getLabel()}` |
||
| 第143行: | 第103行: | ||
} |
} |
||
// 页面加载完成后初始化 |
|||
// Initialize on document ready |
|||
$(() => new SummaryHelper()); |
$(() => new SummaryHelper()); |
||
})(); |
})(); |
||
2025年11月10日 (一) 17:27的版本
(() => {
'use strict';
// 只保留你喜欢的第二套选项,想加/删直接改这个数组就行
const SUMMARY_OPTIONS = [
'新条目',
'修饰语句',
'修正笔误',
'内容扩充',
'排版(调整格式)',
'来源(增加/调整参考资料)',
'内部链接(增加/调整)',
'分类(增加/调整)',
'消歧义',
'维基化(适配维基格式)',
'维护清理'
];
const STYLES = {
dropdownContainer: {
width: '100%',
paddingBottom: '1em'
}
};
class SummaryHelper {
constructor() {
this.summaryBox = $('#wpSummary');
this.initialized = false;
this.init();
}
init() {
if (this.initialized) return;
this.setupVisualEditorHook();
this.setupWikiEditor();
this.initialized = true;
}
// 适配可视化编辑器(VE)
setupVisualEditorHook() {
mw.hook('ve.saveDialog.stateChanged').add(() => {
if ($('body').hasClass('has-summary-dropdowns')) return;
const target = ve.init.target;
const $saveOptions = target.saveDialog.$saveOptions;
this.summaryBox = target.saveDialog.editSummaryInput.$input;
if (!$saveOptions.length) return;
$('body').addClass('has-summary-dropdowns');
$saveOptions.before(this.createDropdown());
});
}
// 适配传统编辑器(WikiEditor)
setupWikiEditor() {
Promise.all([
mw.loader.using('oojs-ui-core'),
$.ready
]).then(() => {
const $editCheckboxes = $('.editCheckboxes');
if (!$editCheckboxes.length) return;
$editCheckboxes.before(
this.createDropdown().css(STYLES.dropdownContainer)
);
});
}
// 只创建一个下拉菜单(包含所有第二套选项)
createDropdown() {
const dropdown = new OO.ui.DropdownWidget({
label: '快捷摘要' // 下拉菜单标题,可改成自己想显示的文字
});
// 点击选项填充到摘要框
dropdown.menu.on('select', this.handleSummarySelect.bind(this));
// 给下拉菜单添加你喜欢的选项
this.addOptionsToDropdown(dropdown, SUMMARY_OPTIONS);
return dropdown.$element;
}
// 给下拉菜单添加选项的工具方法
addOptionsToDropdown(dropdown, optionTexts) {
dropdown.menu.addItems(
optionTexts.map(text => new OO.ui.MenuOptionWidget({ label: text }))
);
}
// 处理选项点击:填充到摘要框,支持拼接已有内容
handleSummarySelect(option) {
const originalValue = this.summaryBox.val();
// 已有内容则加空格拼接,没有就直接填充
const newSummary = originalValue.length && !originalValue.endsWith(' ')
? `${originalValue} ${option.getLabel()}`
: originalValue + option.getLabel();
this.summaryBox.val(newSummary).trigger('change');
}
}
// 页面加载完成后初始化
$(() => new SummaryHelper());
})();