打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

MediaWiki:Common.js:修订间差异

MediaWiki界面页面
Kuina留言 | 贡献
无编辑摘要
标签已被回退
Kuina留言 | 贡献
撤销Kuina讨论)的修订版本2939
标签撤销
第5行: 第5行:
}
}


$(document).ready(function() {
mw.loader.using('mediawiki.Uri', function () {
  // 查找所有以 /index.php? 开头的链接
  $(document).ready(function () {
  $('a[href^="/index.php?"]').each(function() {
    $('a').each(function () {
    var href = $(this).attr('href');
      var href = $(this).attr('href');
    // 判断链接中是否含有 action=veedit 参数
      if (href && href.indexOf('veaction=edit') !== -1) {
    if (href.indexOf('action=veedit') !== -1) {
        // 解析链接
      // 通过正则匹配提取 title 参数的值
        var uri = new mw.Uri(href);
      var titleMatch = href.match(/(?:\?|&)title=([^&]+)/);
        if (uri.query.veaction === 'edit') {
      if (titleMatch && titleMatch[1]) {
          // 将参数替换为 action=veedit
        var title = decodeURIComponent(titleMatch[1]);
          delete uri.query.veaction;
        // 构造新的短链接形式:/w/veedit/Page_title
          uri.query.action = 'veedit';
        var newHref = '/w/veedit/' + encodeURIComponent(title);
          // 构造新的 URL(去除 index.php 部分,让它符合短链接结构)
        $(this).attr('href', newHref);
          // 假设正常页面链接结构为 /wiki/Page_title,因此这里用 veedit 替换 edit 的部分
          var newHref = '/w/veedit/' + encodeURIComponent(uri.query.title || uri.path);
          // 保留其他查询参数
          var params = [];
          $.each(uri.query, function (key, val) {
            if (key !== 'title') {
              params.push(key + '=' + encodeURIComponent(val));
            }
          });
          if (params.length) {
            newHref += '?' + params.join('&');
          }
          // 更新链接
          $(this).attr('href', newHref);
        }
       }
       }
     }
     });
   });
   });
});
});

2025年5月16日 (五) 12:27的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
if (mw.config.get('wgPageName') === '首页'){
importScript( 'MediaWiki:Mainpage.js' );
} else {
}

mw.loader.using('mediawiki.Uri', function () {
  $(document).ready(function () {
    $('a').each(function () {
      var href = $(this).attr('href');
      if (href && href.indexOf('veaction=edit') !== -1) {
        // 解析链接
        var uri = new mw.Uri(href);
        if (uri.query.veaction === 'edit') {
          // 将参数替换为 action=veedit
          delete uri.query.veaction;
          uri.query.action = 'veedit';
          // 构造新的 URL(去除 index.php 部分,让它符合短链接结构)
          // 假设正常页面链接结构为 /wiki/Page_title,因此这里用 veedit 替换 edit 的部分
          var newHref = '/w/veedit/' + encodeURIComponent(uri.query.title || uri.path);
          // 保留其他查询参数
          var params = [];
          $.each(uri.query, function (key, val) {
            if (key !== 'title') {
              params.push(key + '=' + encodeURIComponent(val));
            }
          });
          if (params.length) {
            newHref += '?' + params.join('&');
          }
          // 更新链接
          $(this).attr('href', newHref);
        }
      }
    });
  });
});
我们为您提供服务需要使用Cookie。使用我们的服务即表示您同意我们使用Cookie。