MediaWiki:Common.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
/* 自动补全删除操作的 Edit Token 凭证 */
mw.loader.using(['mediawiki.api'], function () {
new mw.Api().getToken('csrf').then(function (token) {
// 1. 自动为页面上所有【删除链接】拼接 token
$('a[href*="action=deletethread"]').each(function () {
if (this.href.indexOf('token=') === -1 && this.href.indexOf('wpEditToken=') === -1) {
var separator = this.href.indexOf('?') !== -1 ? '&' : '?';
this.href += separator + 'wpEditToken=' + encodeURIComponent(token) + '&token=' + encodeURIComponent(token);
}
});
// 2. 自动为页面上所有【删除表单】注入 hidden 隐藏域 token
$('form[action*="deletethread"]').each(function () {
if ($(this).find('input[name="wpEditToken"]').length === 0) {
$(this).append($('<input>', {
type: 'hidden',
name: 'wpEditToken',
value: token
}));
}
if ($(this).find('input[name="token"]').length === 0) {
$(this).append($('<input>', {
type: 'hidden',
name: 'token',
value: token
}));
}
});
});
});