跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
特殊页面
Minimalist Tower Defense Wiki
搜索
搜索
外观
创建账号
登录
个人工具
创建账号
登录
查看“︁MediaWiki:Common.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
页面信息
外观
移至侧栏
隐藏
←
MediaWiki:Common.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
本页面提供本维基软件的界面文本,并受到保护以防止滥用。 要添加或更改所有维基的翻译,请使用MediaWiki的本地化项目
translatewiki.net
。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有网站访客。
您可以查看和复制此页面的源代码。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ /* 灰白里程有尽矿井计算器 */ ( function () { 'use strict'; var state = { x: 0 }; var recs = []; // { node, expr, unit, raw } function toJS( raw ) { var s = String( raw ).trim(); s = s.replace( /×/g, '*' ).replace( /÷/g, '/' ) .replace( /(/g, '(' ).replace( /)/g, ')' ) .replace( /[-—–−]/g, '-' ).replace( /\s+/g, '' ); s = s.replace( /(\d)(x)/g, '$1*$2' ).replace( /(x)(\d)/g, '$1*$2' ) .replace( /(\d)\(/g, '$1*(' ).replace( /\)(\d)/g, ')*$1' ) .replace( /\)(x)/g, ')*$1' ).replace( /(x)\(/g, '$1*(' ) .replace( /⌊([^⌋]*)⌋/g, function ( m, inner ) { return 'Math.floor(' + inner + ')'; } ); return s; } function evalExpr( raw, x ) { try { var v = ( new Function( 'x', 'return (' + toJS( raw ) + ');' ) )( x ); if ( typeof v !== 'number' || !isFinite( v ) ) return null; return Math.round( v ); } catch ( e ) { return null; } } function asFormula( text ) { var s = String( text ).trim(); if ( s.length < 2 || s.length > 80 ) return null; if ( /[\u4e00-\u9fff]/.test( s ) ) return null; var unit = '', m = s.match( /^(.*?)([GC])$/ ), body = m ? m[1].trim() : s; if ( m ) unit = m[2]; if ( body.indexOf( 'x' ) === -1 ) return null; if ( !/[+\-×*⌊⌋]/.test( body ) ) return null; if ( !/^[0-9x+\-×*/().⌊⌋\s]+$/.test( body ) ) return null; return { expr: body, unit: unit, raw: s }; } function skipNode( node ) { var p = node.parentNode; if ( !p ) return true; var tag = ( p.nodeName || '' ).toLowerCase(); if ( tag === 'script' || tag === 'style' || tag === 'code' || tag === 'pre' ) return true; if ( p.closest && ( p.closest( '.calc-box' ) || p.closest( '.calc-out' ) ) ) return true; return false; } function collect( root ) { var out = []; if ( !root ) return out; var walker = document.createTreeWalker( root, NodeFilter.SHOW_TEXT, null ), node; while ( ( node = walker.nextNode() ) ) { if ( skipNode( node ) ) continue; var info = asFormula( node.nodeValue ); if ( info ) out.push( { node: node, expr: info.expr, unit: info.unit, raw: info.raw } ); } return out; } function sanitizeX( v ) { var n = Math.floor( Number( v ) ); if ( !isFinite( n ) || n < 0 ) n = 0; return n; } function render() { for ( var i = 0; i < recs.length; i++ ) { var r = recs[ i ], v = evalExpr( r.expr, state.x ); r.node.nodeValue = ( v === null ? r.raw : String( v ) + r.unit ); } } function buildInput( box ) { if ( box.querySelector( '.calc-input' ) ) return; var labelText = box.textContent.trim() || '数量 x'; box.textContent = ''; var label = document.createElement( 'label' ); label.className = 'calc-label'; label.appendChild( document.createTextNode( labelText.replace( /[::]\s*$/, '' ) + ':' ) ); var input = document.createElement( 'input' ); input.type = 'number'; input.min = '0'; input.step = '1'; input.value = String( state.x ); input.className = 'calc-input'; input.setAttribute( 'inputmode', 'numeric' ); input.setAttribute( 'aria-label', labelText ); input.addEventListener( 'input', function () { state.x = sanitizeX( input.value ); render(); } ); input.addEventListener( 'blur', function () { state.x = sanitizeX( input.value ); input.value = String( state.x ); render(); } ); label.appendChild( input ); box.appendChild( label ); } function eachNode( sel, fn ) { Array.prototype.forEach.call( document.querySelectorAll( sel ), fn ); } function start() { for ( var i = 0; i < recs.length; i++ ) { try { recs[ i ].node.nodeValue = recs[ i ].raw; } catch ( e ) {} } recs = collect( document.querySelector( '.mw-parser-output' ) || document.body ); eachNode( '.calc-box', buildInput ); render(); } if ( window.mw && mw.hook ) { mw.hook( 'wikipage.content' ).add( start ); } if ( document.readyState === 'loading' ) { document.addEventListener( 'DOMContentLoaded', start ); } else { start(); } } )(); /* 灰白里程页头子页面标题精简、徽标跳转 */ (function () { var ROOT = '灰白里程'; function init() { if (!/(^|\s)page-灰白里程/.test(document.body.className)) return; var h1 = document.getElementById('firstHeading'); if (!h1) return; /*子页面标题精简*/ var span = h1.querySelector('.mw-page-title-main') || h1; var text = (span.textContent || '').trim(); if (text.indexOf(ROOT + '/') === 0) { span.textContent = text.slice(ROOT.length + 1); } /* 徽标跳转 */ if (h1.querySelector('.gbm-hero-home')) return; var path = mw.config.get('wgArticlePath') || '/index.php?title=$1'; var a = document.createElement('a'); a.className = 'gbm-hero-home'; a.href = path.replace('$1', encodeURIComponent(ROOT)); a.title = '返回' + ROOT; a.setAttribute('aria-label', '返回' + ROOT); h1.appendChild(a); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();
返回
MediaWiki:Common.js
。
搜索
搜索
查看“︁MediaWiki:Common.js”︁的源代码
添加话题