From fa0a99203c6eca132c26372cce6276ddbdf2855a Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Sat, 9 Sep 2023 16:22:04 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E5=85=A5=E6=9B=B4?= =?UTF-8?q?=E6=94=B9VisualEditor=E7=9A=84=E6=A0=87=E9=A2=98=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension.json | 22 ++++++++++++++++++---- i18n/en.json | 9 ++++++++- i18n/zh-hans.json | 9 ++++++++- i18n/zh-hant.json | 9 ++++++++- modules/ve.ext.isekai.misc.js | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 modules/ve.ext.isekai.misc.js diff --git a/extension.json b/extension.json index 226cba5..52aec8b 100644 --- a/extension.json +++ b/extension.json @@ -121,9 +121,9 @@ "mobile" ] }, - "ext.isekai.ve": { + "ve.ext.isekai.misc": { "scripts": [ - "ext.isekai.ve.js" + "ve.ext.isekai.misc.js" ], "targets": [ "desktop", @@ -131,8 +131,15 @@ ], "dependencies": [ "ext.visualEditor.mwcore", - "ext.visualEditor.mwmeta", - "ext.visualEditor.desktopArticleTarget" + "ext.visualEditor.mwextensions" + ], + "messages": [ + "isekai-ve-formatdropdown-format-mw-heading1", + "isekai-ve-formatdropdown-format-mw-heading2", + "isekai-ve-formatdropdown-format-mw-heading3", + "isekai-ve-formatdropdown-format-mw-heading4", + "isekai-ve-formatdropdown-format-mw-heading5", + "isekai-ve-formatdropdown-format-mw-heading6" ] }, "ext.isekai.function-btn": { @@ -153,6 +160,13 @@ ] } }, + "attributes": { + "VisualEditor": { + "PluginModules": [ + "ve.ext.isekai.misc" + ] + } + }, "ResourceFileModulePaths": { "localBasePath": "modules", "remoteExtPath": "IsekaiMisc/modules" diff --git a/i18n/en.json b/i18n/en.json index f05ce81..5124df3 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -38,5 +38,12 @@ "isekai-function-btn-exit-fullscreen": "Exit full screen", "group-activated-editor": "Editor", - "group-activated-editor-member": "Editor" + "group-activated-editor-member": "Editor", + + "isekai-ve-formatdropdown-format-mw-heading1": "Heading", + "isekai-ve-formatdropdown-format-mw-heading2": "Sub-heading", + "isekai-ve-formatdropdown-format-mw-heading3": "Sub-heading 3", + "isekai-ve-formatdropdown-format-mw-heading4": "Sub-heading 4", + "isekai-ve-formatdropdown-format-mw-heading5": "Sub-heading 5", + "isekai-ve-formatdropdown-format-mw-heading6": "Sub-heading 6" } \ No newline at end of file diff --git a/i18n/zh-hans.json b/i18n/zh-hans.json index 68bb190..67be991 100644 --- a/i18n/zh-hans.json +++ b/i18n/zh-hans.json @@ -38,5 +38,12 @@ "isekai-function-btn-exit-fullscreen": "退出全屏", "group-activated-editor": "作者", - "group-activated-editor-member": "作者" + "group-activated-editor-member": "作者", + + "isekai-ve-formatdropdown-format-mw-heading1": "标题", + "isekai-ve-formatdropdown-format-mw-heading2": "子标题", + "isekai-ve-formatdropdown-format-mw-heading3": "三级标题", + "isekai-ve-formatdropdown-format-mw-heading4": "四级标题", + "isekai-ve-formatdropdown-format-mw-heading5": "五级标题", + "isekai-ve-formatdropdown-format-mw-heading6": "六级标题" } \ No newline at end of file diff --git a/i18n/zh-hant.json b/i18n/zh-hant.json index 5b8c338..5d4169f 100644 --- a/i18n/zh-hant.json +++ b/i18n/zh-hant.json @@ -38,5 +38,12 @@ "isekai-function-btn-exit-fullscreen": "退出全屏", "group-activated-editor": "作者", - "group-activated-editor-member": "作者" + "group-activated-editor-member": "作者", + + "isekai-ve-formatdropdown-format-mw-heading1": "標題", + "isekai-ve-formatdropdown-format-mw-heading2": "子標題", + "isekai-ve-formatdropdown-format-mw-heading3": "三级標題", + "isekai-ve-formatdropdown-format-mw-heading4": "四级標題", + "isekai-ve-formatdropdown-format-mw-heading5": "五级標題", + "isekai-ve-formatdropdown-format-mw-heading6": "六级標題" } \ No newline at end of file diff --git a/modules/ve.ext.isekai.misc.js b/modules/ve.ext.isekai.misc.js new file mode 100644 index 0000000..f014da1 --- /dev/null +++ b/modules/ve.ext.isekai.misc.js @@ -0,0 +1,35 @@ +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'); + } +} + +updateVisualEditorConfig(); \ No newline at end of file