You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
4.1 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

function updateVisualEditorConfig() {
if (ve) {
if (ve.init && ve.init.mw && ve.init.mw.Target) {
ve.init.mw.Target.static.toolbarGroups.forEach(function (toolbarItem) {
if (toolbarItem.name === 'format') {
// 将heading1从demote中移除防止heading1出现在底部
toolbarItem.demote = toolbarItem.demote.filter(function (item) {
return item !== 'heading1';
});
}
});
} else {
console.warn('Cannot find "ve.init.Target"');
}
if (ve.ui) {
// 重命名heading1-6
for (var i = 1; i <= 6; i ++) {
var className = 'MWHeading' + i + 'FormatTool';
var msgId = 'isekai-ve-formatdropdown-format-mw-heading' + i;
if (ve.ui[className]) {
ve.ui[className].static.title = OO.ui.deferMsg(msgId);
} else {
console.warn('Cannot find "ve.ui.' + className + '"');
}
}
} else {
console.warn('Cannot find "ve.ui"');
}
} else {
console.warn('Cannot find ve lib');
}
if (mw.libs && mw.libs.ve && mw.libs.ve.targetLoader) {
var _oldRequestParsoidData = mw.libs.ve.targetLoader.requestParsoidData;
/**
* Request the page data and various metadata from the MediaWiki API (which will use
* Parsoid or RESTBase).
*
* @param {string} mode Target mode: 'visual' or 'source'
* @param {string} pageName Page name to request, in prefixed DB key form (underscores instead of spaces)
* @param {Object} [options]
* @param {boolean} [options.sessionStore] Store result in session storage (by page+mode+section) for auto-save
* @param {null|string} [options.section] Section to edit; number, 'T-'-prefixed, null or 'new' (currently just source mode)
* @param {number} [options.oldId] Old revision ID. Current if omitted.
* @param {string} [options.targetName] Optional target name for tracking
* @param {boolean} [options.modified] The page was been modified before loading (e.g. in source mode)
* @param {string} [options.wikitext] Wikitext to convert to HTML. The original document is fetched if undefined.
* @param {string} [options.editintro] Name of a page to use as edit intro message
* @param {string} [options.preload] Name of a page to use as preloaded content if pageName is empty
* @param {Array} [options.preloadparams] Parameters to substitute into preload if it's used
* @return {jQuery.Promise} Abortable promise resolved with a JSON object
*/
mw.libs.ve.targetLoader.requestParsoidData = function ( mode, pageName, options ) {
console.log('loading page data: ', pageName);
if (window.URL) {
var urlInfo = new URL(location.href);
let tplPageName = urlInfo.searchParams.get('tplPageName');
if (tplPageName) {
// 使用模板页面名替代页面名
pageName = tplPageName;
}
}
return _oldRequestParsoidData(mode, pageName, options);
}
} else {
console.log('mw.libs.ve.targetLoader not defined');
}
// 重写参数输入框
// 1. 添加下拉框类型
if (ve.ui && ve.ui.MWParameterPage) {
var _oldCreateValueInput = ve.ui.MWParameterPage.prototype.createValueInput;
ve.ui.MWParameterPage.prototype.createValueInput = function () {
var type = this.parameter.getType(),
value = this.parameter.getValue(),
valueInputConfig = this.getDefaultInputConfig();
if ( type === 'dropdown' ) {
return new ve.ui.MWParameterDropdownInputWidget( valueInputConfig, this.parameter.getDefaultValue() );
}
return _oldCreateValueInput.call(this);
}
} else {
console.log('ve.ui.MWParameterPage not defined');
}
}
updateVisualEditorConfig();