全站通知:

MediaWiki:Common.js

来自监狱建筑师WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */

console.log('========= Common.js v220802.01 ==========')

/* 加载 Main.js 用于测试,稳定后加入Common.js */
mw.loader.load("//wiki.biligame.com/prisonarchitect/index.php?title=MediaWiki:Main.js&action=raw&ctype=text/javascript&random="+Math.random(), "text/javascript");
/* 加载 Main.css 用于测试,稳定后加入Common.css */
mw.loader.load("//wiki.biligame.com/prisonarchitect/index.php?title=MediaWiki:Main.css&action=raw&ctype=text/css&random="+Math.random(), "text/css");



/* --编辑摘要-- */
//参考Wikipedia:MediaWiki:Common.js/edit.js
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // 编辑页面
  
( function( $, mw ) { $( function() {
    if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
        if ( $( '#no-new-title' ).length ) {
            $( '#wpSummary' ).attr( 'disabled', true );
        }
        return;
    }
    $( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
        e.preventDefault();
        var $this = $( this ), summary = $( '#wpSummary' ).val();
        var $item = $this.parent( '.mw-summary-preset-item' );
        summary = summary.replace( /\s+$/g, '' );
        if ( summary != '' ) {
            summary += ' ';
        }
        summary += $item.attr( 'title' ) || $this.text();
        $this.replaceWith( $this.contents() );
        $( '#wpSummary' ).val( summary ).focus();
    } );
} ); } )( jQuery, mediaWiki );

}

/* -- 为页面加载JS脚本或CSS样式表 -- */
/* 参见[[模板:ResourceLoader]]*/
/* 来源:碧蓝航线WIKI*/
$('.resourceLoader').each(function () {
  var $x = $(this);
  var text = $.trim($x.text());

  if (!text) return;

  //加载模块
  if ($x.data('isModule') === true)
    return mw.loader.load(text);

  //自动补充MediaWiki命名空间
  var ns = text.match('^.*?:');
  if (!ns) text = 'MediaWiki:' + text;
  
  //加载JS脚本
  if (ns && ns[0].toLowerCase() !== 'mediawiki:') {
    return console.log('ResourceLoader: 不允许加载MediaWiki以外的脚本');
  }
  
  //加载CSS样式表
  var mime = ($x.data('mime') || "text/javascript").toLowerCase();
  if (mime == "text/css") {
    if (text.slice(-4).toLowerCase() !== '.css') text = text + '.css';
    return mw.loader.load("//wiki.biligame.com/csl/index.php?title=" + text + "&action=raw&ctype=text/css", "text/css");
  }

  if (text.slice(-3).toLowerCase() !== '.js') text = text + '.js';
  return mw.loader.load("//wiki.biligame.com/csl/index.php?title=" + text + "&action=raw&ctype=text/javascript", "text/javascript");
});