MediaWiki:Gadget-defaultsummaries.js:修订间差异
跳转到导航
跳转到搜索
删除的内容 添加的内容
小无编辑摘要 |
小无编辑摘要 |
||
| (未显示同一用户的5个中间版本) | |||
| 第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 |
const SUMMARY_OPTIONS = [ |
||
'新条目', |
|||
'修饰语句', |
|||
'修正笔误', |
|||
'内容扩充', |
|||
'排版(调整格式)', |
|||
'图片(添加/修改/删除)', // 补充第一段的高频选项 |
|||
| ⚫ | |||
'模板(添加/调整)', // 补充第一段的高频选项 |
|||
| ⚫ | |||
'来源(增加/调整参考资料)', |
|||
| ⚫ | |||
'内部链接(增加/调整)', |
|||
'分类(增加/调整)', |
|||
'消歧义', |
|||
'维基化(适配维基格式)', |
|||
'维护清理', |
|||
'回退(撤销错误编辑)' // 补充第一段的高频选项 |
|||
'添加/删除外部链接', |
|||
| ⚫ | |||
'删除无源内容' |
|||
| ⚫ | |||
nonArticle: [ |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
'WikiProject 标记', |
|||
'WikiProject 评估' |
|||
| ⚫ | |||
| ⚫ | |||
// 样式调整:移除圆角,贴近MediaWiki原生风格(方角、浅灰背景、无阴影) |
|||
const STYLES = { |
const STYLES = { |
||
dropdownContainer: { |
dropdownContainer: { |
||
width: ' |
width: '100%', |
||
margin: '6px 0', // 原生控件常见间距 |
|||
fontSize: '0.9em' // 匹配原生文字大小 |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
.summary-helper-dropdown .oo-ui-dropdownWidget-handle { |
|||
border: 1px solid #aaa; /* 原生控件边框色 */ |
|||
padding: 3px 8px; /* 紧凑内边距,贴近原生 */ |
|||
background: #f8f9fa; /* 原生浅灰背景 */ |
|||
transition: border-color 0.2s; /* 仅保留边框过渡 */ |
|||
| ⚫ | |||
.summary-helper-dropdown .oo-ui-dropdownWidget-handle:hover { |
|||
border-color: #777; /* hover时边框加深,原生常见效果 */ |
|||
| ⚫ | |||
| ⚫ | |||
.summary-helper-dropdown .oo-ui-menuOptionWidget { |
|||
padding: 4px 10px; /* 原生选项间距 */ |
|||
color: #000; /* 原生文字色 */ |
|||
| ⚫ | |||
.summary-helper-dropdown .oo-ui-menuOptionWidget:hover { |
|||
background: #e5f1ff; /* 维基原生hover浅蓝 */ |
|||
color: #0645ad; /* 维基链接蓝,保持一致性 */ |
|||
| ⚫ | |||
.summary-helper-dropdown .oo-ui-menuOptionWidget.oo-ui-selected { |
|||
background: #c8e4fd; /* 选中时稍深的蓝色,贴近原生选中态 */ |
|||
| ⚫ | |||
| ⚫ | |||
}; |
}; |
||
| 第62行: | 第60行: | ||
init() { |
init() { |
||
if (this.initialized) return; |
if (this.initialized) return; |
||
this.injectStyles(); |
|||
this.setupVisualEditorHook(); |
this.setupVisualEditorHook(); |
||
this.setupWikiEditor(); |
this.setupWikiEditor(); |
||
this.initialized = true; |
this.initialized = true; |
||
| ⚫ | |||
| ⚫ | |||
const style = document.createElement('style'); |
|||
style.textContent = STYLES.dropdown; |
|||
document.head.appendChild(style); |
|||
} |
} |
||
| 第78行: | 第83行: | ||
$('body').addClass('has-summary-dropdowns'); |
$('body').addClass('has-summary-dropdowns'); |
||
$saveOptions.before(this. |
$saveOptions.before(this.createDropdown()); |
||
}); |
}); |
||
} |
} |
||
| 第91行: | 第96行: | ||
$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: '快捷摘要', // 更贴近原生控件的标题 |
||
classes: ['summary-helper-dropdown'] |
|||
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); |
|||
if (isArticle || isDraft) { |
|||
| ⚫ | |||
| ⚫ | |||
this.addOptionsToDropdown(dropdown, SUMMARY_LISTS.nonArticle); |
|||
if (isTalkPage) { |
|||
this.addOptionsToDropdown(dropdown, SUMMARY_LISTS.talkPage); |
|||
| ⚫ | |||
} |
|||
return dropdown.$element |
return dropdown.$element; |
||
} |
} |
||
| 第133行: | 第119行: | ||
} |
} |
||
// 保留轻量反馈,避免突兀 |
|||
handleSummarySelect(option) { |
handleSummarySelect(option) { |
||
const originalValue = this.summaryBox.val(); |
const originalValue = this.summaryBox.val(); |
||
| 第140行: | 第127行: | ||
this.summaryBox.val(newSummary).trigger('change'); |
this.summaryBox.val(newSummary).trigger('change'); |
||
| ⚫ | |||
// 弱化反馈:仅轻微高亮边框,更贴近原生 |
|||
this.summaryBox.css('border-color', '#72b3ff'); |
|||
setTimeout(() => { |
|||
this.summaryBox.css('border-color', ''); |
|||
| ⚫ | |||
} |
} |
||
} |
} |
||
// Initialize on document ready |
|||
$(() => new SummaryHelper()); |
$(() => new SummaryHelper()); |
||
})(); |
})(); |
||
2025年11月19日 (三) 23:36的最新版本
(() => {
'use strict';
const SUMMARY_OPTIONS = [
'新条目',
'修饰语句',
'修正笔误',
'内容扩充',
'排版(调整格式)',
'图片(添加/修改/删除)', // 补充第一段的高频选项
'模板(添加/调整)', // 补充第一段的高频选项
'来源(增加/调整参考资料)',
'内部链接(增加/调整)',
'分类(增加/调整)',
'消歧义',
'维基化(适配维基格式)',
'维护清理',
'回退(撤销错误编辑)' // 补充第一段的高频选项
];
// 样式调整:移除圆角,贴近MediaWiki原生风格(方角、浅灰背景、无阴影)
const STYLES = {
dropdownContainer: {
width: '100%',
margin: '6px 0', // 原生控件常见间距
fontSize: '0.9em' // 匹配原生文字大小
},
dropdown: `
.summary-helper-dropdown .oo-ui-dropdownWidget-handle {
border: 1px solid #aaa; /* 原生控件边框色 */
padding: 3px 8px; /* 紧凑内边距,贴近原生 */
background: #f8f9fa; /* 原生浅灰背景 */
transition: border-color 0.2s; /* 仅保留边框过渡 */
}
.summary-helper-dropdown .oo-ui-dropdownWidget-handle:hover {
border-color: #777; /* hover时边框加深,原生常见效果 */
background: #f0f0f0;
}
.summary-helper-dropdown .oo-ui-menuOptionWidget {
padding: 4px 10px; /* 原生选项间距 */
color: #000; /* 原生文字色 */
}
.summary-helper-dropdown .oo-ui-menuOptionWidget:hover {
background: #e5f1ff; /* 维基原生hover浅蓝 */
color: #0645ad; /* 维基链接蓝,保持一致性 */
}
.summary-helper-dropdown .oo-ui-menuOptionWidget.oo-ui-selected {
background: #c8e4fd; /* 选中时稍深的蓝色,贴近原生选中态 */
}
`
};
class SummaryHelper {
constructor() {
this.summaryBox = $('#wpSummary');
this.initialized = false;
this.init();
}
init() {
if (this.initialized) return;
this.injectStyles();
this.setupVisualEditorHook();
this.setupWikiEditor();
this.initialized = true;
}
injectStyles() {
const style = document.createElement('style');
style.textContent = STYLES.dropdown;
document.head.appendChild(style);
}
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());
});
}
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: '快捷摘要', // 更贴近原生控件的标题
classes: ['summary-helper-dropdown']
});
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');
// 弱化反馈:仅轻微高亮边框,更贴近原生
this.summaryBox.css('border-color', '#72b3ff');
setTimeout(() => {
this.summaryBox.css('border-color', '');
}, 400);
}
}
$(() => new SummaryHelper());
})();