MediaWiki:Gadget-edit0.js:修订间差异
外观
创建页面,内容为“// en:MediaWiki:Gadget-edittop.js // ********************************************************************** // ** ***WARNING GLOBAL GADGET FILE*** ** // ** changes to this file affect many users. ** // ** please discuss on the talk page before editing ** // ** ** // ******************************************************…” |
小无编辑摘要 |
||
| 第1行: | 第1行: | ||
// [[en:MediaWiki:Gadget-edittop.js]] | // [[en:MediaWiki:Gadget-edittop.js]] | ||
(function() { | (function() { | ||
'use strict'; | 'use strict'; | ||
mw.loader.using(['mediawiki.util', 'jquery']).then(function() { | mw.loader.using(['mediawiki.util', 'jquery']).then(function() { | ||
const config = mw.config.get([ | |||
'wgAction', | 'wgAction', | ||
'wgNamespaceNumber', | 'wgNamespaceNumber', | ||
| 第23行: | 第12行: | ||
]); | ]); | ||
if (!['view', 'purge'].includes(config.wgAction) || config.wgNamespaceNumber < 0) { | if (!['view', 'purge'].includes(config.wgAction) || config.wgNamespaceNumber < 0) { | ||
return; | return; | ||
} | } | ||
const EDIT_SUMMARY = '/* top */ '; | const EDIT_SUMMARY = '/* top */ '; | ||
const TITLES = { | const TITLES = { | ||
| 第37行: | 第23行: | ||
}; | }; | ||
$(function() { | $(function() { | ||
const userLang = config.wgUserLanguage; | const userLang = config.wgUserLanguage; | ||
const editTitle = TITLES[userLang] || '编辑首段'; | const editTitle = TITLES[userLang] || '编辑首段'; | ||
const $content = $('#content, #mw_content').first(); | const $content = $('#content, #mw_content').first(); | ||
const $firstEditSection = $content.find('span.mw-editsection:not(.plainlinks):first'); | const $firstEditSection = $content.find('span.mw-editsection:not(.plainlinks):first'); | ||
| 第52行: | 第35行: | ||
const $clonedEditSection = $firstEditSection.clone(); | const $clonedEditSection = $firstEditSection.clone(); | ||
$('#mw_header h1, #content h1').first().append($clonedEditSection); | $('#mw_header h1, #content h1').first().append($clonedEditSection); | ||
$clonedEditSection.find('a').text(editTitle).each(function() { | $clonedEditSection.find('a').text(editTitle).each(function() { | ||
const $link = $(this); | const $link = $(this); | ||
| 第62行: | 第42行: | ||
let newHref; | let newHref; | ||
if (!/&(ve|)section=T/.test(originalHref)) { | if (!/&(ve|)section=T/.test(originalHref)) { | ||
newHref = originalHref.replace(/&(ve|)section=\d+/, `&$1section=0&summary=${encodeURIComponent(EDIT_SUMMARY)}`); | newHref = originalHref.replace(/&(ve|)section=\d+/, `&$1section=0&summary=${encodeURIComponent(EDIT_SUMMARY)}`); | ||
2025年11月12日 (三) 11:08的版本
// [[en:MediaWiki:Gadget-edittop.js]]
(function() {
'use strict';
mw.loader.using(['mediawiki.util', 'jquery']).then(function() {
const config = mw.config.get([
'wgAction',
'wgNamespaceNumber',
'wgUserLanguage',
'wgPageName'
]);
if (!['view', 'purge'].includes(config.wgAction) || config.wgNamespaceNumber < 0) {
return;
}
const EDIT_SUMMARY = '/* top */ ';
const TITLES = {
'zh': '编辑首段',
'zh-hans': '编辑首段',
'zh-hant': '編輯首段'
};
$(function() {
const userLang = config.wgUserLanguage;
const editTitle = TITLES[userLang] || '编辑首段';
const $content = $('#content, #mw_content').first();
const $firstEditSection = $content.find('span.mw-editsection:not(.plainlinks):first');
if (!$firstEditSection.length) {
return;
}
const $clonedEditSection = $firstEditSection.clone();
$('#mw_header h1, #content h1').first().append($clonedEditSection);
$clonedEditSection.find('a').text(editTitle).each(function() {
const $link = $(this);
const originalHref = $link.attr('href') || '';
let newHref;
if (!/&(ve|)section=T/.test(originalHref)) {
newHref = originalHref.replace(/&(ve|)section=\d+/, `&$1section=0&summary=${encodeURIComponent(EDIT_SUMMARY)}`);
} else if (/&vesection=/.test(originalHref)) {
newHref = mw.util.getUrl(config.wgPageName, {
veaction: 'edit',
vesection: 0,
summary: EDIT_SUMMARY
});
} else {
newHref = mw.util.getUrl(config.wgPageName, {
action: 'edit',
section: 0,
summary: EDIT_SUMMARY
});
}
$link.attr('href', newHref);
});
});
});
})();