MediaWiki:Common.js:修订间差异

来自恶俗狗维基-揭露恶俗劣迹的百科全书
跳转到导航 跳转到搜索
创建页面,内容为“这里的任何JavaScript将为所有用户在每次页面加载时加载。:​ // 当页面加载完成时,自动抓取最新的安全令牌并拼接到删除链接上 mw.loader.using(['mediawiki.api'], function () { new mw.Api().getToken('csrf').then(function (token) { $('a[href*="action=deletethread"]').each(function () { if (this.href.indexOf('token=') === -1) { this.href += '&token=' + encodeURIComponent(token);…”
 
无编辑摘要
 
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 自动补全删除操作的 Edit Token 凭证 */
// 当页面加载完成时,自动抓取最新的安全令牌并拼接到删除链接上
mw.loader.using(['mediawiki.api'], function () {
mw.loader.using(['mediawiki.api'], function () {
     new mw.Api().getToken('csrf').then(function (token) {
     new mw.Api().getToken('csrf').then(function (token) {
        // 1. 自动为页面上所有【删除链接】拼接 token
         $('a[href*="action=deletethread"]').each(function () {
         $('a[href*="action=deletethread"]').each(function () {
             if (this.href.indexOf('token=') === -1) {
             if (this.href.indexOf('token=') === -1 && this.href.indexOf('wpEditToken=') === -1) {
                 this.href += '&token=' + encodeURIComponent(token);
                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
                }));
             }
             }
         });
         });
     });
     });
});
});

2026年8月14日 (五) 15:15的最新版本

/* 自动补全删除操作的 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
                }));
            }
        });
    });
});