MediaWiki:Gadget-defaultsummaries.js:修订间差异
跳转到导航
跳转到搜索
删除的内容 添加的内容
小无编辑摘要 |
小 // Edit via Wikiplus |
||
| 第2行: | 第2行: | ||
'use strict'; |
'use strict'; |
||
// 摘要选项(保持你喜欢的第二套内容) |
|||
const SUMMARY_OPTIONS = [ |
const SUMMARY_OPTIONS = [ |
||
'新条目', |
'新条目', |
||
| 第17行: | 第16行: | ||
]; |
]; |
||
// |
// 样式调整:移除圆角,贴近MediaWiki原生风格(方角、浅灰背景、无阴影) |
||
const STYLES = { |
const STYLES = { |
||
dropdownContainer: { |
dropdownContainer: { |
||
width: '100%', |
width: '100%', |
||
margin: ' |
margin: '6px 0', // 原生控件常见间距 |
||
fontSize: '0. |
fontSize: '0.9em' // 匹配原生文字大小 |
||
}, |
}, |
||
// 下拉菜单本身的样式(通过JS动态注入CSS) |
|||
dropdown: ` |
dropdown: ` |
||
.summary-helper-dropdown .oo-ui-dropdownWidget-handle { |
.summary-helper-dropdown .oo-ui-dropdownWidget-handle { |
||
border: 1px solid # |
border: 1px solid #aaa; /* 原生控件边框色 */ |
||
padding: 3px 8px; /* 紧凑内边距,贴近原生 */ |
|||
background: #f8f9fa; /* 原生浅灰背景 */ |
|||
transition: border-color 0.2s; /* 仅保留边框过渡 */ |
|||
transition: all 0.2s; |
|||
} |
} |
||
.summary-helper-dropdown .oo-ui-dropdownWidget-handle:hover { |
.summary-helper-dropdown .oo-ui-dropdownWidget-handle:hover { |
||
border-color: # |
border-color: #777; /* hover时边框加深,原生常见效果 */ |
||
background: #f0f0f0; |
background: #f0f0f0; |
||
box-shadow: 0 1px 3px rgba(0,0,0,0.1); |
|||
} |
} |
||
.summary-helper-dropdown .oo-ui-menuOptionWidget { |
.summary-helper-dropdown .oo-ui-menuOptionWidget { |
||
padding: |
padding: 4px 10px; /* 原生选项间距 */ |
||
color: #000; /* 原生文字色 */ |
|||
} |
} |
||
.summary-helper-dropdown .oo-ui-menuOptionWidget:hover { |
.summary-helper-dropdown .oo-ui-menuOptionWidget:hover { |
||
background: # |
background: #e5f1ff; /* 维基原生hover浅蓝 */ |
||
color: #0645ad; /* 维基 |
color: #0645ad; /* 维基链接蓝,保持一致性 */ |
||
} |
} |
||
.summary-helper-dropdown .oo-ui-menuOptionWidget.oo-ui-selected { |
.summary-helper-dropdown .oo-ui-menuOptionWidget.oo-ui-selected { |
||
background: # |
background: #c8e4fd; /* 选中时稍深的蓝色,贴近原生选中态 */ |
||
font-weight: bold; |
|||
} |
} |
||
` |
` |
||
| 第61行: | 第57行: | ||
init() { |
init() { |
||
if (this.initialized) return; |
if (this.initialized) return; |
||
// 新增:注入美化样式 |
|||
this.injectStyles(); |
this.injectStyles(); |
||
this.setupVisualEditorHook(); |
this.setupVisualEditorHook(); |
||
| 第68行: | 第63行: | ||
} |
} |
||
// 新增:动态注入CSS样式(避免修改全局CSS) |
|||
injectStyles() { |
injectStyles() { |
||
const style = document.createElement('style'); |
const style = document.createElement('style'); |
||
| 第75行: | 第69行: | ||
} |
} |
||
// 适配可视化编辑器(VE) |
|||
setupVisualEditorHook() { |
setupVisualEditorHook() { |
||
mw.hook('ve.saveDialog.stateChanged').add(() => { |
mw.hook('ve.saveDialog.stateChanged').add(() => { |
||
| 第91行: | 第84行: | ||
} |
} |
||
// 适配传统编辑器(WikiEditor) |
|||
setupWikiEditor() { |
setupWikiEditor() { |
||
Promise.all([ |
Promise.all([ |
||
| 第106行: | 第98行: | ||
} |
} |
||
// 创建下拉菜单(增加自定义类名用于美化) |
|||
createDropdown() { |
createDropdown() { |
||
const dropdown = new OO.ui.DropdownWidget({ |
const dropdown = new OO.ui.DropdownWidget({ |
||
label: '快捷摘要 |
label: '快捷摘要', // 更贴近原生控件的标题 |
||
classes: ['summary-helper-dropdown'] |
classes: ['summary-helper-dropdown'] |
||
}); |
}); |
||
| 第125行: | 第116行: | ||
} |
} |
||
// |
// 保留轻量反馈,避免突兀 |
||
handleSummarySelect(option) { |
handleSummarySelect(option) { |
||
const originalValue = this.summaryBox.val(); |
const originalValue = this.summaryBox.val(); |
||
| 第134行: | 第125行: | ||
this.summaryBox.val(newSummary).trigger('change'); |
this.summaryBox.val(newSummary).trigger('change'); |
||
// |
// 弱化反馈:仅轻微高亮边框,更贴近原生 |
||
this.summaryBox.css(' |
this.summaryBox.css('border-color', '#72b3ff'); |
||
setTimeout(() => { |
setTimeout(() => { |
||
this.summaryBox.css(' |
this.summaryBox.css('border-color', ''); |
||
}, |
}, 400); |
||
} |
} |
||
} |
} |
||
2025年11月10日 (一) 17:47的版本
(() => {
'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());
})();