首页
随机
附近
登录
设置
关于陋室
免责声明
陋室
搜索
查看“︁MediaWiki:Gadget-SelectionCounter.js”︁的源代码
←
MediaWiki:Gadget-SelectionCounter.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于这些用户组的用户执行:
用户
、
自动确认用户
本页面提供本维基软件的界面文本,并受到保护以防止滥用。 要添加或更改所有维基的翻译,请使用MediaWiki的本地化项目
translatewiki.net
。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有网站访客。
您可以查看和复制此页面的源代码。
/* MediaWiki Gadget: SelectionCounter */ ( function () { 'use strict'; mw.loader.using( [ 'jquery', 'mediawiki.util' ] ).then( function () { var $counter; var rafId = null; var pollTimer = null; var lastText = ''; var lastTime = 0; var isSelecting = false; if ( window.SelectionCounterLoaded ) { return; } window.SelectionCounterLoaded = true; function label( count ) { var lang = mw.config.get( 'wgUserLanguage' ) || mw.config.get( 'wgContentLanguage' ) || 'zh-cn'; return lang.toLowerCase().indexOf( 'en' ) === 0 ? 'Selected ' + count + ' chars' : '已选 ' + count + ' 字'; } function getSelectionText() { var selection = window.getSelection(); if ( !selection || selection.rangeCount === 0 || selection.isCollapsed ) { return ''; } return selection.toString(); } function showCount( text ) { var compact = text.replace( /\s+/g, '' ); var count; if ( !compact ) { return false; } count = Array.from( compact ).length; $counter.text( label( count ) ).show(); return true; } function updateCounter() { var text; rafId = null; text = getSelectionText(); if ( text ) { lastText = text; lastTime = Date.now(); showCount( text ); return; } if ( lastText && Date.now() - lastTime < 1200 ) { showCount( lastText ); return; } $counter.hide(); } function scheduleUpdate() { if ( !rafId ) { rafId = window.requestAnimationFrame( updateCounter ); } } function scheduleUpdateDelayed() { window.setTimeout( scheduleUpdate, 0 ); } function startPolling() { if ( !pollTimer ) { pollTimer = window.setInterval( updateCounter, 500 ); } } function stopPolling() { if ( pollTimer ) { window.clearInterval( pollTimer ); pollTimer = null; } } function onSelectMove() { if ( isSelecting ) { scheduleUpdate(); } } $( function () { $counter = $( '#mw-selection-counter' ); if ( !$counter.length ) { $counter = $( '<div id="mw-selection-counter" class="mw-selection-counter" role="status" aria-live="polite"></div>' ) .hide() .appendTo( 'body' ); } document.addEventListener( 'selectionchange', function () { var text = getSelectionText(); if ( text ) { lastText = text; lastTime = Date.now(); } scheduleUpdate(); } ); document.addEventListener( 'mousedown', function () { isSelecting = true; }, true ); document.addEventListener( 'mouseup', function () { isSelecting = false; scheduleUpdateDelayed(); }, true ); document.addEventListener( 'mousemove', onSelectMove, true ); document.addEventListener( 'touchstart', function () { isSelecting = true; }, { passive: true, capture: true } ); document.addEventListener( 'touchmove', onSelectMove, { passive: true, capture: true } ); document.addEventListener( 'touchend', function () { isSelecting = false; scheduleUpdateDelayed(); }, { passive: true, capture: true } ); document.addEventListener( 'keyup', scheduleUpdate ); window.addEventListener( 'focus', startPolling ); window.addEventListener( 'blur', stopPolling ); document.addEventListener( 'visibilitychange', function () { if ( document.hidden ) { stopPolling(); return; } startPolling(); } ); startPolling(); } ); } ); }() );
返回
MediaWiki:Gadget-SelectionCounter.js
。