MediaWiki:Common.js

勤求古训,博采众方
鹿野耕云留言 | 贡献2022年12月12日 (一) 16:02的版本 (撤销鹿野耕云讨论)的版本26692)

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

  • 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将为所有用户在每次页面载入时加载。 */

/* 随系统切换暗黑模式。 */
window.wpDarkModeAutoToggle = true;

/* UTC时钟使用本地时区。 */
window.LiveClockTimeZone = 'Asia/Shanghai';

/* 优化 */
if (location.pathname === '/') {
	history.replaceState({}, document.title, 'Index');
}


/* 百度统计代码 */
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?1d1f417946fa19c604c8a03880f407ed";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();


/* 测试 */

$( document ).ready( function( $ ) {
	var $sb = $( '#specialchars' ).find( '.specialbasic' ), bl = $sb.length, $sel, ci = 0;

	if ( bl > 1 ) {
		ci = Number( $.cookie('mw-charinsert') ) || 0;
		if ( ci > bl ) {
			$.cookie( 'mw-charinsert', 0, { expires: 30, path: '/' } );
			ci = 0;
		}
		$sel = $( '<select>' ).change( function(e) {
			var	$this = $( this ),
				i = Number( $this.val() ),
				last = Number( $.cookie('mw-charinsert') ) || 0;

			if ( last !== i ) {
				$sb.eq( last ).css( 'display', 'none' );
				$sb.eq( i ).css( 'display', 'inline' );
				$.cookie( 'mw-charinsert', i, { expires: 30, path: '/' } );
			}
		});
	}

	$sb.each( function( i ) {
		var id = $( this )
			.css( 'display', i !== ci ? 'none' : 'inline' )
			.find( 'a' ).replaceWith( function() {
				var $this = $( this ), onclick = $this.attr( 'onclick' );
				return $( '<button>', { type: 'button', text: $this.text() } )
					.blur()
					.click( $.isFunction( onclick ) ? onclick : Function( onclick ) );
			})
			.end()
			.attr( 'id' )
			.replace( /\.([0-9A-F]{2})/g, '%$1' )
			.replace( /_/g, ' ' );
 
		if ( bl > 1 ) {
			$sel.append(
				'<option value="' + i + '"' + (i === ci ? ' selected="selected"' : '') + '>'
				+ decodeURIComponent( id )
				+ '</option>'
			);
		}
	}).end().prepend( $sel );

	ci = null;
});